Skip to content

fix(xla): replace the reduce_window cumsum in the Mamba2 SSD scan - #3434

Merged
inureyes merged 8 commits into
mainfrom
fix/issue-3343-mamba2-metal-ssd
Nov 26, 2026
Merged

inureyes merged 8 commits into
mainfrom
fix/issue-3343-mamba2-metal-ssd

Conversation

@inureyes

@inureyes inureyes commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

The production chunked SSD prefill returned NaN y and a wrong final state on IREE-Metal while local-task passed. IREE rewrites a left-padded prefix-sum stablehlo.reduce_window into iree_linalg_ext.scan, and the Metal target returns unrelated values for that op at rank 2 and above (a [3,3] module reproduces it without mlxcel). The -inf mask in exp_segsum was not the cause and is unchanged.

  • The scan's two prefix sums (acum and the masked segment sum in exp_segsum) are now a log-depth chain of slice, pad and add in f32 (prefix_add). Builder::reduce_window_prefix_add had no other caller and is removed.
  • The form is device-agnostic, so the emitted prefill StableHLO changes on every backend (capacity-256 probe: 191 to 237 lines, 3 reduce_window become 16 shifted-add levels; 20 levels at capacity 4096). Decode graphs are byte-identical. Summation is pairwise instead of sequential: on local-task f32 the probe output moves by at most 7.2e-7 and the error against HF stays at 3.3e-6 to 3.6e-6. No new tensor size class appears; the largest tensor is still [nc,H,q,q].
  • nemotron_h and falcon_h1 prefill goldens are regenerated deliberately (they share the scan); only the expected reduce_window to shifted-add replacement changed in them.
  • f16 near-tie rule: oracle_continuation.py --top2 records the oracle's per-step top-2 logit gap (opt-in; default output unchanged), near_tie_check.py judges a stream by its first divergence (exit 0 exact, 3 near-tie, 1 mismatch, 2 usage error, empty stream, malformed oracle, or a text divergence inside a word that only token ids can place), and xla_oracle_check prints the gap at the first divergence while keeping its strict exit status. Covered by spike/openxla/test_near_tie_check.py (12 cases, no model needed) and documented in spike/openxla/README.md.
  • spike/openxla/FINDINGS_ssm.md gains the IREE-Metal section with the full tables; src/lib/mlxcel-xla/README.md notes that Mamba2 validates on IREE-Metal.

Test plan

Apple M1 Ultra, IREE 3.12.0rc20260721, AntonV/mamba2-130m-hf at 05e8773f, device metal.

  • Probe, real mixer dims, f32: decode, padded 224/256, full, K-1 and 3584/4096 all within 5e-5 (worst y 1.5e-6, h 2.0e-6); before the fix y NaN, h 0.74. ssm_gate.sh tiny mixer: 6/11 before, 11/11 after.
  • Probe, f16: no NaN, y 7.7e-4 to 1.6e-3, within 1% of local-task f16. The emitted f16 graph keeps all five scan contractions and all prefix-sum adds in f32.
  • validate_arch.sh --model models/hf/mamba2-130m --device metal --batch 4 --requests 8 --maxcap 24: exit 0 at f32; exit 0 at f16 with --skip-structural (the goldens are f32 graphs).
  • xla_oracle_check and mlxcel generate -n 40, five prompts: 5/5 token-exact at f32; at f16 4/5 exact and one near-tie (token 14, top-2 logit gap 0.004593).
  • Server, 4 concurrent /v1/completions at temperature 0: 4/4 equal their CLI streams at f32; at f16 3/4 equal CLI and 4/4 are token-exact against the oracle (the differing CLI stream is the near-tie above).
  • Workspace gate (cargo test --workspace --profile test-fast --features metal,accelerate -- --test-threads=1): 17045 passed, 2 failed. Both failures are root-crate Metal byte-identity tests (deepseek_v2::verify_tests::without_the_scope_a_block_differs_from_the_chain_on_metal, inkling2::speculative::tests::the_verify_block_matches_the_chain_on_metal) that fail deterministically on this host on their own; that test binary does not link mlxcel-xla in this feature set, so they are independent of this PR and tracked separately.
  • cargo clippy -p mlxcel-xla --lib --tests -- -D warnings, cargo clippy --features xla-iree --example xla_oracle_check -- -D warnings, cargo fmt --check, python3 -m unittest spike/openxla/test_near_tie_check.py.
  • ROCm (hip) and CUDA re-validation of the changed prefill graph, including a before/after prefill timing at capacity 4096, and execution of the Nemotron-H and Falcon-H1 hybrids. These run on their own hosts before merge.

Closes #3343

The chunked SSD prefill returned NaN y and a wrong final state on IREE-Metal at f32 while local-task passed. IREE rewrites a left-padded prefix-sum stablehlo.reduce_window into iree_linalg_ext.scan, and the Metal target returns unrelated values for that op on any tensor of rank 2 or more (a [3, 3] input reproduces it outside mlxcel with iree-run-module). Both cumulative sums of the scan, the per-chunk log decay and the masked segment sum, went through it. The -inf mask in exp_segsum was not the cause and is unchanged.

The scan now builds its prefix sums as a log-depth chain of shifted adds (slice, pad, add) in f32. The form is device-agnostic, so the emitted StableHLO changes on every backend: the summation is pairwise instead of a sequential fold, which moves results in the last bits only. Builder::reduce_window_prefix_add had no other caller and is removed.

The nemotron_h and falcon_h1 prefill goldens are regenerated because those hybrids share the scan. New emitter tests pin that no prefill form emits reduce_window and that the prefix sum is a log-depth f32 chain. Narrow mlxcel-xla tests (validation, ssm, numeric_ops) and clippy pass.

Refs #3343
Reduced-precision runs (f16 on IREE-Metal) are judged by a near-tie rule: only the first divergence from the HF fp32 oracle counts, and it passes when the oracle's own top-2 logit gap there is below 0.01. No tool recorded that gap.

oracle_continuation.py takes an opt-in --top2 that adds ref_top2_ids and ref_top2_gaps to the oracle JSON; the default output is unchanged. near_tie_check.py judges a stream given as ids or as generated text against such an oracle (exit 0 exact, 3 near-tie only, 1 otherwise). xla_oracle_check prints the gap at its first divergence when the oracle carries it and keeps its strict exit status.

Refs #3343
FINDINGS_ssm.md gains the Metal section for #3343: the root cause (IREE-Metal returns unrelated values for iree_linalg_ext.scan at rank 2 and above, reproduced standalone), the fix, the probe table before and after at f32 and f16, compile times, throughput, and the model gates. f32 is exact on every gate. f16 has one divergence from the HF oracle, a near-tie with a top-2 logit gap of 0.004593.

near_tie_check.py learns --mlxcel-cli to read captured mlxcel generate stdout, and its text matcher no longer strips a trailing whitespace token from the oracle prefix, which had moved a divergence at a newline token two positions later.

Refs #3343
The Used-by comment on prefix_add listed only Mamba2, but the regenerated goldens show Nemotron-H and Falcon-H1 emit it too. The Metal findings table now carries the digits check.json reports, drops a claim that f16 Metal equals f16 local-task to three digits (the K-1 case differs by 0.4%), and records that the hybrids were not executed and what the local-task probe run time did.

Refs #3343
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) platform:macos macOS (Apple Silicon) specific type:test Test related changes area:architecture Architecture and code structure changes labels Nov 25, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Make the Mamba2 chunked SSD prefill correct on IREE-Metal by replacing the prefix-sum reduce_window (miscompiled as iree_linalg_ext.scan) with a device-agnostic log-depth shifted-add chain, and add the f16 near-tie tooling.

Findings Addressed

None needed fixing at CRITICAL or HIGH.

Remaining Items

  • near_tie_check.py text mode can attribute the first divergence to a later token when the stream's token text extends the oracle token (oracle the + cat, stream there), so the gap is read at the wrong index and a real mismatch could read as a near-tie (MEDIUM). The recorded f16 result is not affected: xla_oracle_check confirms the token-14 divergence by ids.
  • near_tie_check.py reports an empty stream (or an empty --ids) as TOKEN-EXACT with 0 tokens compared and exits 0 (MEDIUM). Treating compared == 0 as a usage error would keep the gate strict.
  • FINDINGS_ssm.md f16 row "padded prefill, before the fix" lists y 3.311 and h 8.674e28. The pre-fix measurement on main recorded NaN y/h for padded at f16 and h 8.7e28 for the full case, so this row may carry the full-case numbers under the padded label (MEDIUM, needs the raw check output to settle).
  • The prefix_add doc says the pairwise association carries less rounding error than the sequential fold, but the measured error against HF moved from 3.34e-6 to 3.58e-6 on y (LOW). Either drop the claim or say the error stays in the same order.
  • shift_along is a third copy of the slice-and-pad shift that numeric_ops.rs and gemma3n_audio_math.rs each implement privately (LOW, not worth churning the goldens over).

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow (selective_scan_prefill -> selective_scan_prefill_form -> chunked_ssd, used by Mamba2, Nemotron-H and Falcon-H1)
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass (emitter::ssm 16, emitter::recurrent 34, validation::tests 10; clippy -p mlxcel-xla --lib --tests -D warnings and fmt clean; the workspace gate is not covered here)

prefix_add is an inclusive Hillis-Steele scan along the same axis the removed reduce_window used. It is correct for length 1 (no levels), for non-power-of-two lengths, and for the nc+1 chunk-level segsum, and the dt = 0 padding rows are unchanged. The regenerated goldens differ only by the expected ops: 6 reduce_window removed, plus 32 slice/pad/add levels per graph (2 SSM layers x (7 + 7 + 2)).

…s row

near_tie_check.py now reports an empty stream as a usage error instead of TOKEN-EXACT, and reports a text divergence that falls inside a word as ambiguous (exit 2, use --ids), since text alone cannot tell whether the stream token extended the previous oracle token.

FINDINGS_ssm.md: the pre-fix Metal f16 padded-prefill row carried the full-prefill numbers; split it into the measured padded (NaN) and full (3.311 / 8.674e28) rows. The prefix_add doc comment no longer claims lower rounding error than the removed reduce_window.
@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

No CRITICAL or HIGH findings, so nothing was auto-fixed and no commits were added. Narrow checks pass on the branch head: emitter::ssm (16 tests), validation::tests (10 goldens), and clippy on mlxcel-xla lib and tests.

Performance

  • MEDIUM: the device-agnostic prefix_add adds memory passes on every backend. At capacity 4096 (chunk 128, 32 chunks) each SSM layer runs 20 shifted-add levels (7 for acum, 7 for the intra-chunk exp_segsum, 6 for the chunk-level decay_c), up from 3 reduce_window ops. The probe graph at real mamba2-130m dims grows from about 191 to 253 lines, so about 62 lines per SSM layer. Applied to the two local hybrid configs, that is about 1.4k extra lines for a 23-SSM-layer Nemotron-3 Nano and about 1.5k for a 24-layer Falcon-H1. Larger Falcon-H1 variants put an SSM mixer in every layer, so the growth scales with the layer count.
  • MEDIUM: the production-capacity cost on the non-Metal backends is not measured before and after. The recorded before/after is local-task at capacity 256 (0.016-0.020 s to 0.023-0.025 s). At 4096 the post-change local-task probe runs in 0.18 s, but no pre-change number exists for that capacity, and CUDA and ROCm were not re-run. The 7 levels on [nc, H, q, q] are the costly part: that is 50 MB at H=24 and about 134 MB at H=64 per level, so about 7x the read/write traffic of one pass over that tensor per layer. Worth one before/after prefill timing at 4096 on CUDA or ROCm when those hosts re-validate.
  • No new size class: the largest tensor in the 4096 graph is still [nc, H, q, q] (T x H x q elements), the same shape that masked and weights already had. No [T, H, P, N] tensor appears. The extra transient memory is a few live level buffers of that shape, not 7. Prefill is per sequence, so batching does not multiply it. acum ([nc, q, H]) and decay_c ([H, nc+1, nc+1]) are negligible.
  • LOW: shift_along emits a fresh 0.0 constant at every level. IREE CSEs these, so it only inflates the text.

Security

  • No unsafe was added. No secrets, host paths, or model-store layout appear in the diff, the regenerated goldens, the commit messages, or the PR body. The findings doc names the chip only.
  • The Python tools do no eval, exec, or subprocess calls, and they read only the JSON and text files passed on the command line.
  • LOW: near_tie_check.py calls AutoTokenizer.from_pretrained(args.model) without local_files_only=True. A --model value that is not a local directory is resolved as a Hub repo id and downloaded. trust_remote_code stays off, so no remote code runs.
  • LOW: judge() indexes ref_top2_gaps[index] without a length check, so a malformed oracle raises IndexError instead of the usage exit. A stream shorter than the oracle exits 0 when it matches the common prefix. The docstring documents that, and it is acceptable for this tool.

near_tie_check.py loaded the tokenizer with a bare AutoTokenizer.from_pretrained, which could fall back to a Hub download when --model was not a local directory. It now exits 2 unless --model is a local directory and passes local_files_only=True.

judge() indexed ref_top2_gaps and ref_top2_ids without checking their length, so a truncated or malformed oracle raised IndexError. It now exits 2 with a message when either array does not match ref_token_ids in length, the index is out of range, or a gap is not a number.

Add test_near_tie_check.py, a model-free unittest file using a fake decode, covering the ids, text, empty stream, ambiguous divergence and malformed-oracle paths. Document the --top2 flag, near_tie_check.py and the IREE-Metal Mamba2 validation in spike/openxla/README.md and the mlxcel-xla README.

Validation:
- python3 -m unittest spike/openxla/test_near_tie_check.py: 12 passed
- cargo test --profile test-fast -p mlxcel-xla --lib emitter::ssm: 16 passed
- cargo fmt --check and cargo clippy -p mlxcel-xla --lib --tests -- -D warnings: clean

Refs #3343
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 25, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Merge is held until the one unchecked test-plan item passes: the shifted-add prefix_add replaces reduce_window on every backend, so the CUDA and ROCm prefill graphs change too, and only Metal and local-task have run it. CI is green (19 pass, 14 skipped) and the branch is mergeable; it is 2 commits behind main (#3432, #3399) with no file overlap.

Remaining checks at this head (f3c771e3), each GPU command under gpu-lock run --tag xla-ssm on GB10 and scripts/rocm_gpu_guard.sh --hold -- on gfx1151:

  • Mamba2 on cuda and hip: xla_ssm_probe (all four cases, 5e-5) and scripts/xla/validate_arch.sh --model models/hf/mamba2-130m --device <dev> --batch 4 --requests 8 --maxcap 24.
  • Nemotron-H and Falcon-H1 (their prefill goldens were regenerated here): the same validate_arch.sh gate on hip, as recorded in spike/openxla/NEMOTRON_H_VALIDATION.md and FINDINGS_falcon_h1.md.
  • Prefill timing at capacity 4096 on cuda or hip, before (main) and after (this head): the review estimated up to about 7x the memory traffic on the [nc, H, q, q] passes.

Merge after those pass and their results are added to FINDINGS_ssm.md.

@inureyes

Copy link
Copy Markdown
Member Author

ROCm gfx1151 validation at f3c771e3

Head f3c771e3450890fd738eff73ba3a22d6f4519d17, merge-base 66bf600a. 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, default precision (recurrent pin resolves f32), release xla-iree build at the head. Every build and device command ran under scripts/rocm_gpu_guard.sh --hold. Checkpoints: AntonV/mamba2-130m-hf@05e8773f (original HF format), nvidia/Nemotron-H-4B-Base-8K@faba3b73, tiiuae/Falcon-H1-Tiny-90M-Instruct@e6389502.

All gates pass and match the #3340, NEMOTRON_H_VALIDATION.md and FINDINGS_falcon_h1.md records. There is no mismatch to report.

Mamba2 130M

check result
ssm_gate.sh OUT local-task hip 11/11 on each device; worst on hip y 1.43e-6, h 1.19e-6, conv 3.6e-7 (tol 5e-5)
validate_arch.sh --batch 4 --requests 8 --maxcap 24 exit 0: structural, HF token-exact, serve reference-exact (125.9 tok/s batched, 78.3 sequential)
HF fp32 oracle, five #3340 prompts regenerated; prompt and continuation ids identical to the #3340 oracles
mlxcel generate -n 40 and xla_oracle_check, five prompts 5/5 token-exact (CLI 135 to 149 tok/s)
xla_batch_bench B=4, 8 requests, 64-token prompt REFERENCE-EXACT PASS, 128.1 tok/s
same, oracle prompt, --cancel 2 PASS, 2/2 cancelled, 127.2 tok/s
same, oracle prompt, --buckets 256,512 PASS, every bucket routed, 102.3 tok/s
B=8, 16 requests (--maxcap 32, as in #3340) PASS, 111.4 tok/s
server, 4 concurrent /v1/completions, temperature 0, 24 tokens 4/4 equal their CLI streams, 24/24 completion tokens each, requests overlapped, prompt cache/APC disabled

"In computer science, a linked list is" has a minimum oracle top-2 gap of 0.0046 (the Metal f16 near-tie); it is exact at f32 here.

Prefill at capacity 4096 (before 66bf600a, after f3c771e3)

Fresh MLXCEL_CACHE_DIR per arm, f32.

measurement before after
whole model, uncached prefill compile (xla_ssm_model_check --compile-times) 2.52 s 3.51 s
whole model, uncached decode compile 1.51 s 1.50 s
whole model, 3584-token prefill, 3 runs 3.514 to 3.520 s (1019 tok/s) 3.626 to 3.645 s (986 tok/s)
single-layer probe 4096/3584, uncached compile 0.75 s 0.85 s
single-layer probe run, 4 runs 0.089 to 0.092 s (39.4K tok/s) 0.094 to 0.096 s (38.1K tok/s)

The prefill is 3.2% slower on the whole model and about 4% slower per layer. Against each other the two arms differ by at most 1.07e-4 on last-token logits (max 93.6), with the same argmax; decode logits are bitwise identical. Probe error against HF is unchanged (y 5.96e-6 on both). The split-prefill state difference in xla_ssm_model_check went from 9.9e-5 to 5.3e-4, while whole versus token-by-token decode logits stayed at 1.0e-3 (before) and 0.97e-3 (after).

Nemotron-H 4B

check result
HF fp32 oracle (--prompt 'The capital of France is' --max-new 40) ids identical to the committed nemotron_h_reference/hf-f32-oracle.json
xla_hybrid_nemotron_h (release, ignored) 5/5
validate_arch.sh --oracle <that file> --batch 4 --requests 8 --maxcap 24 exit 0: structural, token-exact 40/40, serve reference-exact (170 tokens)
CLI with MLXCEL_PRINT_TOKEN_IDS=1 40/40 ids equal the HF oracle
server, 4 concurrent /v1/completions, 40 tokens 4/4 equal their CLI references in text and completion token count, prompt cache/APC disabled
xla_ssm_single_seq, xla_ssm_state_carry 6/6, 5/5

Falcon-H1 Tiny 90M

check result
xla_falcon_h1 (fixtures regenerated, committed oracle) 2/2: synthetic parity, and the 40 original-checkpoint oracle tokens match on hip
validate_arch.sh --batch 4 --requests 8 --maxcap 24 (HF oracle from the venv) exit 0: structural, token-exact, serve reference-exact (133.0 tok/s)
falcon_h1_cli_server_check.py --device hip CLI 40/40 token-exact with the oracle; 8/8 non-stream and SSE responses match displayed CLI text and token count; the Germany completion keeps its " \n" suffix

Commands, logs, binary hashes and outputs are in acceptance/pr3434/f3c771e3450890fd738eff73ba3a22d6f4519d17/ on the ROCm host. Nothing was pushed or merged.

@inureyes

Copy link
Copy Markdown
Member Author

CUDA GB10 validation at f3c771e3

Head f3c771e3450890fd738eff73ba3a22d6f4519d17, merge-base 66bf600a. NVIDIA GB10 (sm_121, driver 580.178.04), IREE 3.12.0rc20260721 @ dc9601f, oracle venv torch 2.12.1+cpu / transformers 5.12.1. Release xla-iree build at the head, setup-cuda.sh --env, device cuda, default precision (recurrent pin resolves f32; Nemotron-H and Falcon-H1 commands set f32 explicitly as their docs do). Every GPU command ran under gpu-lock run --tag pr3434-cuda. Checkpoints were verified file by file against the Hub: AntonV/mamba2-130m-hf @ 05e8773f (README and .gitattributes absent), nvidia/Nemotron-H-4B-Base-8K @ faba3b73, tiiuae/Falcon-H1-Tiny-90M-Instruct @ e6389502.

Everything passed. No mismatch, so there is no divergence position to report.

Mamba2 130M

gate result
ssm_gate.sh OUT cuda (tiny mixer, 11 cases) 11/11 PASS; worst y 1.24e-6, h 1.19e-6, conv 3.6e-7
probe decode 1/1 y 2.623e-6, h 2.384e-7, conv 6.557e-7 (compile 0.71 s)
probe padded 256/224 y 2.503e-6, h 3.949e-7, conv 5.960e-7 (compile 1.45 s)
probe full 256/256 y 2.503e-6, h 2.198e-7, conv 7.153e-7
probe K-1 256/2 y 2.027e-6, h 1.118e-8, conv 6.557e-7
validate_arch.sh --batch 4 --requests 8 --maxcap 24 exit 0: structural, HF token-exact, serve reference-exact; B=4 90.62 tok/s (84.17 sequential)
CLI 40 tokens vs HF fp32 oracle 40/40 token-exact, 158.63 tok/s
server, 4 concurrent /v1/completions, temperature 0, 24 tokens 4/4 equal their CLI streams in text and token counts, both non-streaming and SSE (8/8); requests overlapped

The probe y errors are identical to the #3342 table; h moves in the last bits (padded 1.58e-7 to 3.95e-7, full 1.12e-7 to 2.20e-7), all far inside 5e-5. Server used the #3342 prompts with --ctx-size 2048 --max-batch-size 4, prompt cache and APC disabled by the recurrent guard.

Prefill at capacity 4096 (real mixer, real_len 3584, 3 alternating runs, fresh cache each)

arm compile s run s (first call) run s (warm) max-abs y
before 66bf600a 1.59 / 1.70 / 1.64 0.072 / 0.078 / 0.071 0.075 / 0.073 / 0.071 4.172e-6
after f3c771e3 1.75 / 2.14 / 1.62 0.088 / 0.088 / 0.090 0.089 / 0.095 / 0.089 4.172e-6

Single-layer prefill is about 22% slower (warm median 0.073 to 0.089 s); compile time is unchanged within noise. Correctness is identical.

Hybrids (sharing the scan)

model gate result, equal to the recorded docs
Nemotron-H 4B xla_oracle_check vs committed oracle 40/40 token-exact
xla_batch_bench B=4 N=8 maxcap 24 reference-exact, 170 tokens (4.93 tok/s batched, 5.87 sequential)
CLI 40 tokens same 40 ids as the oracle and the recorded CLI
server, 4 concurrent, capacity 256 8/8 text and count exact (non-streaming and SSE); first 24 ids of each CLI reference equal the recorded ones
xla_ssm_single_seq, xla_ssm_state_carry, xla_hybrid_nemotron_h 6, 5, 5 passed
Falcon-H1 Tiny 90M xla_falcon_h1 suite (--ignored) 2/2: synthetic parity for all three norm modes, 40 original-checkpoint oracle tokens on cuda
falcon_h1_cli_server_check.py --device cuda 40/40 oracle, 8/8 displayed text and counts; every response and CLI id list equals the recorded integrated-cuda-displayed result, Germany keeps its " \n"
xla_batch_bench B=4 N=8 reference-exact (97.64 tok/s batched, 64.52 sequential)

Not run: the Nemotron-H CPU prompt-cache unit test (no device involved). The Nemotron-H server check used the Falcon harness's prompts (the ones the Nemotron-H record used) with 40-token responses instead of 24.

Both backends pass every Mamba2, Nemotron-H and Falcon-H1 gate at the PR head with results equal to the earlier records. Adds the capacity-4096 prefill cost of the shifted-add prefix sum: about 22% on a single CUDA layer, 3.2% on a whole-model ROCm prefill, decode unchanged.
The hold comment asked for the capacity-4096 prefill timing before (main) and after this head; the recorded CUDA pair used the merge-base 66bf600. Re-measured on GB10 with main d43915f as the before arm, three alternating runs each from an empty cache: warm median 0.076 to 0.096 s (+26%), compile 1.51 to 1.67 s against 1.75 to 1.88 s, identical probe error. The Mamba2 scan and probe are unchanged between the two bases, so the two pairs agree.

Refs #3343
@inureyes

Copy link
Copy Markdown
Member Author

CUDA: PASS

The CUDA items from the hold comment pass on GB10 at f3c771e3; full tables are in the earlier CUDA comment.

item result
xla_ssm_probe, four real-dimension cases all pass within 5e-5; worst y 2.623e-6, identical to #3342
validate_arch.sh --model models/hf/mamba2-130m --device cuda --batch 4 --requests 8 --maxcap 24 exit 0: structural, HF token-exact, serve reference-exact
prefill at capacity 4096, before main d43915fa, after f3c771e3 same error (4.172e-6); warm run 0.076 to 0.096 s (+26%), compile 1.51 to 1.67 s against 1.75 to 1.88 s

The main-based timing pair agrees with the merge-base pair already recorded (+22%); the Mamba2 scan and probe are unchanged between the two bases. The 7x memory-traffic estimate on the [nc, H, q, q] passes shows up as about a quarter more single-layer prefill time on CUDA.

d06e1dd5 adds the main-based rows to the prefill table in FINDINGS_ssm.md, on top of 7a736a82, which already records the CUDA and ROCm results. Not merged.

@inureyes
inureyes merged commit db3a231 into main Nov 26, 2026
33 checks passed
@inureyes
inureyes deleted the fix/issue-3343-mamba2-metal-ssd branch November 26, 2026 17:22
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) platform:macos macOS (Apple Silicon) specific priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(xla): validate the Mamba2 SSM path on IREE-Metal (macOS)

1 participant