Skip to content

Add exact Qwen4Exp text core - #655

Merged
justinchuby merged 7 commits into
mainfrom
justinchuby-finish-qwen4exp-core
Aug 27, 2026
Merged

justinchuby merged 7 commits into
mainfrom
justinchuby-finish-qwen4exp-core

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • add the pinned qwen4_exp_text decoder for Qwen/Qwen3.8-Flash-Next@f5d08274bafd880402bd16f5e3e6c514136ec06c and Transformers 598d8ba8baaec7fec5a22da0e2844c7bf4ea20e1
  • implement the 3:1 Gated-DeltaNet/QSA schedule, hyper-connections, routed plus shared MoE, PLE hashing/convolution, and heterogeneous cache ABI
  • preserve the BF16 checkpoint contract by keeping DeltaNet recurrence and recurrent state in float32
  • make QSA exact for non-contiguous masks and validate official packed experts, deterministic hash buffers, and all PLE shards fail-closed
  • register the standalone text route while rejecting unsupported multimodal export and dedicated MTP embeddings

Validation

  • targeted Qwen4Exp/DeltaNet/build/weight tests: 37 passed, 7 skipped, 1857 deselected
  • exact pinned Transformers reduced-model parity: prefill, token-by-token decode, and non-contiguous-mask parity passed
  • broad serial suite: 8377 passed, 64 skipped, 12 deselected, 1 subtest passed
  • lintrunner init && lintrunner f --output oneline --all-files && lintrunner -a: no lint issues
  • GPT-5.6 Sol medium review: no significant findings
  • pinned checkpoint index verified: 31 ignored mtp.* tensors, 128 PLE shards, and official packed expert/shared-gate names

Fail-closed guards

  • rejects invalid heterogeneous schedules, linear head ratios/dimensions, QSA dimensions/budgets, PLE dimensions/sharding, non-float32 recurrent state, and dedicated MTP embeddings
  • rejects malformed packed expert tensors, changed deterministic hash buffers, missing/extra PLE shards, and wrong reconstructed PLE table shapes
  • composite qwen4_exp export requires text_only=True; multimodal export is not silently aliased

Waivers

  • Full-checkpoint L2/L4/L5 and CLI export were not run locally: the pinned model includes a roughly 95 GiB PLE embedding table and is not a practical local golden fixture. The independently instantiated pinned Transformers reduced model provides full-logit L3 parity.
  • BF16 execution was structurally validated through the graph/state ABI. Stock local ORT CPU cannot execute BF16 MatMul and expands standard BF16 Attention through an unsupported mixed-type internal Add; no CUDA runner was available.
  • The MTP sidecar and multimodal wrapper are intentionally out of scope. The pinned official causal runtime ignores mtp.*; unsupported contracts fail closed rather than exporting approximate behavior.

justinchuby and others added 2 commits August 26, 2026 08:47
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]>
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 26, 2026 16:25
Comment thread src/mobius/models/qwen4_exp.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and Qwen4ExpCausalLMTask to build the exact text-core graph + cache ABI and register qwen4_exp, qwen4_exp_text, and Qwen4ExpForConditionalGeneration routes.
  • 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 separate num_experts knob 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.

Comment thread src/mobius/models/qwen4_exp.py Resolved
Comment thread src/mobius/_configs/_base.py Resolved
@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing ee521b0 → feae79c

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

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]>
@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing ee521b0 → feae79c

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 324 KB 324 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 265 265 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 127 127 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 450 450 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

justinchuby and others added 4 commits August 26, 2026 11:14
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
justinchuby merged commit 4ee4580 into main Aug 27, 2026
23 of 26 checks passed
@justinchuby
justinchuby deleted the justinchuby-finish-qwen4exp-core branch August 27, 2026 05:09
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants