Skip to content

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

Merged
inureyes merged 7 commits into
mainfrom
feature/issue-3348-mamba1-selective-scan
Nov 25, 2026
Merged

inureyes merged 7 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 add English and Korean technical reports

Correctness and integration 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
  • construct log_a and bx inside the mixer chunk loop, so capacity 4096 never creates a full [4096,D,N] producer
  • preserve the merged Nemotron-H compact KV indexing, grouped normalization, hybrid state carry, MoE paths, and registered Mamba2/Nemotron-H golden bytes
  • document MLXCEL_FREEZE_MAMBA1 and remove the duplicate Nemotron-H allowlist entry that caused the hosted environment-variable documentation jobs to fail

Integrated validation

The executable source for the final integrated checks is abd1520fd669624cb668bd558b98e332d0955093, based on merged PR #3411. The final branch adds only the bilingual reports after that source commit.

  • cargo fmt --all -- --check
  • cargo clippy -p mlxcel-xla --lib -- -D warnings
  • cargo test -p mlxcel-xla --lib -- --test-threads=4 (555 passed, 21 ignored)
  • cargo test -p mlxcel-xla --lib validation::tests::registered_fixtures_are_byte_exact -- --exact --test-threads=1 (Mamba1, Mamba2, and Nemotron-H registered goldens byte-exact)
  • python3 scripts/ci/check_env_var_docs.py (396 discovered, 265 documented, 131 allowlisted)
  • python3 -m unittest discover -s tests -p 'test_check_env_var_docs.py' -v (15 passed)
  • official state-spaces/mamba-130m-hf@1e76775f628fbf1350fbe4dbb3d971ba64af25a1 on IREE local-task: whole prefill, split prefill, and decode match the independent Transformers 5.12.1 CPU fp32 reference; worst max-abs 1.488e-4, same argmax
  • seeded synthetic FalconMambaForCausalLM on IREE local-task: whole prefill, split prefill, and decode match the independent reference; worst max-abs 3.725e-7, same argmax
  • capacity 4096, D=1536, N=16: no [4096,D,N] tensor; 3,116-line / 320-KiB StableHLO; direct CPU compile 10.64 s at 228.2 MiB peak RSS; run 0.862 s

Exact integrated CUDA acceptance

On NVIDIA GB10, source abd1520fd669624cb668bd558b98e332d0955093 passed the capacity-4096 CUDA probe under gpu-lock:

  • compile 5.03 s, run 0.319 s
  • process peak RSS 203200 KiB
  • independent oracle max-abs: output 3.651e-7, recurrent state 1.141e-8, convolution state 1.371e-6
  • timing log: /tmp/epic564-plan/3348-cuda-cap4096-integrated-abd1520f-time.log
  • result bundle: /tmp/issue3348-cap4096-integrated-abd1520f

This establishes correctness and compile footprint, not a throughput claim.

ROCm acceptance and source boundary

External ROCm gfx1151 acceptance passed at exact source 3a1688f7daaf9bae8bea09997b804e6509357c25:

  • library tests, formatting, clippy, and registered goldens
  • 12 local-task and HIP mixer-probe cases, including capacity 4096
  • real Mamba and synthetic Falcon reference and CLI parity (40/40 tokens)
  • B4/N8 batching, cancellation, slot recycling, and four concurrent server requests
  • five hybrid tests, Mamba2 synthetic and real regressions, and real Nemotron-H 4B integration checks

All ROCm device/build work used the ROCm guard. Server checks compare rendered text because the HTTP API does not expose token IDs. Optimized test-fast binaries make no performance claim. Full commands and provenance are in the ROCm acceptance record.

The later rebase onto PR #3411 did not change the blobs for the Mamba1 scan, parser, recurrent emitter, or Python oracle. It added disjoint Nemotron-H MoE integration and the CI allowlist correction. Full library, golden, lint, environment-variable, and CUDA gates were rerun on the integrated source; ROCm was not rerun after this source-neutral integration, so the exact-SHA evidence boundary is retained here.

Reports

  • TECHNICAL_REPORTS/3413-mamba1-falcon-mamba-selective-scan-20261125.en.md
  • TECHNICAL_REPORTS/3413-mamba1-falcon-mamba-selective-scan-20261125.ko.md

Closes #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.

@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
@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.

inureyes added a commit that referenced this pull request Nov 24, 2026
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 and others added 7 commits November 25, 2026 16:04
Add chunk-bounded f32 Mamba1 and Falcon-Mamba recurrence, checkpoint layouts, threaded state handling, HF probes, and a whole-model golden.

Refs #3348
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
inureyes force-pushed the feature/issue-3348-mamba1-selective-scan branch from 3a1688f to 946054f Compare November 25, 2026 07:19
@inureyes
inureyes marked this pull request as ready for review November 25, 2026 07:20
@inureyes
inureyes merged commit 2e46fc0 into main Nov 25, 2026
23 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-3348-mamba1-selective-scan branch November 25, 2026 07:20
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 25, 2026
inureyes added a commit that referenced this pull request Nov 25, 2026
Add original-HF Falcon-H1 execution with parallel attention/Mamba2 followed by a separately normalized MLP. Preserve HF muP placement, optional SSM normalization, independent head widths/biases, and dual KV/recurrent state across prefill, single decode, and ragged decode. Integration retains #3411 MoE and #3413 Mamba1 behavior.

Fix plain CLI completion display losing trailing whitespace: an explicit flush mode preserves raw text while default chat and structured reasoning/tool/Harmony/Muse cleanup remain unchanged. The portable replay compares actual stdout with concurrent non-streaming HTTP and SSE responses; earlier CUDA HTTP evidence compared raw token decoding, not displayed stdout.

Validation at integrated runtime source `8c7b4412d37b91807f8d688ba2f3febbc7a7e41f` (base `2e46fc09`):

- Full XLA crate: 560 passed / 22 ignored; byte-exact goldens, every-family layouts, fmt, and narrow clippy pass. Environment-docs checker + 15 Python tests pass after classifying two test-only controls.
- All 7 display tests and 146 filter tests pass; all 5 CUDA hybrid tests and all 6 Mamba2 tests pass.
- CPU/CUDA synthetic norm/ragged/recycle gates and real HF40/40 pass; CUDA CLI40/40 passes.
- Strict displayed stdout: 4/4 nonstream + 4/4 SSE text/count matches, including Germany's exact trailing whitespace; overlapping requests and server cleanup verified.

External HIP acceptance at `852129eb` passed numerical, real 40-token CLI, batching/recycling, regression, and release architecture gates. Strict displayed CLI/SSE parity was 3/4 because Germany ended in `"  \n"`; all four raw token decodes matched. That evidence predates this fix and merged shared recurrent plumbing. Request a final-head ROCm replay with explicit `hip`, `gfx1151`, and `f32` under the ROCm guard; no new HIP run is claimed.

Oracle, provenance, logs, portable replay, and instructions are in `spike/openxla/falcon_h1_reference` and `FINDINGS_falcon_h1.md`; bilingual reports document the exact evidence boundaries. HTTP exposes text/counts, not output IDs. Hosted CI is canceled under the local-validation policy.

Refs #3346
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): Mamba1 selective scan; Mamba and Falcon-Mamba end to end

1 participant