Repository navigation
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>
* take prompt into account in speculative decoding * comments * Simplify tests --------- Co-authored-by: Michal Klein <46717574+michalk8@users.noreply.github.com>
* sparse attention optimization for deepseek * refactor code and tests --------- Co-authored-by: Vincent Clifford <v_clifford@apple.com>
All four kernels (KL/JS, forward/backward) reuse shared[] for the max values and then for the partial sums, with no barrier in between. A fast SIMD group could overwrite a max before a slower one read it. On an M1 Pro this gave losses off by up to 34%, and a different result on most calls. Added a threadgroup barrier after the max read in each kernel. Also switched the final reduction barrier in KL forward from mem_none to mem_threadgroup to match JS forward (no measurable effect). New large-input tests (128 x 151936, fp32) check loss and grad against CPU and that repeated calls are bit-identical. Both fail on main and pass with this fix. Fixes ml-explore#1700. AxelNoun found the cause in ml-explore#1714. Co-authored-by: AxelNoun <150222552+AxelNoun@users.noreply.github.com>
Co-authored-by: Lumonopolis <Lumonopolis@users.noreply.github.com> Co-authored-by: michalk8 <46717574+michalk8@users.noreply.github.com>
Co-authored-by: Vincent Clifford <v_clifford@apple.com>
* Add Qwen3.8-Flash-Next (qwen4_exp) model support Adds the qwen4_exp architecture: a hybrid Gated DeltaNet / Qwen Sparse Attention trunk wrapped in gated-residual hyper-connection streams, a sharded n-gram PLE embedding, and a 512-expert MoE. * Load the official Qwen3.8-Flash-Next checkpoint - non-gated norms use 1 + weight (checkpoint is zero-centered) - strip the model.language_model. prefix - split the fused gate_up_proj experts - drop the MTP block - accept an mx.array offset * Include each query's own partial block in the QSA selection Without it, queries with fewer than compress_ratio tokens of history ended up with fully masked rows, which softmax turns into a uniform average over all keys, future ones included. The tail is also no longer marked visible for every query. * Support left padding in the QSA indexer and batched caches * qwen4_exp: accept both quant_predicate calling conventions quant_predicate returned fn(path, module, _); mlx-lm 0.31.3 calls predicates with two arguments, later versions with three, so the conversion failed with TypeError: fn() missing 1 required positional argument: '_'. The default value _=None covers both conventions. Reported by @Sofille65. Verified: mlp.gate remains unquantized in both call cases. * qwen4_exp: fold RMSNorm +1 into weights during sanitize Fold the reference +1 into the weight once by sanitize instead of per call; fold guarded on the model.language_model prefix so converted checkpoints (model.*) are never folded twice. _FOLD_ONE covers the eight affected norm suffixes (linear_attn.norm excluded: RMSNormGated scales by w alone). Init zeros -> ones so unloaded modules stay identity. Pre-existing conversions load silently without the +1 and must be redone. * qwen4_exp: keep n-gram shards in a list, accept both key layouts The shards were flat `shard_{i}` attributes, so a checkpoint converted by mlx-vlm (`ngram_embedding.shards.{i}`, quantized) failed a strict load with missing/unexpected keys. Store them as a list and map the HF `shard_{i}` names onto it in sanitize. * qwen4_exp: default the n-gram hash seed to 1234, and check the constants at load Re-applied onto da1148f by @sje397: eauchs#1 no longer applies because da1148f reorganised the n-gram shard handling underneath it. The change is Beata's; only the anchors moved. The seed is not in config.json, so the default is load-bearing: a different seed rebuilds different multipliers and every PLE lookup lands on the wrong rows. `Model.sanitize` now compares the constants rebuilt from the config against the checkpoint's own copies and raises on mismatch, so a wrong seed fails loudly instead of silently reading the wrong rows. Verified against a real checkpoint, which the test alone cannot do (it constructs the model, so any self-consistent seed satisfies it): the community oQ4e conversion of this architecture at Jundot/Qwen3.8-Flash-Next-oQ4e-mtp carries layer_multipliers (3,), ngram_heads_vocab_sizes (16,) and ngram_heads_offsets (16,), and all three match the seed-1234 rebuild exactly at ple_layer_index 0. Candidates 0, 617 and 1235 do not match any layer index. So 1234 is not merely plausible -- it is the seed written into a shipped checkpoint, which is why the guard is worth having at load rather than trusting the default. * Update the model --------- Co-authored-by: Beata Kouchnir <12824699+beatakouchnir@users.noreply.github.com> Co-authored-by: michalk8 <46717574+michalk8@users.noreply.github.com>
* Move models to directories * Update Muse spark * Add `ZeroCenteredRMSNorm` * Move Qwens * More moves * Unify multimodal layouts * Fix step3p5 * More moves * Re-order functions, etc. * Fix nemotron * Fix LoRA * Move up constants * Fix remapping * Klear lower-case, drop some docstrings * Update docstrings, etc. * Final clean-up * Update contributing * Clean-up use_fp8_linears in Mistral3 * Minor aesthetic fixes
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.
No description provided.