GPU Hierarchy Meets Structured Matrices: Fast Algorithms for State-Space Models

Berlin Chen, Caitlin Wang, Aakash Lahoti, Kevin Li, Jay Shah, Jack Carlisle, Timmy Liu, Mengyu Guo, J Zico Kolter, Albert Gu, Tri DaoNeurIPS 2026

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:

  1. 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).
  2. 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.
Comparison of threadblocks launched and HBM state I/O between standard chunk-parallel scheduling and Split Sequence for a 32k token sequence.
  • 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 memcpy bandwidth (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

Abstract

Linear-time sequence models such as State Space Models (SSMs) offer an efficient alternative to self-attention and have demonstrated strong language modeling performance at scale. In practice, however, their asymptotic advantage is often lost at common training and prefill lengths---optimized FlashAttention kernels remain faster than existing SSM implementations up to 8k tokens. In this work, we substantially narrow this performance gap with novel algorithmic improvements: First, we introduce a split-sequence algorithm that decouples the compute tile from the sequence-parallel split length, preserving efficient matrix multiplication tiles while substantially reducing boundary-state traffic and latency. Second, we resolve a longstanding *speed--stability tradeoff* in computing the 1-semiseparable (SS) decay mask, the main non-matmul bottleneck shared by all chunk-wise linear-time kernels (Mamba-2, Mamba-3, GDN, KDA). Existing kernels use the fast *diff segsum* (prefix subtraction), which suffers monotonicity violations and catastrophic cancellation---failures observed in real pretraining (e.g., Nemotron-H); the stable alternative (*direct segsum*) materializes the dense mask and is $\sim30\\%$ slower. Our *hierarchy-aware segsum* decomposes the SS mask into 1-SS diagonal blocks and rank-one off-diagonal blocks, computed via warp-level scans and cross-warp aggregation directly in registers, achieving the stability of direct segsum at the speed of diff segsum. We implement these algorithms using CuTe-DSL with warp specialization, asynchronous TMA, WGMMA, and layout-aware accumulator fragments. Across a large range of sequence length, our H100 kernels reach 91\% of measured memcpy bandwidth, improve prefill time by $4.1\times$ over the official Triton Mamba-2 kernel, and **outperform the highly-optimized FlashAttention-4 starting at 1-2k sequence length**---to our knowledge, the first time a linear-time sequence layer is faster than state-of-the-art attention at the 2-4k sequence lengths used in common pretraining and prefill workloads, where prior linear-time kernels only reached parity at $\geq 8$k. Our hierarchy-aware segsum is $1.35$-$1.40\times$ faster than a naive stable direct-segsum implementation.
BibTeX
@inproceedings{chen2026gpu,
  author = {Berlin Chen and Caitlin Wang and Aakash Lahoti and Kevin Li and Jay Shah and Jack Carlisle and Timmy Liu and Mengyu Guo and J Zico Kolter and Albert Gu and Tri Dao},
  title = {{GPU Hierarchy Meets Structured Matrices: Fast Algorithms for State-Space Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=m6QBIQ5qCZ},
}

Loading related content...

Figure