Papers · 2023 · Reading: 24 min, plus 2 in closed details.
Paper · COLM 2024 · arXiv 2312.00752

Mamba: Linear-Time Sequence Modeling with Selective State Spaces (Mamba)

Albert Gu, Tri Dao (equal contribution, listed alphabetically)
Carnegie Mellon University (Gu), Princeton University (Dao) · December 2023 (arXiv v1 1 December 2023; v2 31 May 2024, with the same numbers in every table)

In one line: Made SSM parameters (B, C, delta) input-dependent, breaking LTI so the model selectively remembers or forgets per token, and paired it with a fused parallel-scan GPU kernel; in the paper's scaling runs (the Pile, 125M to 1.3B) the first attention-free model to match Transformer++ perplexity, with linear-time training and 5x generation throughput, seeding today's hybrid attention-SSM production models.

99.8% vs 56.4%
Selective Copying, the same Mamba block with a selective (S6) or a time-invariant (S4) layer
the selection mechanism alone; this page's toy, same block both ways: 99.8% against 67.4% · Table 1
63.3 vs 59.1
average zero-shot accuracy, Mamba-2.8B vs Pythia-2.8B (same data, tokenizer, 300B tokens)
ahead on all six tasks; Pythia-6.9B scores 61.7 · Table 3
5× throughput
generation tokens per second against a same-size Transformer (A100, prompt 2048, 128 new tokens)
no KV cache, so far larger batches; baseline is Hugging Face transformers · Figure 8

How far to trust it: Believe the mechanism: letting the input set Delta, B and C is what lets a recurrent model select, the synthetic gaps are huge, and this page's toy reproduces the selective-copying one. Read "Transformer quality" narrowly: models stop at 2.8B, every number is one run, the 5x throughput is against the unoptimised Hugging Face Transformer, and a later same-data 8B study found pure Mamba level on common zero-shot tasks but 18 points behind on 5-shot MMLU, which is why production models became hybrids. The evidence, point by point.

The idea in one sentence: let the state space model's step size Δ and its input and output maps B and C depend on the current token, so a fixed-size recurrent state can choose what to keep and what to skip; that kills the fast convolution, so a fused, hardware-aware scan computes the recurrence in GPU SRAM instead, and the result trains in linear time, generates without a KV cache, and matches Transformers on language up to 3B parameters.

You need: a linear recurrence with a fixed state and how S4 turns it into a convolution; both are taught on Beyond attention, which also owns Mamba-2 and the hybrids. The KV cache it is compared with is sized on Long context.

New terms

  • LTI (linear time-invariant): the same Δ, A, B, C at every step, so the layer is a convolution.
  • Selection, S6: Δ, B, C computed from the token; S4 plus selection, computed with a scan.
  • Δ: the discretisation step; large means "take this token in", near zero means "skip it".
  • Hardware-aware scan: the recurrence fused into one GPU kernel, run in SRAM, states recomputed in the backward pass.
The paper's Figure 1: a recurrent state h, drawn as stacked orange channels, passes from step t minus 1 to step t through a fixed matrix A; the input x_t is projected into B_t, C_t and the step size Delta_t (the selection mechanism, in blue); Delta_t discretises A and B; C_t reads y_t out of the state. A small pyramid marks GPU SRAM above GPU HBM.
Everything blue is new: Bt, Ct and Δt are projected from the token xt, so the update of the wide state h (orange, D channels × N) differs at every step; the state lives only in fast SRAM. Figure 1 of the paper, credit Albert Gu and Tri Dao, CC BY 4.0, arXiv 2312.00752.

Problem

§1 Introduction, §3.1

Transformers pay quadratic compute in sequence length to train and keep a KV cache that grows with every generated token (§1). Subquadratic alternatives (linear attention, gated convolutions such as H3 and Hyena, RWKV, RetNet, structured state space models like S4) scale better but had never matched attention on dense, discrete data like language (§2).

The paper's diagnosis is a framing: sequence modelling is compressing context into a state (§3.1). Attention is effective and slow for the same reason, it does not compress at all; a recurrent model is fast because its state is fixed, and only as good as what it kept. Every efficient SSM before Mamba was linear time-invariant (LTI): the same dynamics at every step, which lets it run as one global convolution and stops it deciding, token by token, what to store.

  1. The input. Twelve tokens, three of them fillers ("um", "uh"). Mamba's state (right, glass) is allocated at its full size before the first token; the Transformer's cache (left) starts empty.
  2. Transformer: keep everything. Each token appends its keys and values, for every layer, to the cache (one slab, 320 KiB) and reads all cached entries back to produce the next output. Memory and per-token work both grow with the sequence; nothing is ever dropped, so recall is exact.
  3. Mamba: fold each token into a fixed state. The same twelve tokens go into one state of constant size, read once per output. In the paper's reading a selective Δ near 0 leaves the state almost unchanged on fillers, so they are skipped (the faint streams, drawn to illustrate the claim). At this length the state is still the larger of the two.
  4. The crossover. The cache keeps growing one slab per token and passes the whole state at 38 tokens.
  5. At 2,048 tokens, 54 times the state. Both drawn again to one scale: at the 2,048-token prompts of the paper's throughput test the cache is 640 MiB per sequence against the state's 11.9 MiB. That is what limits the batch size.
  6. The price. The state is the same size at any length, but whatever it did not keep cannot be recovered: the limit later work measured on copying and recall (How much to believe).

The same contrast in general, at a 2026 hybrid's shapes, is Fig. 1 of Beyond attention; this stage keeps to the paper's own pair, Pythia-2.8B against Mamba-2.8B.

Counters from the released configs (derived in recompute.py): Pythia-2.8B caches 2 × 32 layers × 2,560 numbers per token, 320 KiB in bf16; Mamba-2.8B keeps a 5,120 × 16 state and a 5,120 × 3 convolution buffer in each of 64 blocks, 11.9 MiB at any length. They cross at 38 tokens; at 2,048 the cache is 54 times the state.

Synthetic tasks make the limit concrete (Figure 2). Plain Copying has constant spacing, so a convolution kernel of the right length solves it. Selective Copying scatters the tokens to remember among noise, and Induction Heads asks for the token that followed an earlier occurrence of the current one ("Harry Potter ... Harry → Potter"), a test the paper calls predictive of in-context learning (§4.1.2). Both need content-aware filtering; with varying spacing no static kernel lines inputs up with outputs.

State spaces, before Mamba

§2 State Space Models, Eqs. 1 to 4

A structured SSM (S4) maps each channel of the input through an N-dimensional latent state, defined in continuous time and then discretised with a step size Δ (Eqs. 1 to 3):

h′(t) = Ah(t) + Bx(t),  y(t) = Ch(t)   ⟶   ht = Aht−1 + Bxt,  yt = Cht

That is the S4 family the paper starts from, taught on Beyond attention. What matters here: being LTI is what let it run as one global convolution, and its state is D × N per sequence (A diagonal), which over a batch costs O(BLDN) to materialise, the bottleneck §3.3 attacks.

Discretisation, the convolution form, and the LTI baselines (§2)

The usual rule is the zero-order hold, A = exp(ΔA), B = (ΔA)−1(exp(ΔA) − I) · ΔB (Eq. 4). Because (Δ, A, B, C) are the same at every step, the output is one convolution, y = x ∗ K, K = (CB, CAB, …) (Eq. 3): S4 trains in parallel by FFT and generates recurrently in constant time per step. A is diagonal, so each matrix is N numbers per channel; with D channels the state is D × N per sequence, and materialising it over a batch costs O(BLDN), the bottleneck §3.3 attacks. The convolution is what let LTI SSMs expand the state by N ≈ 10 to 100 over a classic RNN for free (§3.3.1).

The baselines all live in this family and are all LTI (§2): linear attention is a degenerate linear SSM, H3 wraps S4 in two gates, Hyena swaps in an MLP-parameterised convolution, RetNet uses state size 1, RWKV a ratio of two SSMs.

Selection: the one change

§3.2, Algorithms 1 and 2; §3.5.2

Make Δ, B and C functions of the current token (§3.2): Bt = LinearN(xt), Ct = LinearN(xt) and Δt = softplus(Parameter + BroadcastD(Linear1(xt))). The parameters gain a length dimension, so the model becomes time-varying and the convolution is gone; the paper calls the result S6 (S4 plus selection, computed with a scan; Remark 3.1). A stays a plain parameter, because Δ already makes A = exp(ΔA) input-dependent, and the authors expect a selective A to perform about the same (§3.5.2).

TensorAlgorithm 1: S4, time-invariantAlgorithm 2: S6, selective
A(D, N) parameter(D, N) parameter
B, C(D, N) parameters(B, L, N) = LinearN(x)
Δ(D) = τΔ(Parameter)(B, L, D) = τΔ(Parameter + sΔ(x))
A, B(D, N)(B, L, D, N)
computerecurrence or convolutionrecurrence (scan) only

The paper reads each piece mechanically (§3.5.2): large Δ resets the state and focuses on xt, Δ near 0 keeps the state and skips the token; selective B controls what enters the state, selective C what leaves it. Hence variable spacing (fillers such as "um" can be ignored), filtering context (performance should improve with more context, not degrade) and boundary resetting (packed documents need not bleed into each other).

take the Mamba block, keep everything, but freeze Δ, B and C as learned constants (an LTI layer). On Selective Copying, about what share of the copied tokens does it get right?

The stage runs one sequence (48 positions, 6 data tokens among grey noise, then 6 markers) through two trained toy models live, forward pass checked against PyTorch. Drawn from layer 1 at each position: Δt per channel (64 purple bars, one per column of the state), Bt (green, left) and Ct (gold, right) along the state axis, and the state h itself, 64 channels × 16, as cells on a glass plate (blue positive, orange negative). In the time-invariant model B and C differ per channel, so the bars show the outlined channel's.

  1. The input. Six coloured tokens are scattered among noise at random positions; after them come six markers, and at each marker the model must output the next data token in order. Nothing in the spacing says where the tokens are: the model has to notice them by content.
  2. Data token 1: written through Bt, scaled by Δt. The bars change at every position because they are computed from the token. The token enters the state through Bt, and Δt sets how strongly it is written and how fast the state decays. The paper reads Δ as a gate (large on what matters, near zero on noise); this trained toy did not learn that textbook pattern: averaged over channels Δ is about the same on data and noise (0.0187 against 0.0193 in layer 1).
  3. Data token 2: Δ keeps time. Instead Δ varies with context. In layer 2 it drifts with position: the largest channel correlation is 0.68 with position against 0.22 with "this is a data token", a clock the model can use to keep the tokens in order (the Δ strips of both layers are in Run a toy Mamba).
  4. Data token 3: the selection carries the task. Freeze Δ at its average and held-out accuracy falls from 99.93% to 37.6% (layer 1) or 23.2% (layer 2); freezing B in layer 1 gives 39.1%, freezing C in layer 2 29.3%.
  5. Data tokens 4 to 6. Each data token is written into its own directions of the state (the plate), which the markers read back through Ct.
  6. The markers: read out through Ct. At each marker the model reads the state out through Ct and answers (the cubes above the markers, ringed green when right). On this input it gets of 6.
  7. Result. On 1,000 fresh sequences this selective model gets 99.8% of copied tokens and 99.1% of whole sequences right (the paper, at length 4,096: 99.8%). Same block, same training: only Δ, B and C differ.

Beyond attention (§4, Fig. 4) measures the same selection inside a trained tiny GPT, as the decay each token gets; this stage shows the paper's own synthetic task.

Δ is a gate

Theorem 1, §3.5.1, Appendix C

The most important connection, the paper says, is that classical RNN gating is a special case of selection (§3.5.1). Theorem 1: with N = 1, A = −1, B = 1, sΔ = Linear(x) and τΔ = softplus, the selective recurrence is exactly the gated RNN

gt = σ(Linear(xt)),    ht = (1 − gt) ht−1 + gt xt

This is why Δ is projected from the input to one dimension and broadcast: if a token should be ignored, all channels should ignore it.

The two-line proof, and how Δ is initialised and projected

The proof (Appendix C) is two lines of zero-order hold: exp(−softplus(z)) = 1/(1 + ez) = 1 − σ(z), and B = 1 − A. In the experiments Δ's bias is initialised to τΔ−1(Uniform[0.001, 0.1]), and the projection is widened from 1 to a small rank R (§3.6); the released code uses R = ⌈D/16⌉, 160 for Mamba-2.8B.

Try it: slide z down and the gate closes (Δ → 0, A → 1: keep the state, skip the token); slide it up and the token replaces the state. Solid lines are the theorem's zero-order hold; the dashed line is B as the released code computes it (selective_scan_ref): the first-order B = ΔB, equal to the gate for small Δ and larger beyond (at z = 2, 2.13 against 0.88). So the shipped models are not exactly the theorem's gated RNN; this page's toys follow the code.

The hardware-aware scan

§3.3, Appendix D

Time-varying parameters kill the convolution, and the plain recurrence is sequential and would materialise A, B and the state, each (B, L, D, N), N times the size of input and output (§3.3.2). But the recurrence costs O(BLDN) FLOPs against the convolution's O(BLD log L) with a lower constant, and outside matrix multiplication GPUs are limited by memory bandwidth, so the cost to cut is memory traffic. Three classical techniques do it: kernel fusion and recomputation (the stage beside this, run at Figure 8's setting) and a parallel scan (further down).

  1. The inputs sit in HBM. x and Δ are (B, L, D), B and C (B, L, N), A (D, N). HBM is large and slow, SRAM small and fast; the counts below are elements moved between them at L = 16,384, D = 1,024, N = 16, batch 1.
  2. Naive: discretise, write Ā and B̄x. A plain implementation reads the inputs (34,095,104 elements), computes A = exp(ΔA) and Bx, and writes both back: each (B, L, D, N), a stack of N = 16 inputs. So far 570,966,016.
  3. Naive: the scan writes every state. The scan reads A and Bx back and writes h, another (B, L, D, N) tensor. So far 1,376,272,384.
  4. Naive: read h and C, write y. The output needs the states once more. Whole run: 1,661,747,200 elements, almost all of them the three (B, L, D, N) tensors.
  5. Fused: load once into SRAM. One kernel loads (Δ, A, B, C) and x from slow HBM into fast SRAM (Appendix D).
  6. Fused: recur in SRAM, write only y. It discretises and recurs there; the state (D, N) per position never leaves SRAM, and only the (B, L, D) output is written. Long sequences go in chunks, carrying the state. Whole run: 50,872,320 elements, 32.7 times fewer, about 2N: IO falls by O(N), 20 to 40 times faster in practice.
  7. Backward: recompute, do not store. States needed for the backward pass are recomputed, not stored, which is faster than reading O(BLDN) from HBM. A selective SSM layer then stores about 16 bytes of activations per token, against about 12 for FlashAttention and 20 for an MLP: two Mamba blocks match one attention plus MLP pair.

Count the traffic yourself

Try it: HBM traffic of one scan, counted in elements from the steps of Appendix D (batch 1): naive writes A, B and h to HBM and reads them back; fused reads Δ, A, B, C, x once and writes y. The ratio grows with N, not L. Counted, not measured: at the paper's benchmark setting (D = 1,024, N = 16) it is about 33, against a measured 20 to 40 (§4.5).

The parallel scan

The recurrence is linear, and pairs (a, b) meaning h ↦ ah + b compose associatively, so a work-efficient (Blelloch) scan gets every ht in O(log L) parallel steps. The card runs eight positions with real numbers, one channel and one state entry, both ways.

  1. Start from h = 0. The loop applies one update per position, ht = At ht−1 + Bt xt, so h0 is just the first input.
  2. h1 to h3, one after another. Each step needs the previous one: the work is minimal (one multiply-add per position) but nothing runs in parallel.
  3. h4 to h6. Still one at a time: 8 positions take 8 dependent steps; a million positions take a million.
  4. h7. The last state, after 8 dependent steps: the value the parallel scan has to reproduce.

The Mamba block

§3.4, Figure 3

Earlier SSM architectures interleaved an H3 block with an MLP block; Mamba merges them into one block repeated homogeneously, like the gated attention unit (§3.4, Figure 3): expand D by E = 2 with two input projections; on the main branch a short causal convolution, SiLU and the selective SSM; on the other SiLU as a multiplicative gate; project back down. Against H3 it replaces the first gate with an activation; against the gated MLP (SwiGLU) it adds the SSM. Stack with RMSNorm and residuals: no attention, no separate MLP (an optional LayerNorm, after RetNet, can sit before the output projection).

Real states and the S4D-Real initialisation (§3.6)

Two further choices (§3.6): states are real, not complex, by default (complex helps on continuous signals such as audio, the one experiment that switches it), and A is initialised S4D-Real, An = −(n + 1), with the expectation that many initialisations work at scale.

Redrawn from Figure 3; parameters from the released code's shapes (mamba_simple.py) at D = 2,560. Projections are 3ED2 = 6D2; the SSM's own parameters add 4.7%, so two blocks are 1.05 × 12D2, one attention plus MLP pair: Mamba-2.8B has 64 blocks where a 2.8B Transformer has 32 layers.

Results

§4 Empirical Evaluation

Synthetics (§4.1). Selective Copying at length 4,096 with 16 tokens: S6 gets 99.7 to 99.8% inside H3 or Mamba blocks, every LTI layer 18.3% to 57.0% (Table 1). Induction Heads, 2-layer models trained at 256: Mamba is perfect up to 220 = 1,048,576, 4,096 times the training length (the text rounds to 4,000), while no other model goes beyond twice; attention was tested only to 16,384 for memory (Table 2, numbers in Table 11).

a 2-layer Mamba and a 2-layer Transformer with RoPE are both trained on induction heads at one length. Tested at 64 times that length, which still answers?

Language (§4.2). Under the Chinchilla protocol from about 125M to 1.3B on the Pile (Figure 4, sizes in Table 12), Mamba is the first attention-free model to match "Transformer++" (GPT-3 shapes plus rotary embeddings, SwiGLU, RMSNorm, no biases, higher learning rates), with the gap favouring Mamba at 8K context. Trained to 300B tokens with Pythia's data and tokenizer, every Mamba is best in its size class on every column of Table 3 (45 of 45 cells, one tie); Mamba-2.8B beats Pythia-2.8B on all six tasks (average 63.3 against 59.1) and Pythia-6.9B on the average (61.7). "Matches baselines at twice the model size" holds for three of five sizes, not at 130M or 370M (recount).

Average zero-shot accuracy against parameters, from Table 3 (log scale). Mamba, Pythia and RWKV share the Pile, the GPT-NeoX tokenizer and 300B tokens; the other baselines (GPT-Neo, OPT, Hybrid H3) differ in data or tokenizer. The paper's averages recompute exactly from its six columns.

DNA (§4.3). On one human genome (HG38, about 4.5 billion base pairs) Mamba matches Transformer++ and HyenaDNA with about 3 to 4 times fewer parameters at the largest size, about 40M (Figure 5, a figure with no table); at fixed size (about 1.4M) its perplexity keeps improving out to 1M-token context while HyenaDNA's gets worse. On five great apes sharing 99% of their DNA, a 7M Mamba fine-tuned at 1M context reaches 81.3% against HyenaDNA's 54.9% (chance 20%; Table 13).

Audio (§4.4): Mamba blocks in place of SaShiMi's S4 + MLP improve long-context piano modelling and SC09 speech generation (FID 0.94 for a 6.1M Mamba against 1.42 for the 23M DiffWave + SaShiMi).

Audio in detail (YouTubeMix, SC09, the U-Net ablation)

Swapping SaShiMi's S4 + MLP blocks for Mamba blocks: on YouTubeMix piano both improve with context and Mamba more, up to near-minute sequences at fixed compute (the one experiment with complex states). On SC09 spoken digits a 6.1M Mamba beats the larger GAN and diffusion models, FID 0.94 against 1.42 for the 23M DiffWave + SaShiMi, and a 24.3M one gets 0.67 (Table 4); Mamba blocks beat S4 + MLP in the outer U-Net stages, and in the center Mamba beats S4 + MLP, which beats attention (Table 5).

Speed and memory (§4.5, Figure 8). With N = 16 the fused scan beats FlashAttention-2 beyond length 2K and a PyTorch scan by 20 to 40 times; generation throughput is 4 to 5 times a same-size Transformer's because, with no KV cache, Mamba runs far larger batches (even an untrained Mamba-6.9B out-generates a Transformer five times smaller). Training memory at 125M is "comparable" to the best Transformer: in Table 15 Mamba needs 4% to 12% more.

Try it: why no KV cache means bigger batches: per-sequence memory of Pythia-2.8B (KV cache) and Mamba-2.8B (state) in bf16 from their configs, and how many sequences fit beside the 5.6 GB of weights. Illustrative: it ignores activations and allocator overhead; the paper's test uses prompt 2,048 plus 128 tokens (Appendix E.5).

Ablations at about 350M (§4.6). LTI layers barely differ from each other (within 0.3 perplexity) and real equals complex for text; S6 gives a large gain in either block (Mamba 10.56 → 8.69, H3 10.34 → 8.95; Table 6). Δ is the most important selective parameter (10.93 → 9.81 alone) and the three together beat any one (Table 7); real initialisations beat complex S4D-Lin when selective (Table 8); a rank-1 Δ projection gives most of its gain (Table 9).

raise the SSM state size N from 1 to 16 (about 1% more parameters). With B and C fixed (not selective), how much does perplexity improve?

How much of this to believe

§5 Discussion, Appendix E

What holds up. The mechanism and the synthetic evidence. The selective-copying gap (99.8% against 56.4% in the same block) dwarfs any plausible noise, the ablations agree (selective Δ, B, C each help; a larger state helps only when selective), and this page's toy reproduces the gap independently (it does not reproduce the indefinite induction-heads extrapolation: its selective model fades after about 8 times the training length). The language comparison is fairer than most: Mamba, Pythia and RWKV share data, tokenizer and token count, and with binomial errors from the evaluation set sizes the 2.8B gains on HellaSwag (+6.8, about 10 standard errors), LAMBADA (+4.5, 4.9) and ARC-Easy (+5.6, 4.1) are solid, WinoGrande (+3.8, 2.0) and ARC-Challenge (+3.4, 1.7) marginal, PIQA (+1.2, 0.8) noise (recount; conservative, since both models answer the same questions). Checkpoints and evaluation commands are public, an independent 8B study confirmed parity on these tasks, and the authors state their own limit: nothing above 3B, and scaling "may involve further engineering challenges" (§5).

What to discount:

  • Single runs, no error bars. Every result is one training run; several ablation gaps are hundredths of perplexity (ranks 1 and 2 of Table 9 both 8.97; two initialisations tie at 8.71 in Table 8), so those orderings are not established.
  • The throughput baseline is not an optimised server. The 5× (abstract; "4 to 5×" in §4.5) pits the fused Mamba kernels against "the standard Transformer implementation in the Huggingface transformers library" (Appendix E.5), not a paged server such as vLLM, and the Mamba-6.9B there is untrained. The direction is structural; the factor belongs to that baseline.
  • The speed numbers change with the comparison. "Up to 3× faster on A100" (introduction), "up to 7× faster than attention at 32K" (Appendix D), "20 to 40×" and "40×" against a PyTorch scan (§4.5, Figure 8): different baselines and lengths, and the core scan only.
  • "Comparable" memory is more memory. Table 15 shows Mamba using 4% to 12% more training memory than the FlashAttention-2 Transformer at every batch size, while §3.3 says the fused layer "has the same memory requirements".
  • Synthetic comparisons are not budget-matched. On induction heads Mamba has D = 64 where the others have 128, attention trained 50 epochs against Mamba's 25 and the LTI models' 10, each at the better of two learning rates, and Hyena's 69M parameters are mostly positional encodings (Appendix E.1). None of that explains a perfect result at 4,096× the length, but it is not like for like.
  • DNA results change sign across lengths. In Table 13 the 1.4M Mamba trails HyenaDNA at 212, 214 and 216 (by 0.9, 13.5, 1.5 points) and leads elsewhere; the 220 point is one run, and Mamba's pretraining learning rate (8e-3) was the top of its sweep (Appendix E.3).
  • Selection is not free on every modality. The paper's own audio ablation shows S6 "significantly hampers" performance on raw waveforms, where LTI layers fit better (Figure 10); the authors report it, which counts in their favour.
  • Later controlled tests narrow the language claim. Waleffe et al. (NVIDIA, with Gu and Dao; 2024) trained 8B Mamba, Mamba-2 and Transformer models on the same 1.1T tokens: Mamba matched the Transformer on the common zero-shot average (68.07 against 67.87) but scored 28.00 against 46.28 on 5-shot MMLU, and SSMs stayed behind on Phonebook copying and long-context reasoning; 3.5T tokens narrowed MMLU for Mamba-2 to 1.4 points. Copying and recall are where a fixed state is provably limited (Jelassi et al., 2024; Arora et al., 2023).

Verdict: believe that selection is the missing ingredient that makes recurrent state-space models competitive, and that they generate far more cheaply; the synthetic and ablation evidence is strong and reproduces. Treat "Transformer quality" as true for perplexity and common zero-shot tasks at up to 3B parameters, from single runs; it does not extend to recall-heavy use, which is exactly where later work found the gap and why the field settled on hybrids.

What it takes to use this

  • Code and licence. state-spaces/mamba, Apache 2.0: the selective scan CUDA kernel, the block, Mamba-2 and Mamba-3. Core requirements are Linux, Python 3.10+ and PyTorch; the fast kernels need an NVIDIA GPU with CUDA 11.6+ (AMD ROCm has extra prerequisites), and in the current README they are an opt-in build (MAMBA_KEEP_CUDA_BUILD=TRUE). Hugging Face transformers has Mamba classes that run without the kernels, slowly (docs).
  • Checkpoints. Mamba 130M, 370M, 790M, 1.4B and 2.8B, all trained on 300B tokens of the Pile, plus a 2.8B trained on 600B tokens of SlimPajama; base models only, no instruction tuning (README). Their sizes recount exactly from the configs (129.1M to 2,768M, Tables tab).
  • Budget. The paper's largest runs are 2.8B parameters on 300B tokens; the scaling-law runs follow GPT-3 shapes with Chinchilla token counts (2.5B to 26B tokens, Table 12). Training needs the fused kernel: in Waleffe et al. the 8B Mamba-1 trained almost 3× slower than Mamba-2 because of its large state.
  • When it pays off. Long sequences and generation-heavy serving (constant memory per sequence, large batches); continuous or very long signals (DNA, audio, time series), though raw audio waveforms preferred the LTI layer. When it buys little: short contexts where FlashAttention is as fast (the scan only wins beyond about 2K), and tasks that need exact recall or copying from a long context, where hybrids with a few attention layers are the practical choice (Then and now).

Why it matters (beyond the paper)

Mamba ended the era in which subquadratic meant worse: a recurrent model with input-dependent dynamics matched Transformer perplexity and common benchmarks while training in linear time and generating with constant state. The compression framing stuck (attention is the no-compression extreme, a classic RNN the full-compression one, selectivity the knob between), and with FlashAttention, by the same author, it cemented the pattern that architecture design and GPU memory-hierarchy design are one discipline.

The authors followed up twice; both are taught on Beyond attention and summarised here. Mamba-2 (Dao and Gu, 2024) introduced state space duality: selective SSMs and masked attention are both structured semiseparable matrices; a scalar A per head turns the scan into matrix multiplications, simpler and 2 to 8 times faster, with much larger states (released default N = 128) and a clean bridge to attention theory. Mamba-3 (Lahoti et al., 2026) went "inference-first" (a more expressive discretisation, complex-valued state for state tracking, multi-input multi-output) and reports Mamba-2's perplexity at half the state size.

In production the winner is the hybrid: a few full-attention layers for exact recall, SSM or linear-attention layers for cheap length (each drawn from its config in Then and now; the design space is on Beyond attention). Pure SSMs stay rarer because exact long-range retrieval still favours some attention, but the selective recurrence is now standard infrastructure for long context, edge inference and non-text sequences (DNA, audio, time series, vision backbones).

Who ships hybrids, as of 25 October 2026

AI21's Jamba (1 attention layer in 8, plus MoE); NVIDIA's Nemotron-H (Mamba-2 plus attention, up to 3× faster than similar Transformers at similar accuracy), the architecture its Nemotron Nano 2 reasoning models build on, and Nemotron 3 Nano; IBM's Granite 4.0-H; TII's Falcon-H1 (attention and Mamba-2 side by side in every layer). Frontier labs ship the same idea with linear or sliding-window hybrid layers to cut long-context prefill and KV-cache cost (for example MiniMax's lightning attention).

Connections