GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
COLM 2024

Mamba: Linear-Time Sequence Modeling with Selective State Spaces

Make a state space model's update depend on the current token, so it can choose what to remember, and run it as a fused GPU scan. Transformer-level quality to 2.8B parameters with no KV cache.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2023
AUTHORS
Gu, Dao
FROM
Carnegie Mellon University, Princeton University
PUBLISHED
Dec 2023 · COLM 2024
CITED BY
9,660Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 24% of this breakdown.

01

The paper in one minute

Transformers dominate sequence modeling, but attention compares every token with every other one. Training cost grows with the square of the sequence length, and generation needs a KV cache that grows with every token. Many linear-time alternatives exist, and structured state space models (SSMs) such as S4 were the strongest of them: a hidden state is updated at each step as h = Ā·h + B̄·x, and output as y = C·h. They excelled at long continuous signals like audio but lagged on text.

Albert Gu at CMU and Tri Dao at Princeton pinned the weakness on one property. Earlier SSMs are linear time-invariant: the same Δ, A, B and C apply at every position. That lets them run as one long convolution, which is fast, but it also means they cannot decide, based on content, to keep one token and ignore the next. Two synthetic tasks make the point: selective copying (remember the colored tokens scattered among noise) and induction heads (after "Harry Potter ... Harry", predict "Potter").

Mamba's fix, the selection mechanism, makes Δ, B and C functions of the current input. A large Δ lets the input in and largely resets the state; a tiny Δ lets the state pass through unchanged. With N=1 this reduces exactly to a gated RNN. The cost is losing the convolution form, so the authors wrote a hardware-aware scan: load the parameters into fast on-chip SRAM, discretize and run the recurrence there with a parallel scan, write only outputs back to GPU memory, and recompute intermediate states in the backward pass. The Mamba block merges the SSM layer with a gated MLP-like structure and is stacked with no attention at all.

Mamba solved both synthetic tasks, extrapolating induction heads from 256 to a million tokens. On language, it matched a modern Transformer recipe in scaling studies up to 1.3B parameters and beat same-size open models at 2.8B. It also set best results on DNA and audio modeling.

THE IDEA, VISUALLY
ONE SELECTIVE SSM STEP, PER CHANNEL input xₜ current token Δₜ, Bₜ, Cₜ = functions of xₜ earlier SSMs: fixed for every position hₜ = exp(Δₜ·A)·hₜ₋₁ + B̄ₜ·xₜ yₜ = Cₜ·hₜ large Δ: let xₜ in, forget the past. tiny Δ: skip xₜ. With N=1, A=−1, B=1 this is exactly a gated RNN: h = (1 − g)·h + g·x with g = sigmoid(·) (Theorem 1). THE MAMBA BLOCK (STACKED, NO ATTENTION) Linear ×2 expand width Conv + SiLU Selective SSM Linear + SiLU gate branch multiply, Linear Runs as a parallel scan, not a convolution: the expanded state lives only in on-chip SRAM, and is recomputed in the backward pass instead of stored. Inference keeps a fixed-size state: no KV cache. ZERO-SHOT AVERAGE, SAME DATA AND TOKENS (TABLE 3) ~150M Pythia 40.6 Mamba 44.7 ~400M Pythia 48.2 Mamba 50.0 1.4B Pythia 55.2 Mamba 59.7 2.8B Pythia 59.1 Mamba 63.3 Pythia-6.9B: 61.7; GPT-J-6B: 63.0. Axis starts at 30. WHICH PARAMETERS ARE SELECTIVE (TABLE 7) none ppl 10.93 B only ppl 10.15 C only ppl 9.98 Δ only ppl 9.81 Δ, B and C ppl 8.71 350M models; perplexity, lower is better; axis starts at 8 OTHER HEADLINES Induction heads: trained at 256 tokens, perfect up to 1M; attention was tested only up to 16,384 (memory). Inference throughput 4-5× a same-size Transformer, from larger batches without a KV cache. Largest model: 2.8B.
Mamba computes the state update's step size and input and output maps from each token, letting the model admit or skip inputs, and runs the recurrence as a fused scan. It beat same-size Pythia models trained on the same data and kept a fixed-size state at inference; tests stopped at 2.8B parameters.
Research notes: the problem, approach and results
63.3 vs 59.1

six-task zero-shot average, Mamba-2.8B against Pythia-2.8B, both trained on 300B Pile tokens

10.93 → 8.71

perplexity of a 350M model with no selective parameters against selective Δ, B and C (Table 7)

4-5×

inference throughput over a Transformer of similar size, from larger batches without a KV cache

THE PROBLEM

Transformers' attention costs grow with the square of sequence length in training and need a KV cache that grows linearly at inference. Linear-time alternatives (linear attention, long convolutions, earlier state space models) had not matched attention on language, because their fixed dynamics cannot decide what to keep based on content.

THE IDEA

Make the state space model's step size Δ and its B and C maps functions of the current input, so it can let a token in and reset, or ignore it. That breaks the fast convolution form, so compute the recurrence with a parallel scan that keeps the expanded state in GPU SRAM and recomputes it in the backward pass. Stack one simple block, with no attention or MLP.

THE RESULT

On the Pile, Mamba matched a strong Transformer recipe in scaling up to 1.3B parameters. Mamba-2.8B averaged 63.3 on six zero-shot tasks against 59.1 for Pythia-2.8B and 61.7 for Pythia-6.9B, with 4 to 5 times the inference throughput of a same-size Transformer. It also led on DNA and audio benchmarks.

02

Why it matters to an FDE

You will meet Mamba-style layers inside production models rather than as standalone Mamba checkpoints: several current open models mix linear-time layers with a few attention layers. Knowing what they buy and give up helps when sizing serving or choosing a model.

No KV cache means bigger batches. A Transformer's memory per sequence grows with context length; an SSM's state is fixed. For long contexts and high concurrency, that is the difference between a handful of sequences per GPU and thousands, and it is where the paper's throughput gain comes from.

Long inputs get cheaper. Linear-time training and constant-time generation steps matter for long logs, genomic data, audio and long documents.

Exact recall is the weak spot. A fixed-size state must compress the past. Later work found Transformers better than state space models at copying long strings from context. If the task is "find the exact clause in this 200-page contract", check recall before switching.

Tooling maturity varies. Serving engines, quantization and fine-tuning recipes are most mature for Transformers; the authors list these "downstream affordances" as an open question.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦1 results table
  • ?5 interview questions with answers
  1. 03Key takeaways

    The selection mechanism, the scan, the block, the results and misreadings to avoid

    Free account
  2. 04How it works

    Discretization, the selection mechanism, the hardware-aware scan and the block design

    Premium
  3. 05The numbers that matter

    Synthetic tasks, language scaling and zero-shot results, DNA, audio, speed and ablations

    Premium
  4. 06Try it yourself

    Verify Theorem 1, watch selection filter noise, and compare inference memory with a KV cache

    Premium
  5. 07Where it breaks

    Scale limits, recall from a fixed state, benchmark scope and inconsistencies

    Premium
  6. 08Using it on a deployment

    When state space or hybrid models fit a customer's workload

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →