Skip to content

feat(xla): add gated delta-rule primitive and probe - #3607

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-3352-gated-delta-primitive
Dec 1, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-3352-gated-delta-primitive

Conversation

@inureyes

@inureyes inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Adds the matrix-valued delta-rule primitive that Qwen3-Next / Qwen3.5 (GatedDeltaNet) and Kimi-Linear (KDA) need in place of the selective scan: one decode step and a chunk-64 prefill with a fixed 64-step forward substitution, f32, matching HF torch_recurrent_gated_delta_rule and torch_chunk_gated_delta_rule. This is the contract #3353/#3354 consume; model wiring is deferred there.

What changed

  • src/lib/mlxcel-xla/src/emitter/delta.rs and delta_chunk.rs: DeltaGate (Scalar / PerChannel), DeltaConfig, delta_step, delta_prefill. Prefill batches chunks, solves (I + T)[Wv | R] by forward substitution, and scans the T/64 inter-chunk states the way HF and MLX do. Padded rows get g = 0, beta = 0 in-graph.
  • emit_delta_probe in emitter/model.rs, its dump test in emitter/mod.rs, and delta_probe.rs (probe spec, IREE auxiliary runner, XlaCache::DeltaProbe).
  • examples/xla_ssm_probe.rs --kernel delta, plus spike/openxla/delta_oracle.py, delta_gate.sh and delta_lowering_measure.py.
  • spike/openxla/FINDINGS_ssm.md addendum: per-case max-abs table for both gate modes on local-task and hip, and compile time / op / dispatch counts at capacity 256 and 4096.

Validation

Every delta gate case passed on both devices (11/11 each, tolerance 5e-5), worst max-abs 9.54e-7 (hip, per-channel full prefill). The per-case table and the exact commands are in the FINDINGS_ssm.md addendum; the two reproductions are:

MLXCEL_ORACLE_PYTHON=spike/openxla/.venv/bin/python spike/openxla/delta_gate.sh /tmp/delta-gate-local local-task
MLXCEL_ORACLE_PYTHON=spike/openxla/.venv/bin/python scripts/rocm_gpu_guard.sh --hold -- spike/openxla/delta_gate.sh /tmp/delta-gate-hip hip

Lowering at tiny probe dims (ops / dispatches / llvm-cpu compile s / rocm compile s): scalar 256 597 / 115 / 4.41 / 1.20, scalar 4096 1917 / 475 / 24.62 / 6.61, per-channel 256 601 / 116 / 4.80 / 1.20, per-channel 4096 1921 / 476 / 22.01 / 6.40. The 64-step substitution is the fixed part (~509 ops); capacity only adds the 22-op inter-chunk scan per chunk.

Also clean locally: cargo test --profile test-fast -p mlxcel-xla --lib (602 passed, dense goldens included), cargo test ... --lib delta, cargo clippy -p mlxcel-xla --lib --tests -- -D warnings, cargo fmt --all -- --check.

Closes #3352

Adds the matrix-valued delta-rule recurrence Qwen3-Next / Qwen3.5 (GatedDeltaNet) and Kimi-Linear (KDA) need: a one-step form and a chunk-64 prefill with a fixed 64-step forward substitution, both f32 and matching HF torch_recurrent_gated_delta_rule / torch_chunk_gated_delta_rule. The scalar and per-channel gates share the primitive through DeltaConfig.

A one-layer IREE probe (emit_delta_probe, examples/xla_ssm_probe.rs --kernel delta, delta_oracle.py, delta_gate.sh) passes every acceptance case on local-task and hip at 5e-5. FINDINGS_ssm.md records compile time, op and dispatch counts at capacity 256 and 4096. Model wiring stays with #3353/#3354.

Refs #3352
MLXCEL_DELTA_GATE, MLXCEL_DELTA_MODE and MLXCEL_DELTA_T are read only from
the opt-in #[ignore] dump test in emitter/mod.rs, so they join the existing
MLXCEL_SSM_MODE and MLXCEL_SSM_T entries in the same allowlist block.
verify-env-var-docs fails without them.
@inureyes
inureyes force-pushed the feature/issue-3352-gated-delta-primitive branch from a6472f0 to 63d2d35 Compare December 1, 2026 08:15
@inureyes
inureyes marked this pull request as ready for review December 1, 2026 08:23
@inureyes
inureyes merged commit 69740c5 into main Dec 1, 2026
36 checks passed
@inureyes
inureyes deleted the feature/issue-3352-gated-delta-primitive branch December 1, 2026 08:23
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 1, 2026
@inureyes inureyes added area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority type:enhancement New features, capabilities, or significant additions 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): gated delta-rule primitive (chunked prefill + step decode)

1 participant