Skip to content

feat(xla): add Jamba hybrid support - #3448

Merged
inureyes merged 6 commits into
mainfrom
feature/issue-3349-jamba-hybrid
Nov 26, 2026
Merged

inureyes merged 6 commits into
mainfrom
feature/issue-3349-jamba-hybrid

Conversation

@inureyes

@inureyes inureyes commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds Jamba (model_type: jamba) to the OpenXLA/IREE backend: Mamba1 blocks with learned dt/B/C RMSNorms, attention blocks without RoPE, and a dense or softmax-routed MoE FFN after every block.

  • SsmKind::Mamba1 carries BcdtNorm (None, Weightless, Weighted). Falcon-Mamba stays weightless with an unchanged op sequence; Jamba reads dt_layernorm, b_layernorm and c_layernorm.
  • A recurrent layer that has an FFN goes through the general layer path (mixer weights last, pre_ff_layernorm as the post-mixer norm). Pure SSM layers keep their short list, so every existing golden is byte-identical.
  • Routing follows HF JambaSparseMoeBlock: softmax over all experts, top-k, no renormalization. The MLX reference (src/models/jamba.rs) renormalizes the selected weights; that path is not changed here.
  • MoE weights load from the stacked switch_mlp layout with feed_forward.router. Raw per-expert HF checkpoints are refused at load with a missing switch_mlp tensor error (the real 3B checkpoint is dense).
  • Softmax-MoE decodes compile without aggressive fusion (Config::has_softmax_moe): with it, IREE 3.12.0rc20260721 cannot lower the fused router softmax and top-k argmax on llvm-cpu or CUDA. This changes the decode compile flags for every softmax-routed MoE family, not only Jamba: the committed Qwen2-MoE and OLMoE ragged goldens fail to compile with the flag and compile without it. No real Qwen2-MoE or OLMoE checkpoint was re-run here, and their decode throughput without the flag is unmeasured.

Test plan

Rebased onto main 01e6516b (Falcon-H1 plain RoPE #3452, Plamo2 #3449). Integrated runtime source b9b5545a, with fresh release binaries, re-passed on GB10 CUDA: every registered golden byte-exact (PLAMO2, FALCON_H1, JAMBA included), clippy -p mlxcel-xla --all-targets -D warnings, guard tests 9/9, Jamba 3B validate_arch.sh b4 n8, the 40-token engine test, CLI 40/40, server 8/8, and Jamba synthetic parity on CUDA and local-task. The Plamo2, Falcon-H1, Mamba SSM single-seq/state-carry and Nemotron-H --ignored suites also passed on CUDA. Logs: spike/openxla/jamba_reference/integrated-*. The rows below are from the first run at 76a3dc4c.

Device runs used release binaries built at 76a3dc4c; later commits only move the softmax-MoE predicate onto Config (same behaviour, local-task parity rerun) and add evidence on NVIDIA GB10, IREE 3.12.0rc20260721, f32. Logs, commands and binary hashes are in spike/openxla/jamba_reference/.

  • cargo test -p mlxcel-xla --lib (573 passed, every previous golden byte-identical), fmt, clippy -D warnings; check_env_var_docs.py (plus 15 pytest cases) and check_used_by.py
  • Prompt-cache/APC guard: an_emitter_loadable_jamba_gets_no_prompt_cache_or_apc (8/8 guard tests)
  • Real 3B, CUDA: validate_arch.sh --device cuda --batch 4 --requests 8 --maxcap 24 exits 0 (goldens, 40/40 HF oracle tokens, 170 reference-exact batched tokens); engine test 40/40
  • Real 3B, CUDA: CLI 40/40 oracle; four concurrent non-streaming and four SSE completions equal CLI displayed stdout and token counts (8/8)
  • Seeded 4-block MoE fixture vs HF fp32 on local-task and CUDA: ragged logits within 3e-4 (max abs 2.0e-6 and 3.6e-6), CLI 12/12, xla_oracle_check token-exact, xla_batch_bench reference-exact (B=4, N=8)
  • Flag choice: softmax_moe_selects_the_unfused_decode_compile runs in the default lib tests. The iree-gated softmax_moe_decode_drops_aggressive_fusion is type-checked only, since that test binary cannot link without the root crate.
  • Clippy with --features iree,test-support reports four pre-existing private_interfaces errors in IreeRaggedLlama prefill methods that this branch does not touch.
  • ROCm (external)

Closes #3349

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority labels Nov 26, 2026
Jamba interleaves Mamba1 and attention blocks and ends every block in a dense or softmax-routed MoE FFN. The emitter rejected model_type jamba, and every recurrent layer was assumed to be a pure SSM block without an FFN.

- jamba_config parses the HF JambaConfig: attention and expert schedules from their period/offset, Mamba1 with learned dt/B/C RMSNorms, no RoPE, and HF routing (softmax over all experts, top-k, no renormalization). num_experts = 1 keeps every FFN dense.
- SsmKind::Mamba1 now carries a BcdtNorm (None, Weightless, Weighted). Falcon-Mamba stays Weightless and emits the same ops; Jamba takes dt_layernorm, b_layernorm and c_layernorm after D.
- A recurrent layer with an FFN goes through the general layer path (mixer weights last, pre_ff_layernorm as the post-mixer norm). Pure SSM layers keep the short list, so existing goldens are byte-identical.
- The WeightScheme::Jamba names reuse Falcon-H1's outer names, read the MoE router as feed_forward.router, and the checkpoint cross-check validates mixer norms, dense FFNs and stacked experts.
- A seeded four-block MoE fixture generator, registered goldens, emitter tests, an ignored device parity test, and a prompt-cache guard test for Jamba.

Refs #3349
The decode compile adds --iree-dispatch-creation-enable-aggressive-fusion for every dense config (#3043). With a softmax MoE router it fuses the softmax with the tuple-reduction top-k argmax into one dispatch that llvm-cpu and CUDA cannot lower ('vector.store' op write affecting operations on global resources are restricted to workgroup distributed contexts, IREE 3.12.0rc20260721). The Jamba MoE ragged decode failed this way on local-task, and the committed Qwen2-MoE and OLMoE ragged goldens fail the same way with the flag and compile without it.

A config with a softmax-routed MoE now keeps the compiler defaults for its decode, like Gemma3n. Sigmoid routing (#3411) already uses a single-result argmax and keeps the flag, and no emitted graph changes.

Refs #3349
Logs from runtime source 76a3dc4 on NVIDIA GB10 (IREE 3.12.0rc20260721, f32): validate_arch.sh batch 4 / requests 8 on the real AI21-Jamba-Reasoning-3B checkpoint (registered goldens, 40/40 HF oracle tokens, 170 reference-exact batched tokens), the 40-token engine test, CLI 40/40 plus four concurrent non-streaming and SSE completions equal to CLI stdout, and the seeded MoE fixture on local-task and CUDA (ragged logits within 3e-4 of HF, CLI 12/12, oracle check and batch bench exact). provenance.json lists every command, binary hash, and what was not verified.

Refs #3349
The decode-flag unit test lives in an iree-gated module whose test binary cannot link on its own (the runtime archives are linked by the root crate), so it was only type-checked. The softmax-router predicate moves to Config::has_softmax_moe, which the default lib tests now exercise for Jamba MoE, dense Jamba, Qwen2-MoE, OLMoE, Llama, and sigmoid-routed Nemotron-H. Behaviour is unchanged.

Also records that the raw per-expert HF MoE layout is refused at load with a missing switch_mlp tensor error.

Refs #3349
Record the weighted dt/B/C norm design, HF routing choice, the softmax-MoE decode fusion exemption (Qwen2-MoE and OLMoE ragged decode goldens also fail to compile with aggressive fusion on main), the synthetic MoE fixture, CUDA and CPU acceptance results, and the ROCm handoff.
@inureyes
inureyes force-pushed the feature/issue-3349-jamba-hybrid branch from 4dc7da5 to b9b5545 Compare November 26, 2026 12:06
The branch was rebased onto main 01e6516 (Falcon-H1 plain RoPE #3452, Plamo2 #3449). The integrated-* logs come from runtime source b9b5545 on NVIDIA GB10: every registered golden byte-exact, clippy --all-targets clean, the Jamba 3B validate_arch gate, the 40-token engine test, CLI 40/40 and 8/8 concurrent server parity, and the Jamba synthetic MoE parity on CUDA and local-task. The Plamo2, Falcon-H1, Mamba SSM and Nemotron-H CUDA suites pass too. The provenance and the report validation sections name the new head.

Refs #3349
@inureyes

Copy link
Copy Markdown
Member Author

ROCm gfx1151 validation at a3bd4e82

Head a3bd4e828d166f7d70c444dd557c59ea9af7d423 (rebased on 01e6516b). Radeon 8060S (gfx1151), IREE 3.12.0rc20260721 @ dc9601f, oracle venv torch 2.12.1+cpu / transformers 5.12.1. MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_ROCM_TARGET=gfx1151 MLXCEL_XLA_PRECISION=f32; every device command ran under scripts/rocm_gpu_guard.sh --hold. Checkpoint ai21labs/AI21-Jamba-Reasoning-3B@75243704: every model and tokenizer file matches that revision's HF hashes (only the README images are absent).

All five items pass.

item result
(1) validate_arch.sh --model models/hf/jamba-3b --device hip --batch 4 --requests 8 --maxcap 24 --oracle spike/openxla/jamba_reference/hf-f32-oracle.json exit 0: structural PASS, 40/40 token-exact, serve reference-exact (8 requests, 170 tokens)
(2) jamba_moe_fixture.py then jamba_moe_hf_synthetic_parity pass: 4 cases x 8 steps match HF on hip, max abs 2.98e-6; generator controls: norm-weight 0.222, renorm 0.020
(3) falcon_h1_cli_server_check.py --device hip --model models/hf/jamba-3b --oracle ... --checkpoint-revision 75243704... CLI 40/40 token-exact; 4 HTTP and 4 SSE concurrent completions equal the displayed CLI text and token count (8/8)
(4) xla_plamo2 --ignored (fixtures from the #3449 run) 3/3, same numbers as at 68e4c47a (synthetic 1.01e-5, window probe worst 5.5e-6, 40/40 tokens)
(4) xla_falcon_h1 --ignored (fixtures from the #3452 run) 3/3, same numbers as at 6a7d3968 (long positions worst 8.39e-5, argmax all match, 40 tokens)

(5) Softmax-routed MoE decode without aggressive fusion

There is no real Qwen2-MoE or OLMoE checkpoint on this host, so I checked it two ways:

  • Committed goldens, compiled for gfx1151 with --iree-input-type=stablehlo --iree-hal-target-device=hip --iree-rocm-target=gfx1151. decode.mlir and decode_ragged_logits_b4.mlir for qwen2-moe-tiny and olmoe-tiny all compile without the fusion flag. As a control, with --iree-dispatch-creation-enable-aggressive-fusion added, both decode.mlir still compile but both ragged b4 goldens fail on ROCm too ('vector.transfer_write' op write affecting operations on global resources are restricted to workgroup distributed contexts).
  • End-to-end on hip. I built tiny random checkpoints (seed 3448) from the two asset configs: an HF directory for the HF fp32 oracle (prompt w1 w2 w3 w4 w5, 40 tokens, minimum top-2 gap 3.8e-3 and 5.8e-3) and the same weights restacked into the switch_mlp layout for the XLA loader. validate_arch.sh --device hip --batch 4 --requests 8 --maxcap 24 --oracle <that oracle> exits 0 for both: 40/40 token-exact single-sequence, serve reference-exact across 8 requests through the ragged b4 decode.

Binaries for (3) were the test-fast build at the head (mlxcel f7286bd6…, mlxcel-server 28f6db81…). Commands, logs, the tiny-checkpoint builder and oracles are in acceptance/pr3448/a3bd4e828d166f7d70c444dd557c59ea9af7d423/ on the ROCm host. Nothing was pushed or merged.

@inureyes
inureyes marked this pull request as ready for review November 26, 2026 15:03
@inureyes
inureyes merged commit ed7f31e into main Nov 26, 2026
1 check passed
@inureyes
inureyes deleted the feature/issue-3349-jamba-hybrid branch November 26, 2026 15:03
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 26, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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): Jamba hybrid (Mamba1 + attention + softmax MoE)

1 participant