Skip to content

feat: add XLA Mamba1 and Falcon-Mamba support - #3413

Draft
inureyes wants to merge 5 commits into
mainfrom
feature/issue-3348-mamba1-selective-scan
Draft

inureyes wants to merge 5 commits into
mainfrom
feature/issue-3348-mamba1-selective-scan

Conversation

@inureyes

@inureyes inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add an f32 diagonal selective scan and Mamba1 mixer for prefill and batched decode
  • keep prefill chunk-bounded and compile-efficient with a log-depth affine prefix scan inside each 128-row chunk
  • parse and validate Mamba and Falcon-Mamba configs, legacy bias aliases, checkpoint tensors, weight names, and threaded [L,D,N] state
  • extend the independent Transformers oracle and whole-model IREE harness, including synthetic Falcon-Mamba B/C/dt RMS normalization
  • register a compact whole-model Mamba decode golden and record reproducible CPU measurements

Review fixes

  • honor the original bias / conv_bias aliases while giving canonical use_bias / use_conv_bias keys precedence
  • reject unsupported rms_norm = false configs and require every active block or mixer epsilon to be finite and positive
  • replace the row-by-row prefill unroll with a chunk-local, log-depth associative affine scan; mixer projections are built inside the chunk loop, so no full [T,D,N] producer exists
  • preserve Nemotron-H compact KV indexing, grouped normalization, hybrid state carry, and registered Mamba2/Nemotron-H golden bytes after rebasing onto feat(xla): Nemotron-H hybrid with dual KV + recurrent state carry #3344

Validation

  • cargo fmt --all -- --check
  • cargo clippy -p mlxcel-xla --lib -- -D warnings
  • cargo test -p mlxcel-xla --lib -- --test-threads=4 (551 passed, 21 ignored)
  • cargo test -p mlxcel-xla --lib validation::tests::registered_fixtures_are_byte_exact -- --exact --test-threads=1 (registered Nemotron-H and Mamba2 fixtures unchanged)
  • cargo test -p mlxcel-xla --profile test-fast --lib mamba1 -- --test-threads=1 (10 passed)
  • Mamba1 IREE local-task: padded prefill, full prefill, B=3 decode, and a real-dimension capacity-4096 prefill pass the Transformers fp32 oracle at 5e-5; the 4096 output/state errors are 3.427e-7 / 1.246e-8
  • capacity 4096, D=1536, N=16: no [4096,D,N] tensor; 3,116-line / 320-KiB StableHLO, direct llvm-cpu compile 10.64 s at 228.2 MiB peak RSS, IREE run 0.862 s
  • IREE-CUDA capacity-4096 probe at pre-rebase SHA dcbb6be9fcac6ec3189c2659c9bd0bc44780eeea: compile 6.27 s, run 0.315 s, process peak RSS 256500 KiB, output/state/conv max-abs 3.651e-7 / 1.141e-8 / 1.371e-6; this is exact-SHA evidence, not a claim that CUDA was rerun after the rebase (the Mamba1 scan source blob is unchanged)
  • rebased HEAD 079b5f087af62c699bdef6dfd84ace6d9a79c6ab, official state-spaces/mamba-130m-hf@1e76775f628fbf1350fbe4dbb3d971ba64af25a1: whole, split-prefill, and decode paths pass the independent Transformers fp32 whole-model check on local-task; worst max-abs 1.488e-4, same argmax
  • rebased HEAD, seeded synthetic FalconMambaForCausalLM: whole, split-prefill, and decode paths pass on local-task; worst max-abs 3.725e-7, same argmax

Pending hardware gates

  • hip probe coverage for decode, padded prefill, full prefill, and capacity 4096
  • real state-spaces/mamba-130m-hf full-checkpoint CLI/server validation, including HIP, cancellation, and slot-recycling gates
  • seeded synthetic Falcon-Mamba HIP token/reference and serving gates; exact-current-head CUDA hardware rerun remains separate from the pre-rebase probe evidence above

Refs #3348

@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 Nov 24, 2026
@inureyes

Copy link
Copy Markdown
Member Author

ROCm interim at exact HEAD b4bcdf36604902f2bbce88a85b451df2a3a61763: Mamba1 and Falcon-Mamba decode, padded prefill and full prefill probes pass on both local-task and HIP (12 cases). Real Mamba-130M and seeded synthetic Falcon-Mamba both match the independent HF fp32 oracle and CLI continuation IDs for 40/40 tokens. B4/N8 reference-exact batches and Mamba cancellation/recycling pass.

FAILED: scripts/rocm_gpu_guard.sh --hold -- cargo clippy -p mlxcel-xla --lib --tests -- -D warnings with Rust 1.97.1 reports clippy::borrow_deref_ref at src/lib/mlxcel-xla/src/emitter/model.rs:5009, the &*c argument to mamba2_mixer_prefill_form. Please fix this in the implementation branch. No common code changed on the ROCm side.

Server concurrency, Mamba2 regression, and capacity-4096 compile/memory checks are still pending; this is not full acceptance. Evidence and exact commands: /home/devops/Development/mlxcel/acceptance/pr3413/b4bcdf36604902f2bbce88a85b451df2a3a61763/. Runtime binaries use optimized test-fast; no performance claim.

Add chunk-bounded f32 Mamba1 and Falcon-Mamba recurrence, checkpoint layouts, threaded state handling, HF probes, and a whole-model golden.

Refs #3348
@inureyes

Copy link
Copy Markdown
Member Author

ROCm results at exact HEAD dcbb6be9fcac6ec3189c2659c9bd0bc44780eeea, retested after the bounded parallel scan change. Runtime correctness gates PASS; overall acceptance remains FAILED because clippy still reports borrow_deref_ref at emitter/model.rs:5009 (&*c).

  • XLA library: 547 passed, 21 ignored; registered goldens and formatting pass.
  • Independent HF fp32 mixer oracle: Mamba1 and Falcon-Mamba B3 decode, padded prefill, full prefill pass on both local-task and HIP (12 cases, tolerance 5e-5).
  • Real state-spaces/mamba-130m-hf and seeded synthetic FalconMambaForCausalLM: both whole-model oracle checks and parsed CLI IDs match HF 40/40. B4/N8 batches are reference-exact. Mamba cancellation and slot recycling pass.
  • Four concurrent real Mamba SSE completions exactly match separately generated CLI text references for four distinct prompts. This establishes rendered-text parity; HTTP token IDs were not collected.
  • Mamba2 regression: six single-sequence and five state-carry tests pass; real Mamba2-130M HF oracle 40/40 and B4/N8 reference-exact batch pass.
  • Capacity 4096, chunk 128, real Mamba130M mixer dimensions: no full [4096,1536,16] recurrence tensor; bounded [128,1536,16] tensors present. CPU compilation: 3.2s / 191.2MiB peak RSS. ROCm gfx1151 compilation: 2.8s / 232.2MiB peak RSS. Both report 521 dispatches and 240.1MiB transient allocation. These are standalone mixer compiler measurements, not whole-model runtime peak GPU memory or throughput.

Evidence, exact commands, scripts, model oracle IDs and summary.json: /home/devops/Development/mlxcel/acceptance/pr3413/dcbb6be9fcac6ec3189c2659c9bd0bc44780eeea/. All builds/GPU execution were serialized under scripts/rocm_gpu_guard.sh --hold --; independent oracle/model runs did not overlap. Optimized test-fast runtime binaries, Rust 1.97.1, IREE 3.12.0rc20260721 at dc9601f88654749456c7cee4ae87e13de2654e1e. No production source modifications, issue closure or PR merge performed.

Please resolve the remaining clippy error on the implementation side. Reproducer: scripts/rocm_gpu_guard.sh --hold -- cargo clippy -p mlxcel-xla --lib --tests -- -D warnings. Detailed failure remains in clippy.log.

@inureyes
inureyes force-pushed the feature/issue-3348-mamba1-selective-scan branch from dcbb6be to 079b5f0 Compare November 24, 2026 17:35
Pass the existing shared config reference directly to the prefill emitter so the test target passes clippy with warnings denied. Library tests (551 passed), fmt and focused clippy pass on ROCm.

Refs #3413
@inureyes

Copy link
Copy Markdown
Member Author

Fixed the remaining clippy error in 3a1688f7daaf9bae8bea09997b804e6509357c25, based on refreshed PR HEAD 079b5f087af62c699bdef6dfd84ace6d9a79c6ab. The test probe now passes its existing shared config reference directly.

Validated at the fix SHA on gfx1151: library 551 passed / 21 ignored, registered goldens, fmt and clippy pass. CPU/HIP mixer probes (12 cases), real Mamba and synthetic FalconMamba HF/CLI 40/40, B4/N8 batches, cancellation/recycling, four concurrent server text references, capacity-4096 compilation, five hybrid HIP tests, and Mamba2 synthetic/real-model regressions pass. Real Nemotron-H-4B oracle 40/40 and B4/N8 regression also pass after the refreshed shared emitter/shim changes.

All builds/GPU operations were serialized under the ROCm guard. Evidence: /home/devops/Development/mlxcel/acceptance/pr3413/3a1688f7daaf9bae8bea09997b804e6509357c25/. Optimized test-fast binaries; no throughput claim. HTTP server validation compares rendered text, not exposed token IDs. No merge or issue closure performed.

This branch has not been deployed

No deployments
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:review Under review type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant