Repository navigation
Add exact Qwen4Exp text core - #655
Merged
Merged
Conversation
Session: Implement qwen4exp core Project: mobius Branch: justinchuby-implement-qwen4exp-core Workspace: 5e64d099-fb0c-4b40-8cb3-75ccbab8693a Files: 14 changed Auto-saved before the worktree was removed so no work is lost. Restore it as a branch with `git branch <name> <this-commit>`.
Keep Gated-DeltaNet recurrence and cache state in float32 for the BF16 checkpoint, match upstream normalization and masking behavior, and make QSA exact for non-contiguous masks. Add fail-closed config and weight-layout validation plus pinned Transformers parity coverage. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for the pinned “Qwen4-Exp / Qwen3.8 Flash-Next” exact text decoder core in mobius, including its heterogeneous cache ABI (DeltaNet recurrence + QSA + PLE) and fail-closed weight/config guards, then wires it through the registry/tasks/testing surface.
Changes:
- Introduces
Qwen4ExpConfig,Qwen4ExpCausalLMModel, andQwen4ExpCausalLMTaskto build the exact text-core graph + cache ABI and registerqwen4_exp,qwen4_exp_text, andQwen4ExpForConditionalGenerationroutes. - Extends DeltaNet/LinearAttention plumbing to support float32 stash/state for BF16 checkpoint contracts and optional masked-token preservation.
- Adds targeted unit/integration tests plus design documentation for the new text-core implementation.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/build_graph_test.py | Skips ONNX checker for new Qwen4-Exp model types due to custom-op/shape-info limitations. |
| tests/_test_configs.py | Adds tiny Qwen4-Exp config overrides and registers three model-type entries for graph tests. |
| src/mobius/tasks/_qwen4_exp.py | New task defining I/O and cache ABI for the heterogeneous Qwen4-Exp text decoder. |
| src/mobius/tasks/_cache_utils.py | Adjusts LinearAttention function registration to use mamba_ssm_dtype when present. |
| src/mobius/tasks/init.py | Exposes Qwen4ExpCausalLMTask and registers the task name. |
| src/mobius/models/qwen4_exp.py | New exact decoder implementation: 3:1 schedule, hyper-connections, QSA indexer, PLE, routed+shared MoE, and weight preprocessing. |
| src/mobius/models/qwen4_exp_test.py | Comprehensive tests for config extraction/guards, ABI, dtype/stash behavior, and weight preprocessing; includes optional HF parity integration test. |
| src/mobius/models/init.py | Exports Qwen4ExpCausalLMModel. |
| src/mobius/integrations/transformers/_builder.py | Fail-closed guard to reject unsupported multimodal export for qwen4_exp unless text_only=True. |
| src/mobius/components/_gated_deltanet.py | Adds float32 stash support (mamba_ssm_dtype), token masking support, and stabilizes norms/decay computation. |
| src/mobius/_registry.py | Registers new Qwen4-Exp model types and maps composite qwen4_exp to text-only model type. |
| src/mobius/_configs/_base.py | Adds dtype conversion helper and introduces Qwen4ExpConfig with strict validation + HF extraction. |
| src/mobius/_configs/init.py | Re-exports Qwen4ExpConfig. |
| docs/design/qwen4-exp-text-core.md | New design note documenting architecture, cache ABI, and fail-closed decisions. |
| docs/design/index.md | Adds the new design doc to the index. |
Suppressed comments (1)
src/mobius/_configs/_base.py:1605
- The bounds check uses
num_local_experts, but the error message says[1, num_experts]. Using the normalized field name (num_local_experts) makes the failure clearer and avoids implying there’s a separatenum_expertsknob in this config class.
if not self.num_experts_per_tok or not (
0 < self.num_experts_per_tok <= self.num_local_experts
):
raise ValueError("Qwen4-Exp num_experts_per_tok must be in [1, num_experts]")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
This was referenced Aug 26, 2026
Correct QSA RoPE widths and bounded-memory selection, preserve pinned DeltaNet and BF16 router semantics, and execute only packed top-k experts. Stream official packed weights and PLE shards, pin L2 provenance, and fail closed for unsupported composite and ORT GenAI routes. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Performance Comparison
|
Apply the pinned Ruff formatting and use the required absolute test import. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Use the canonical ONNX RotaryEmbedding semantics for QSA query and pooled-key rotation, including interleaved layouts, and preserve half-width cos/sin cache shapes during block gathering. Make Qwen4Exp text synthetic parity execute its full runtime path instead of skipping setup or inference failures.\n\nCo-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Exercise half-split and interleaved ONNX RotaryEmbedding expansion against a NumPy reference. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
justinchuby
added a commit
that referenced
this pull request
Aug 27, 2026
## Stack - Depends on #655 (`justinchuby-finish-qwen4exp-core`). - Includes the sharded GGUF importer commit from #652 (`eacf244864284cc96bd70f1187b145446783aab4`) so the three-file artifact is evaluated as one complete model. ## Summary - register `general.architecture=qwen4exp` as `qwen4_exp_text` with the exact Qwen3.8 Flash-Next config, DeltaNet/QSA schedule, hyper-connections, PLE, routed/shared MoE, and output HC mixer metadata - pin `unsloth/Qwen3.8-Flash-Next-GGUF@d3bc75ee6ccef3efc1e228ec00a6cc2cdb1e2249`, all three shard sizes/LFS SHA-256 identities, and the metadata-only shard-0 closure `0 + 595 + 629 = 1224` - map every GGUF tensor family, including GGUF split indexer Q/K rows reconstructed exactly into Hugging Face's fused `index_qk_proj` - validate every tensor name, logical shape, and dynamic qtype using the complete bounded-header manifest digest `25a1e6a2073caf19d3a3835dd23702a19fa09cc651506e11a13de7b48076359d` - preserve existing official fused HF indexer checkpoints while accepting only the exact GGUF split representation on the GGUF path - fail closed before Hub payload download when header policy cannot be established, source/revision/shard identity differs, or either payload mode is requested ## Fail-closed payload policy The only published `UD-IQ1_S` route is intentionally not emitted as an executable ONNX payload: - `per_layer_token_embd.weight` is an enormous IQ4_NL embedding with no compatible native gather ABI - rank-3 routed expert banks dynamically mix IQ1_S/IQ2_XXS gate/up with IQ4_NL down tensors; released runtime evidence does not establish a matching mixed-format sparse native-block MoE ABI - these tensors are not ordinary affine rank-2 `MatMulNBits` - float32 dequantization would materialize roughly 191 GiB for the PLE table alone, exceeding the bounded 8 GiB single-tensor policy The exact header/config/mapping support is therefore a truthful preflight foundation for future ABI work, not a quantized-runtime claim. ## Validation - targeted Qwen4Exp/GGUF/registry review suite: `1187 passed, 2 skipped` - complete GGUF + Qwen4Exp + graph serial suite: `4865 passed, 54 skipped` - broad serial non-integration suite: `8409 passed, 64 skipped, 12 deselected, 1 subtest passed` - `lintrunner f --output oneline --all-files && lintrunner -a`: clean - GPT-5.6 Sol medium review run twice; fused-HF compatibility, complete qtype evidence, config pinning, and Hub fallback findings were resolved ## Waivers - No full payload download, real-weight runtime execution, L4, or L5 claim is made for the GGUF route. The exact pinned artifact is deliberately rejected before its 72+ GB payload is downloaded because neither supported native preservation nor bounded dequantization is truthful under the current Mobius/ORT ABI. - Runtime support remains deferred. This PR must not be interpreted as ORT or ORT GenAI execution evidence for the quantized artifact. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
10 tasks
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.
Summary
qwen4_exp_textdecoder forQwen/Qwen3.8-Flash-Next@f5d08274bafd880402bd16f5e3e6c514136ec06cand Transformers598d8ba8baaec7fec5a22da0e2844c7bf4ea20e1Validation
37 passed, 7 skipped, 1857 deselected8377 passed, 64 skipped, 12 deselected, 1 subtest passedlintrunner init && lintrunner f --output oneline --all-files && lintrunner -a: no lint issuesmtp.*tensors, 128 PLE shards, and official packed expert/shared-gate namesFail-closed guards
qwen4_expexport requirestext_only=True; multimodal export is not silently aliasedWaivers
mtp.*; unsupported contracts fail closed rather than exporting approximate behavior.