Repository navigation
Add Qwen4 MoE (text): upstream qwen4_exp package + #2140 - #68
Merged
Merged
Conversation
Qwen4-35B-A3B (model_type qwen4_moe) runs on the qwen4_exp model, which upstream rewrote as a package with QSA sparse attention (ml-explore#2082, ml-explore#2112) after the single file this fork took in ml-explore#1788. - models/qwen4_exp/: upstream's package with ml-explore#2140 (Qwen4 MoE configs, FP8 and per-expert checkpoints); the old qwen4_exp.py is gone. - kernels/sparse_attention.py: upstream's indexed attention kernels. - layers/attention.py, layers/recurrent.py: upstream's import paths, re-exporting the fork's models.base / models.gated_delta helpers (same signatures). - --mmap-lookup-tables reads Qwen4's n-gram tables (a list of embeddings, ~11 GB at 4 bits) from the file: map_lookup_tables matches list entries by the list's name. - reasoning_effort "off" (or "none") now sets enable_thinking false when the request doesn't: Qwen4's template rejects enable_thinking true with effort off. Checked: logits equal to upstream's branch (5e-7, full and cached decode) on a tiny random model; the mlx-community 4-bit checkpoint's 2271 tensors match the model tree (keys and shapes, from the file headers); the fork server with the real Qwen4 tokenizer on a tiny model: streaming, tools, tool results, thinking budget, --kv-bits 8, 4 concurrent requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…odex) map_lookup_tables removes the tensors before the strict load: a table of the wrong shape, or without the biases its module has, was mapped unchecked. It now stays loaded and load_weights reports it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Adds Qwen4-35B-A3B (
model_type: qwen4_moe, text only).Upstream implements Qwen4 MoE on the
qwen4_expmodel, which it has since rewritten as a package with QSA sparse attention (ml-explore#2082, ml-explore#2112). This fork still had the single file from ml-explore#1788.models/qwen4_exp/: upstream's package plus Add Qwen4 MoE ml-explore/mlx-lm#2140 (Qwen4 MoE configs, FP8 and per-expert checkpoints). The oldqwen4_exp.pyis removed; its only fork commit was lint.kernels/sparse_attention.py: upstream's indexed attention kernels.layers/attention.py,layers/recurrent.py: upstream's import paths, re-exporting the fork'smodels.base/models.gated_deltahelpers (same signatures).--mmap-lookup-tablesnow covers Qwen4's n-gram tables (~11 GB at 4 bits). They are a list of embeddings, somap_lookup_tablesalso matches list entries by the list's name.reasoning_effort: "off"(or"none") setsenable_thinkingfalse when the request doesn't. Qwen4's template rejectsenable_thinking=truewith effortoff, and the wrapper defaulted it to true.Checks:
--kv-bits 8, 4 concurrent requests. Tool parser<tool_call>,<think>/</think>and EOS 248044/248046 are inferred.Known behavior:
--kv-bitsleaves Qwen4's KV cache in full precision. ItsCacheList(attention KV plus the indexer's cache) is skipped by the KV quantization paths, as upstream does. Only 10 of the 40 layers have KV, with 2 KV heads.reasoning_effortchange also applies to other templates: a Qwen3 template that ignoresreasoning_effortnow gets thinking off when a request sendsoffornonewithoutenable_thinking.Not included: image input (ml-explore#2141) and the MTP head.
Reviews: codex (findings above addressed or listed). muse could not run: its quota is used up until 2026-12-07.
🤖 Generated with Claude Code