TL;DR
State Space Models (SSMs) like Mamba promise linear-time scaling, yet in practice, highly optimized Transformers (via FlashAttention) still outrun them at common training lengths up to 8,000 tokens. By redesigning SSM algorithms from the ground up to respect how modern GPUs move data—from global memory down to individual thread registers—the authors make Mamba-2 over $4\times$ faster and completely eliminate a nasty numerical bug that crashes real-world training runs. For the first time, a linear-time model beats state-of-the-art FlashAttention-4 starting at just 1,000 to 2,000 tokens.
What Problem Does This Paper Address?
On paper, linear-time sequence models ($O(L)$) should effortlessly beat quadratic self-attention ($O(L^2)$). Yet if you sit down to pretrain a language model at typical sequence lengths of 2k to 4k tokens, FlashAttention-4 is noticeably faster than official Mamba-2 implementations, which only catch up around 8k tokens. Why? Attention has enjoyed years of obsessive hardware-software co-design around the GPU memory hierarchy, whereas SSM kernels are still early on that curve.
Current chunk-wise SSM kernels suffer from two major bottlenecks:
- Excessive Memory Traffic: To use fast GPU Tensor Cores, SSMs chop sequences into small chunks (e.g., 64 tokens) and assign one GPU processor (threadblock) per chunk. For long sequences, this spawns thousands of tiny jobs that must constantly read and write recurrent states back and forth to slow High-Bandwidth Memory (HBM).
- The Speed–Stability Tradeoff: Within each chunk, SSMs apply a causal decay mask to control how past information fades. Computing this mask quickly via prefix subtraction (diff segsum) causes floating-point errors that can blow up into
NaNs during real training runs. Computing it safely (direct segsum) requires writing a dense mask to shared memory, slowing the kernel down by roughly 30%.
Methods
The authors tackle both bottlenecks by mapping the mathematical structure of SSMs directly onto the physical hierarchy of the GPU:
- Split Sequence (Device-Level): Standard kernels tie the Tensor Core matrix size ($C=64$) to the parallel work size assigned to each Streaming Multiprocessor (SM). Split Sequence decouples them. It assigns a much larger sequence split (e.g., $T=8192$) to each SM to generate just enough parallel work to keep the GPU busy, while still processing tokens internally in tiny $C=64$ chunks. Intermediate recurrent states stay fast and local in registers rather than taking round trips to HBM.
- Hierarchy-Aware Segsum (Thread-Level): Instead of building a dense $64 \times 64$ decay mask in shared memory or using unstable subtraction, the authors exploit the mask's "1-semiseparable" structure—meaning its off-diagonal blocks are mathematically rank-one. Any off-diagonal decay value can be summed from three tiny, reusable pieces: a within-group suffix, an intervening group total, and a within-group prefix. Threads compute and apply their exact mask entries directly in registers, matching the exact layout of the Tensor Core accumulators.
Datasets
Not discussed in the paper. Because this work focuses on exact algorithmic reformulations and low-level GPU kernel engineering rather than changing model architectures, the authors evaluate their methods using synthetic tensor workloads (varying batch sizes, sequence lengths, and head dimensions), numerical stability simulations, and real decay values captured from a production Nemotron-H pretraining run.
Key Insights and Ideas
- Floating-Point Addition Isn't Associative—And Parallel Scans Care: In exact math, summing negative decay rates yields a strictly decreasing sequence. However, parallel GPU prefix scans (like Hillis–Steele) reorder additions. In floating-point math, subtracting two massive, rounded prefix sums can flip a negative decay into a positive number. Using real weights from NVIDIA's Nemotron-H run, the authors caught prefix subtraction turning a true decay of $-72.3$ into $+128$—causing
exp(128)to overflow FP32! - Clamping Masks the Symptom, Not the Disease: Standard Mamba patches overflows by clamping positive exponents to zero. The authors show this fixes sign flips, but leaves massive negative-side "catastrophic cancellation" rounding errors untouched ($20\times$ higher error than direct summation). Hierarchy-aware segsum gets exact, non-positive sums by construction, at full speed.
- Structured Matrices Belong in Registers: A $64 \times 64$ mask has 4,096 entries. By factoring off-diagonal blocks into rank-one components, the shared memory footprint drops to just 72 numbers, completely bypassing shared-memory bottlenecks.
Key Results
Implemented in CuTe-DSL for Hopper (H100) and Blackwell (GB200) GPUs, the kernels achieve near-roofline performance:
- Bandwidth & Speedup: Reaches 91% of measured HBM
memcpybandwidth (up to 2.73 TB/s) on H100, running $4.1\times$ faster than the official Mamba-2 Triton kernel and $>2.5\times$ faster than Mamba-3 Triton. End-to-end Mamba-2 mixer blocks see $1.50\text{–}2.80\times$ prefill speedups. - Beating FlashAttention-4: Crosses over causal FlashAttention-4 latency between 1k and 2k tokens on the forward pass (and 2k–4k for forward + backward), running $4\times$ faster at 8k tokens on H100.
- Speed + Stability: Hierarchy-aware segsum runs $1.35\text{–}1.40\times$ faster than naive stable direct segsum, matching the speed of unstable diff segsum with zero overflow risk.
- Blackwell Portability: On NVIDIA GB200, achieves $4.60\text{–}5.09\times$ speedups over the Mamba-2 baseline and $1.18\text{–}1.54\times$ over NVIDIA's cuDNN FROST implementation.
Limitations and Future Work
- Training and Prefill Only: These kernels optimize parallel sequence processing (training and prompt prefill), not token-by-token autoregressive decoding.
- Manual Mathematical Tailoring: While aligning structured matrices with the GPU hierarchy is a general principle, it isn't plug-and-play—every new linear-time variant (like GDN or KDA) has slightly different operators that require re-deriving its specific matrix decomposition by hand.
Summary updated