Skip to content

feat(xla): add Qwen3-Next and Qwen3.5 text hybrids (GatedDeltaNet) - #3614

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-3353-qwen3-next-qwen35
Dec 1, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-3353-qwen3-next-qwen35

Conversation

@inureyes

@inureyes inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Closes #3353.

Adds the Qwen3-Next and Qwen3.5 text hybrids to the OpenXLA / IREE emitter (mlxcel-xla): GatedDeltaNet linear-attention layers interleaved with gated full attention, a softmax-routed MoE with a gated shared expert, and the two checkpoint layouts that share the math.

What changed

  • emitter/qwen3_next_config.rs (new): parse qwen3_next and the Qwen3.5 VLM wrapper (text_config with model_type = qwen3_5_text, vision tower ignored). Reads layer_types / full_attention_interval, the delta dimensions and conv kernel, the MoE schedule, rope_parameters (rope_theta, partial_rotary_factor), the (1 + w) norm style, per-head (1 + w) q/k norms and attn_output_gate.
  • emitter/delta_model.rs (new): the GatedDeltaNet mixer. Unwraps the fused Qwen3-Next in_proj_qkvz / in_proj_ba per-key-head grouping (with element-count assertions, because a wrong grouping width only surfaces as a reshape error at IREE compile time), splits the separate Qwen3.5 projections, runs the short causal conv over the flat q | k | v with the carried tail, computes g = -exp(A_log) * softplus(a + dt_bias) and beta = sigmoid(b), advances the landed delta primitive, then the plain gated RMSNorm and out_proj.
  • emitter/model.rs: the per-head [query | gate] q_proj split, with sigmoid(gate) applied to the attention output before o_proj; ungated families keep their exact previous graph.
  • emitter/model_recurrent.rs: RecurrentLayers now holds an SSM row or a delta row per recurrent layer; the delta state advances per slot in ragged decode and the prefill threads real_len so padded rows stay inert.
  • emitter/delta.rs, recurrent_config.rs, config.rs: DeltaConfig accessors, MixerKind::GatedDelta, WeightScheme::Qwen35, delta / delta_fused_proj / q_gate config fields, state_tensors (delta_s, then delta_conv, both f32).
  • weights.rs, weight_names.rs, recurrent_checkpoint.rs, validation.rs: weight specs in load order, model.language_model.* names for the Qwen3.5 wrapper, split/fused projection validation, and the qwen3_next / qwen3_5 structural fixtures.

Evidence

Real Qwen/Qwen3.5-0.8B (revision 2fc06364715b967f1860aea9cf38778875588b17) on IREE hip:

  • scripts/xla/validate_arch.sh --model models/hf/qwen3.5-0.8b --device hip --batch 4 --requests 8 --maxcap 24 exits 0 (structural, token-exact, serve reference-exact).
  • CLI token ids equal the HF transformers fp32 oracle across 40 greedy tokens.
  • Four concurrent HTTP completions (non-stream and SSE) equal their separate CLI references in text and token counts; evidence committed under spike/openxla/qwen3_5_reference/.

Synthetic tiny Qwen3-Next (fused projections, 3 delta layers, 1 gated-attention layer, 4 experts plus a gated shared expert), fp32 HF Qwen3NextForCausalLM oracle:

  • xla_oracle_check --device hip token-exact, xla_batch_bench --device hip --batch 4 --requests 8 --maxcap 12 reference-exact.
  • Fixture generator, oracle and raw logs committed under spike/openxla/.

Local: 606 mlxcel-xla lib tests pass (24 ignored), the registered structural goldens are byte-identical (10/10), cargo fmt --check, cargo clippy -p mlxcel-xla --all-targets -D warnings, the CI clippy invocation (cargo clippy -p mlxcel --lib --tests -D warnings) and the verify-env-var-docs / verify-versions / verify-kernel-dtype-keys / verify-used-by gates all exit 0.

Notes

  • The real checkpoint is Qwen3.5's VLM release, but only its text tower is implemented; text_config.rope_parameters carries mrope_* keys that are ignored because text-only positions are identical across the m-rotary sections, which the token-exact gate confirms against HF.
  • The Qwen3.5 MTP head (mtp_* config keys) is not part of the causal-LM path and is not loaded.

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Dec 1, 2026
@inureyes
inureyes force-pushed the feature/issue-3353-qwen3-next-qwen35 branch from f497900 to 280627a Compare December 1, 2026 10:42
Add the Qwen3-Next and Qwen3.5 text hybrids to the OpenXLA / IREE emitter: GatedDeltaNet linear-attention layers interleaved with gated full attention, softmax-routed MoE with a gated shared expert, and the two checkpoint layouts that share the math.

Config parsing (`emitter/qwen3_next_config.rs`): read `layer_types` or `full_attention_interval`, the delta dimensions and kernel, the MoE schedule (`mlp_only_layers`, `decoder_sparse_step`), `rope_parameters` (`rope_theta`, `partial_rotary_factor`), the `(1 + w)` norm style, per-head `(1 + w)` q/k norms, and the `attn_output_gate` output gate. Qwen3-Next parses directly; the Qwen3.5 VLM wrapper unwraps `text_config` (`model_type = qwen3_5_text`) and ignores the vision tower, using the new `WeightScheme::Qwen35` for the `model.language_model.*` names.

Delta mixer (`emitter/delta_model.rs`): unwrap the fused `in_proj_qkvz` / `in_proj_ba` per-key-head `[q, k, v, z]` / `[b, a]` grouping (with element-count assertions, since a wrong grouping width is only a reshape error at compile time), split the separate Qwen3.5 `in_proj_qkv` / `in_proj_z` / `in_proj_b` / `in_proj_a`, run the short causal conv over the flat `q | k | v` with the carried tail, compute `g = -exp(A_log) * softplus(a + dt_bias)` and `beta = sigmoid(b)`, advance the landed delta primitive, then the plain gated RMSNorm and `out_proj`.

Threading: `MixerKind::GatedDelta` splits `RecurrentLayers` into SSM and delta state rows, `state_tensors` declares `delta_s` then `delta_conv`, the Jamba-style block order is reused, the delta state advances per slot in the ragged decode, and the prefill threads `real_len` so padded rows stay inert.

Attention: the `q_proj` per-head `[query | gate]` split multiplies the attention output by `sigmoid(gate)` before `o_proj`; ungated families keep their exact previous graph. Weights, checkpoint validation, weight names and the MFE/structural fixtures are extended for both layouts.

Evidence: the real `Qwen/Qwen3.5-0.8B` (revision 2fc06364715b967f1860aea9cf38778875588b17) is token-exact against an HF transformers fp32 oracle and reference-exact across four serving slots, and four concurrent HTTP completions equal their CLI outputs. A synthetic tiny Qwen3-Next checkpoint (fused projections, three delta layers, one gated-attention layer, four experts plus a gated shared expert) is token-exact against its `Qwen3NextForCausalLM` fp32 oracle and reference-exact in the batched engine. The oracle JSON, fixture generator and raw hip logs are committed under `spike/openxla/`.

Closes #3353
Adds the raw hip evidence for the Qwen3.5 text hybrid serving gate: the CLI 40-token HF fp32 oracle check and four concurrent non-stream and SSE completions per transport, each compared byte for byte with its separate CLI reference. The provenance records the checkpoint revision, the binary sha256 and the source commit 7fe37b4; the IREE VM cache is not committed.
@inureyes
inureyes force-pushed the feature/issue-3353-qwen3-next-qwen35 branch from 280627a to 50474da Compare December 1, 2026 10:43
@inureyes
inureyes force-pushed the feature/issue-3353-qwen3-next-qwen35 branch from 3f42fed to 3b0f6ff Compare December 1, 2026 10:49
@inureyes
inureyes marked this pull request as ready for review December 1, 2026 10:50
@inureyes
inureyes merged commit 3df900d into main Dec 1, 2026
35 of 36 checks passed
@inureyes
inureyes deleted the feature/issue-3353-qwen3-next-qwen35 branch December 1, 2026 10:50
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(xla): Qwen3-Next and Qwen3.5 text hybrids (GatedDeltaNet)

1 participant