Repository navigation
Merge upstream mlx-lm 4cfc647 into local - #26
Merged
Merged
Conversation
Co-authored-by: Cheng <git@zcbenz.com>
QuantizedSwitchLinear passes global_scale to mx.gather_qmm since ml-explore#1844. That keyword first shipped in mlx 0.32.3, so with mlx 0.32.2 every quantized MoE fails with a TypeError on the first forward.
* Improve the state machine a bit * Fix tool calling within reasoning * Use deltas * Prune tests * Remove test * Drop `drop_held` * Make _state private * Add discard to the reader * Non-optional transitions * Drop empty tool calls * Prune comments * Let first match win * Don't add empty tool calls v2 * Add stopped flag * Add deltas * Simpler made_tool_call check * Better typing * Better API * Fix stop reason when delta was stopped * Catch any tool formatting exceptions * Build from tokenizer/stop words * Drop make_stop_sequences * Drop header * Drop SM cache * Check for valid states * Update server.md, prune docs * Drop the add methods * Revert trie change
* Fix ERNIE-4.5 MoE correction bias routing - Add `Ernie4_5_MoeStatics` to preserve `e_score_correction_bias` from the checkpoint. - Apply correction bias during top-k expert selection while keeping routing weights based on unbiased gates. - Update sanitization to squeeze the bias from `[1, E]` to `[E]` and default to zeros when missing. - Handle partial weight dictionaries safely and preserve float32 bias precision during conversion. - Add tests for correction-bias sanitization and routing behavior. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Knightkolla <kartikeyadhavala2468@gmail.com> * Drop the `Ernie4_5_MoeStatics` class --------- Signed-off-by: Knightkolla <kartikeyadhavala2468@gmail.com> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: Michal Klein <46717574+michalk8@users.noreply.github.com>
Pass the starting cache offset to KV-reuse attention layers instead of deriving it from shared sequence dimensions. Add AFM7 left-padding regression coverage and build test caches using make_prompt_cache(model). Signed-off-by: Knightkolla <kartikeyadhavala2468@gmail.com> Co-authored-by: michalk8 <46717574+michalk8@users.noreply.github.com>
…ore#1955) * Fix ModelOpt NVFP4 config loading and global scales in convert The ModelOpt config failed with a KeyError from both config.json and hf_quant_config.json. convert --dtype cast global_scale away from float32, and convert --dequantize ignored it. * Drop the ModelOpt config changes main now loads the ModelOpt config from config.json and hf_quant_config.json. The fallback for hf_quant_config.json files without quant_method only helps models with nvfp4 dense layers, which mlx-lm can't run yet. --------- Co-authored-by: jundot <jundot@users.noreply.github.com>
* mistral 3.5 * pipelining fr mistral
Co-authored-by: Vincent Clifford <v_clifford@apple.com>
…#1997) Co-authored-by: Vincent Clifford <v_clifford@apple.com> Co-authored-by: Cheng <git@zcbenz.com>
* Support loading original checkpoint * Keep router in float32 so expert selection matches the original. Tested converting the original checkpoint to mlx and comparing long generations match. --------- Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
* Flint * Align implementation with transformers * Flint: use the fused expert routing kernel Route with mlx_lm.kernels.expert_routing, the kernel added with Muse Spark Open. Flint has no expert bias, so the kernel gets a zero bias. Training and non-Metal backends keep the ops path because the kernel has no vjp. * Apply suggestions from code review Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Add tests * Fix int4 loading * Fix layers of only 1 type * Test left padding * Use strict=True --------- Co-authored-by: jundot <jundot@users.noreply.github.com> Co-authored-by: michalk8 <46717574+michalk8@users.noreply.github.com>
…hine cache (upstream builds the machine per request)
…behaviour, pillow and test status (review of #26)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge
Merge upstream
4cfc6478473b0668ede3eb0cc93f2a9181a15052intolocalwith a merge commit. No tag is cut here;v0.32.2-local06remains planned.The 12 upstream commits:
8b37582Fix [THINK] tokens (Fix [THINK] tokens ml-explore/mlx-lm#1974)c39139dSupport PLaMo3 instruction-tuned models with YaRN (Support PLaMo3 instruction-tuned models with YaRN ml-explore/mlx-lm#1931)e7d21f4Require mlx 0.32.3 (Require mlx 0.32.3 ml-explore/mlx-lm#1995)ab7f704TextMachine improvements (TextMachine improvements ml-explore/mlx-lm#1973)a28cdd0Fix ERNIE-4.5 MoE correction bias routing (Fix ERNIE-4.5 MoE correction bias routing ml-explore/mlx-lm#1959)72be8c9Fix AFM7 RoPE offsets for left-padded batches (Fix AFM7 RoPE offsets for left-padded batches ml-explore/mlx-lm#1990)33fdd16Keep nvfp4 global scales in convert --dtype and --dequantize (Keep nvfp4 global scales in convert --dtype and --dequantize ml-explore/mlx-lm#1955)0d4d3d0Mistral3 medium (Mistral3 medium ml-explore/mlx-lm#1986)4e9a1deGLM-5.2 DSA cross-layer indexer sharing (glm_moe_dsa: DSA cross-layer indexer sharing (GLM-5.2) ml-explore/mlx-lm#1410)dc2012bGLM DSA sparse prefill (glm_moe_dsa: sparse prefill over the indexer's top-k keys ml-explore/mlx-lm#1997)59995f1Support the original MiniMax M3.1 checkpoint (Support loading the original MiniMax M3.1 checkpoint ml-explore/mlx-lm#2003)4cfc647Recursive Flint model support (Recursive Flint model support ml-explore/mlx-lm#1998)Conflict resolutions
generate.py: take upstreamTextStateMachinereader/Delta implementation, not the former tuple API; retain the fork's token stop-sequence helper andstream_generate(ignore_eos=...)behavior.server.py: retain imports andBareToolCallFilter; adapt the formatter to upstream Delta tool calls while retaining theNotAToolCallcontent fallback and streaming indices. PreserveGenerationArguments.ignore_eosand request parsing/validation alongside upstream stop validation. Replace the old cached state-machine factory with upstream text-state and stop readers; for batched insertion select EOS stop tokens per request and omit ignored EOS from detokenization, while single generation forwardsignore_eos. In the chat handler feed the new reader and flush bare-call recovery at each normal-state exit, then handle parser fallback content and tool-call finish reasons for streaming and non-streaming. Upstream text stop handling remains in place.tests/test_server.py: retain both upstream and fork tests, adapting fork state-machine helpers to readers and upstream formatter assertions to the fork's tuple return. No topic test was intentionally deleted or weakened.pyproject.tomlexcludes non-PEP-440 fork-local*tags from setuptools-scm'sgit describe; without this, editable installation fails parsingv0.32.2-local05.Verification and limitations
Python 3.14, MLX 0.32.4+local03,
HF_HUB_OFFLINE=1, models cached (includingmlx-community/Qwen1.5-0.5B-Chat-4bit, which the first run lacked); fullpytest tests --continue-on-collection-errorsin each tree:4cfc647: 23 failed, 357 passed, 1 skipped, 1 error, 181 subtests passed.The failing and erroring sets are identical in both trees (numerical assertions in
test_generate/test_models, among themtest_flint, uncached tokenizer models, one collection error intests/models/test_muse_spark.py): they are inherited from pristine upstream on this host. The 94 extra passes are the carried topics' tests, all of which now run, including everyTestIgnoreEostest (23 passed, 142 subtests).An earlier version of this body said the model-dependent topic tests did not run and that no topic test was weakened. An independent review found four
TestIgnoreEostests failing in the merged tree because the test helper readResponseGenerator._state_machine_cache, which upstream removed (the machine is built per request). The helper no longer touches a cache (commit 8e78509); the assertions are unchanged.Deliberately kept fork behaviour (also in
UPSTREAM.md): themade_callfinish-reason rule of topicllama3-tool-parser, which differs from upstream'stool_formatter.countfor a response whose only tool call fails to parse (tool_callshere,stopupstream). Open owner decision. Packaging: the port needspillowindepends_lib(upstream dc2012b).PYTHONPATH=<merged tree> python -c 'import mlx_lm.models.flint'succeeded. Offline real-model smoke withmlx-community/Llama-3.2-1B-Instruct-4bit: plain chat returnedHello!(stop, 3 completion tokens);ignore_eos=true,max_tokens=8returned length with 8 completion tokens; tool request returned aweathertool call with{"city":"Paris"}. Server stopped afterward. These smokes do not replace the unavailable topic tests.