Skip to content

feat(xla): add Plamo2 hybrid support - #3449

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-3347-plamo2-hybrid
Nov 26, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-3347-plamo2-hybrid

Conversation

@inureyes

@inureyes inureyes commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Closes #3347

Adds PLaMo 2 (model_type: plamo2, e.g. pfnet/plamo-2-1b) to the XLA emitter as a hybrid of a Mamba2-variant mixer and sliding-window attention.

  • New SsmKind::Plamo2 mixer in its own module, built from the shared conv and selective-scan helpers: per-head interleaved z/x in_proj, bcdt_proj split into [B N, C N, dt R] with R = max(64, hidden/16), a weighted RMSNorm on each piece, dt_proj, no gated output norm. Mamba1 and the SSD internals are untouched apart from one exhaustive-match arm.
  • Four offset norms per block (1, 1/5, 1, 1/5^1.5) and the final norm (1), added to the weights in the graph.
  • Q/K: weightless per-head RMSNorm with eps 1e-6, then the learned [heads, d] scale.
  • Window: HF keeps keys with age <= 2048 while the emitter band keeps age < W, so the band is stored as W + 1. No shared mask code changed.
  • Plain RoPE. The base config's Llama3 scaling was inherited at first and only showed at long positions; the window probe caught it and a unit test now pins it.
  • Checkpoint shape validation, f32 pin, and refusal by the prompt cache and APC (with a test).

Oracle and known differences

The HF remote code needs mamba_ssm / causal_conv1d (CUDA builds), so the 40-token oracle is the MLX eager CPU run of src/models/plamo2.rs, not HF. Synthetic parity uses an independent float64 pure-PyTorch reimplementation of the HF formulas (spike/openxla/plamo2_oracle.py).

dt is clamped to (0.001, 100) to match MLX eager; HF does not clamp. Padded prefill rows get dt = 0 after the clamp, so the floor does not revive them.

Validation

Logs are in spike/openxla/plamo2_reference/.

  • validate_arch.sh --device cuda --batch 4 --requests 8 --maxcap 24: structural, 40/40 token-exact and serve reference-exact all pass.
  • CLI 40/40 against the oracle; four concurrent server completions equal their CLI outputs in plain HTTP and SSE (8/8 text and token counts) on CUDA.
  • Hybrid synthetic parity (single-sequence tokens, ragged logits, slot recycling): worst logit delta 6.9e-6 on local-task, 1.0e-5 on CUDA, tolerance 3e-4. Removing the dt clamp moves these logits by 4e-3 to 4e-2.
  • Window probe at 2047-2051 tokens across prefill, decode and ragged, plus W - 1 and W + 1 controls that follow the exclusive and one-wider masks: worst delta 5.4e-6 on CUDA, nearest wrong variant 5.9e-3 and different tokens.
  • mlxcel-xla lib tests, new goldens registered, existing goldens byte-identical; fmt, clippy, env-var docs and Used-by checks pass.

Not run: ROCm. The CLI/server check compares CLI and server text and token counts but does not re-decode ids in Python, since the checkpoint ships tokenizer.jsonl only.

PLaMo 2 interleaves a Mamba2-style mixer with sliding-window attention, so the emitter gains a dedicated SsmKind::Plamo2 mixer (per-head interleaved z/x in_proj, bcdt_proj split into B, C and a rank-R dt, each with a weighted RMSNorm, dt_proj, no gated output norm) built from the shared conv and selective-scan helpers, plus a Plamo2Mamba layer kind on the generic weight path. Norm offsets (1, 1/5, 1, 1/5^1.5, final 1) are added to the weights in the graph, Q/K use a weightless per-head RMSNorm (eps 1e-6) with a learned [heads, d] scale, and the local band is stored as W + 1 to reproduce HF's inclusive age <= W mask. RoPE is plain; the Llama3 scaling inherited from the base config only showed at long positions and was caught by the window probe.

dt is clamped to (0.001, 100) like MLX eager (HF does not clamp), and padded prefill rows get dt = 0 after the clamp. Checkpoint shapes are validated per layer, the config pins f32 and is refused by the prompt cache and APC.

Validated on local-task: tiny-config unit tests and goldens, a pure-PyTorch float64 reference (hybrid parity across single and ragged graphs with slot recycling, and a 2047-2051 token window probe with W-1 and W+1 controls), and 40/40 tokens against the MLX oracle for pfnet/plamo-2-1b.

Refs #3347
@inureyes inureyes added status:in-progress Currently being worked on type:enhancement New features, capabilities, or significant additions labels Nov 26, 2026
The hybrid parity tolerance was 5e-3, below one of the dt-clamp effects the fixture generator reports (4e-3 to 4e-2), so it could not prove the clamp is present. It is now 3e-4 and the test prints its worst ragged logit delta (6.9e-6 on local-task, 1.0e-5 on CUDA).

Adds the CUDA logs: validate_arch.sh (structural, 40/40 token-exact, batch 4 / requests 8 reference-exact), the window probe for all graph flavors, the 40-token real-checkpoint oracle, and the CLI versus four concurrent server completions in plain HTTP and SSE.

Refs #3347
@inureyes inureyes added status:review Under review priority:medium Medium priority priority:low Low priority area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) and removed status:in-progress Currently being worked on priority:medium Medium priority labels Nov 26, 2026
Record the block structure, the inclusive 2048 sliding window stored as W + 1, the inherited Llama3 RoPE scaling bug found by the window probe, the MLX-matching dt clamp, the MLX eager oracle choice, CPU and CUDA acceptance results, and the ROCm handoff.
@inureyes

Copy link
Copy Markdown
Member Author

ROCm gfx1151 validation at 68e4c47a

Head 68e4c47afff3aa846f5e5969766ca071044ca158. Radeon 8060S (gfx1151), IREE 3.12.0rc20260721 @ dc9601f, oracle venv torch 2.12.1+cpu. 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 pfnet/plamo-2-1b@92c75fd6 with tokenizer.jsonl; every file matches that revision's HF hashes.

All three checks pass.

check result
validate_arch.sh --model models/hf/plamo-2-1b --device hip --batch 4 --requests 8 --maxcap 24 --oracle spike/openxla/plamo2_reference/oracle.json exit 0: structural PASS, token-exact 40/40 against the MLX eager oracle, serve reference-exact (8 requests, 170 tokens)
xla_plamo2 (test-fast, fixtures from plamo2_oracle.py) 3/3
plamo2_synthetic_parity single-sequence tokens exact; worst ragged logit delta 1.01e-5 (tol 3e-4)
plamo2_window_probe (2047 to 2051) window, window_minus and window_plus each match their inclusive, exclusive and plus masks; worst deltas 5.5e-6, 3.7e-6, 2.7e-6; nearest wrong variant 5.9e-3
plamo2_original_checkpoint_oracle_tokens 40/40 oracle tokens match on hip
plamo2_cli_server_check.py --device hip CLI 40/40 token-exact with the oracle; 4 HTTP and 4 SSE concurrent completions equal their CLI references in text and token count (8/8)

In validate_arch the batched serve phase ran at 7.81 tok/s against a 19.36 tok/s sequential baseline (0.4x). This does not affect the gate. Plamo2 is f32-pinned and 1B, so it is context only.

Binaries for the CLI/server check were the test-fast build at the head (mlxcel 175d5c58…, mlxcel-server 80ea588b…). Commands, logs, fixtures and responses are in acceptance/pr3449/68e4c47afff3aa846f5e5969766ca071044ca158/ on the ROCm host. Nothing was pushed or merged.

@inureyes
inureyes marked this pull request as ready for review November 26, 2026 11:40
@inureyes
inureyes merged commit 01e6516 into main Nov 26, 2026
24 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-3347-plamo2-hybrid branch November 26, 2026 11:40
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 26, 2026
inureyes added a commit that referenced this pull request Nov 26, 2026
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 inureyes mentioned this pull request Nov 26, 2026
6 of 7 tasks
inureyes added a commit that referenced this pull request Nov 26, 2026
* feat(xla): add Jamba hybrid Mamba1, attention, and MoE support

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

* fix(xla): compile softmax MoE decodes without aggressive fusion

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

* update(xla): record Jamba CUDA and CPU acceptance evidence

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

* update(xla): test the softmax-MoE decode fusion choice without IREE

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

* docs(xla): add Jamba findings and technical reports

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.

* update(xla): record Jamba acceptance after the Plamo2 rebase

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 added a commit that referenced this pull request Nov 27, 2026
…#3471)

Main has been red in `mlxcel-xla` since #3434 (db3a231): `registered_fixtures_are_byte_exact` and `emit_all_reproduces_registered_goldens` fail on `plamo2/prefill.mlir`. #3434 replaced the `reduce_window` cumsum in the Mamba2 SSD scan with a shifted-add prefix sum and regenerated the nemotron_h and falcon_h1 goldens, but the plamo2 fixture added by #3449 was frozen against the old scan.

This re-freezes the registered goldens with `MLXCEL_FREEZE_GOLDENS=1`. Only `plamo2/prefill.mlir` and `plamo2/prefill_logits.mlir` change, and the op counts differ only by the expected substitution: 6 `reduce_window` ops are replaced by shifted `pad`, `slice` and `add`, the same pattern as the nemotron_h regeneration in #3434. No emitter code changes.

## Validation

- `cargo test -p mlxcel-xla --lib`: 585 passed, 0 failed (2 failed on main).
- `scripts/xla/validate_arch.sh --model models/plamo-2-1b --device metal`: structural gate passes. The execution tier could not run on this host because the checkpoint ships `tokenizer.jsonl` only and the trajectory dump reads `tokenizer.json`, the same limit #3449 recorded. The scan change itself was validated in #3434.
@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

area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:low Low 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): Plamo2 (Mamba2 variant with dt/B/C RMSNorms) hybrid

1 participant