Repository navigation
perf(models): chunk the Mamba2 SSD and block the Mamba1 graph scan - #3087
Merged
Merged
Conversation
The Falcon-H1, GraniteMoeHybrid and PLaMo 2 SSD scans built the [B, H, L, L] float32 surrogate attention over the whole prefill piece, so a 28K single-pass prefill of granite-4.0-h-tiny or falcon-h1-tiny ran out of GPU memory on M5 Max. The three families and NemotronH now share one float32-hardened chunked scan (src/models/ssd_scan.rs) with a chunk length independent of the piece: 256 tokens, as in mlx-lm's ssm_attn, for the three, and NemotronH's configured chunk_size with its per-chunk eval unchanged. A single pass longer than 2048 tokens schedules each window's output and state with schedule_prefill_state; the callers keep scheduling the final state and storing conv tails through materialized_state_tail as after #3063. Jamba's Mamba1 graph-scan fallback built (delta * x) B and exp(delta A) as [B, L, D, N] for the whole piece before its sequential loop. It now builds them per 256-step block in graph_selective_scan, which is bit-identical for any block length. Mamba's fallback already projects one timestep at a time and is unchanged. Validated on M5 Max: single pass completes for all three families (granite 17.1 GB), 2048-chunk greedy output is byte-identical to main for granite and PLaMo 2, and the teacher-forced logit trace shows 0 to 0.025% disagreement at decided positions. New unit tests cover chunked against unchunked scans and a forced Jamba fallback. Refs #3073
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[B, H, L, L]float32 surrogate attention over the whole prefill piece. They now share one float32-hardened chunked scan with NemotronH (src/models/ssd_scan.rs). The chunk is 256 tokens, as in mlx-lm'sssm_attn, independent of the piece. NemotronH keeps its configuredchunk_sizeand per-chunk eval. A single pass longer than 2048 tokens schedules each window's output and state withschedule_prefill_state. The callers keep the fix(models): release long prefill inputs held by lazy recurrent state #3063 behavior: the final state is scheduled and conv tails go throughmaterialized_state_tail.(delta * x) Bandexp(delta A)as[B, L, D, N]before its sequential loop.graph_selective_scannow builds them per 256-step block, and the result is bit-identical for any block length. The Mamba fallback (mamba.rs) already projects one timestep at a time, so its state is[B, D, N]per step, and it is unchanged.Measurements (M5 Max, 28K prompt, two order-reversed cooled rounds)
The chunk changes the arithmetic order. Teacher-forced
logit_traceat forward width 2112 (16,896 positions each), main as the reference, decided gap 2:Falcon-H1 tiny's greedy divergence is in output that is already degenerate at 28K on both arms. Full tables and CSVs are in
docs/benchmark_results/ssm-prefill-scan-chunking-m5max-2026-11-15.md.Test plan
ssd_scan::tests). Jamba graph-scan blocks bit-identical, and a forced fallback prefill over three blocks matches the fused kernel (jamba::tests).tests/mamba2_hybrid_finite.rsandtests/mamba2_hybrid_decode_finite.rswith--include-ignoredagainst the real checkpoints (MLXCEL_REQUIRE_MODELS=1).check_env_var_docs.py,check_benchmark_raw_logs.py,make verify-kernel-dtype-keys.Closes #3073