Frontier Foundry

State space models vs Transformers

36 sourced facts · updated

State space models (Mamba) or transformers: what is the difference?

A transformer lets every token look back at every earlier token, so its cost grows with the length of the input. A state space model reads the input once and keeps one fixed-size state, so compute grows linearly and memory stays constant. The price is a lossy memory: early details can be overwritten. The sources show newer models mixing the two, with a few attention layers kept to carry exact retrieval. [1][2][3][4]

In the knowledge graph: Both turn a sequence into its next step: one carries a running state, the other looks back at everything.

The difference between State space models and Transformers

State space modelsTransformers
What it keeps of the pastOne fixed-size state, updated token by token. Albert Gu calls it a brain: it compresses what it saw. [2][3]A key and a value vector for every earlier token: ten tokens need ten sets, a thousand tokens need a thousand. Gu calls this a database that can look back exactly. [5][6]
Cost as the input growsCompute grows only linearly and memory stays constant. [1][2]Attention costs quadratic computation, because every element interacts pairwise with every other, and memory grows linearly with context on top of that. In NVIDIA's words, processing the 10-millionth token takes a million times longer than the 10th. [7][8]
Exact recallWeak. The price of the fixed state is weak fine-grained recall and retrieval. One lab found its linearized versions had trouble learning dependencies at long context. [3][9]Strong. Some attention heads do the retrieval: after removing the top 50 heads found by one method, Qwen3-8B fell from 0.401 to 0.000 ROUGE-L on a non-literal retrieval benchmark. [10][11]
Fit with GPUsRecurrence is cheap only in theory until it can run in parallel. Linearizing it makes that possible, and a parallel scan turns L sequential steps into about log2 L parallel steps. The cost is that the linear form is less expressive. [12][13][14]Transformers are matrix multiplications and scale on the hardware that exists. FlashAttention-style kernels tile the attention matrices to fit in fast memory. [15]
What serving costs in memoryA constant slab per sequence, but not a small one: in NVIDIA's analysis one SSM layer's FP32 state is 4 MiB per sequence, equal to the KV of 8K tokens. [16]A shelf that grows with context and with users. For the 7B model in one workshop it is 131 KB per token, and at a 4K context and 80 users it comes to about 42 GB, more than a 24 GB card holds. [17][18]
Where it is usedSequential data such as time series and voice, and long document pages: one document model chose a state-space backbone for long pages and accepted somewhat lossy recall to avoid the compute cost of a transformer. [19][20]The loop behind every token a model writes: attention works out which tokens refer to which, and the feed-forward layers are where stored knowledge mostly sits. [21][22]
How serving goes wrongSilently. Attention writes its cache before reading it, but a Mamba decode step reads the state first, so a stale slot corrupts the answer. One engine returned gibberish on about 1 in 1,000 requests, and nothing crashed. [23][24]At the edge of memory or in the kernel: the shelf outgrows the card, or a tuning change backfires. NVIDIA's larger FlashAttention tiles made the kernel 18-43% slower. [18][25]

When to use State space models

  • The input is long and sequential, such as time series, voice or a long document page, and the cost of attention over all of it is the problem. [19][20][7]
  • The task is long-horizon generation where bounded attention caches limit access to distant history: one motion-generation model uses Mamba to keep resumable recurrent states plus a persistent content memory. [26]
  • You can accept lossy memory for constant memory. The sources say the update rule decides what is written and how strongly it overwrites, and a gated, correctable memory did best in one comparison of three subquadratic designs. [27][28][8]

When to use Transformers

  • You need to find one specific fact buried in a long context. NVIDIA says pure SSMs struggle with precise associative recall, and Albert Gu names weak fine-grained recall as the price of the fixed state. [4][3]
  • You want to avoid immature tooling. A lab that linearized recurrent nets found the state-space versions had trouble learning long-context dependencies, and open inference kernels for hybrids were immature when Olmo Hybrid was post-trained. [9][29]
  • You would rather shrink attention's cost than change architecture. The transformer sources list fixes: grouped-query attention cut key-value memory 4x in the workshop's example (8 key-value heads in place of 32), and quantizing the cache lets the same memory hold more tokens or users. [30][31][13]

Using State space models and Transformers together

The sources show the two mixed: hybrids keep a few attention layers among the state-space layers. Long-range retrieval is mainly carried by the full-attention layers. One hybrid Mamba-attention model with 55 billion active parameters was extended to 1M tokens of context, and Albert Gu says today's models use at least 3:1 or 4:1 SSM to attention layers, where older papers found about 10:1 best. Hybrids are not free: Olmo Hybrid gained about 2x in pretraining, but post-training results were mixed and RL took more compute than the dense 7B model. [32][33][34][29][4]

Does a model need a very long context, or is a short one with frequent compaction enough?

The sources disagree. One says a very long context is worth building, since a hybrid with a one-million-token context suits long-running autonomous agent tasks. Another says frequent compaction kept task accuracy with short contexts, so long-context models may be unnecessary. [35][36][8]

Each one on its own

from their concept pages

What is State space models?

A state space model reads text one token at a time and keeps a fixed-size running summary instead of looking back at everything. Memory use stays constant however long the input grows. That makes very long sequences cheap, at the risk of forgetting details the summary did not keep.

A state space model reads a long input once, token by token, and keeps one fixed-size state instead of a growing cache: compute grows linearly and memory stays constant. The price is a lossy memory, so early details can be overwritten; the sources show hybrids that keep a few full-attention layers to carry long-range retrieval, and that serving the state is its own hazard.

5,000 to 10,000 visual tokens
Tokens on one long document page in a document-reading system whose speaker explains why a state-space backbone fits long pages; reported by the speaker Krishna Prasad Srinivasan
up to ~6x
Inference throughput of a large hybrid Mamba-attention model against publicly available models of similar accuracy; reported by the model authors Hugging Face

State space models, explained in full: how it works as a machine, every part and its sources.

What is Transformers?

A transformer writes text one token at a time. Each token becomes a vector and passes through a stack of layers, where attention scores it against every earlier token, and the last layer picks the next token, which goes back in. The memory it must keep grows with the length of the context.

In this corpus a transformer is the loop behind every token a model writes: text is cut into tokens, embedded, and put through a stack of layers whose attention scores each token against all earlier ones, then one new token is chosen and goes back in. The sources are about its costs (quadratic attention, the key-value shelf that grows per token) and its fixes (fused norms, grouped heads, sparse blocks, cache compression), and one bug a speed-up exposed.

16 by 16
Patch size of the original vision transformer: the image is cut into patches this size before they become tokens (reported by a Roboflow talk) Isaac Robinson
32 layers
Transformer layers in the 7B model used in the inference workshop (varies by model) Harshul Jain
4x near-lossless
Value-cache compression from predicting values from keys in LowRAM Hugging Face

Transformers, explained in full: how it works as a machine, every part and its sources.

In AI coverage over the last four weeks, State space models took 0.10% and Transformers 2.6%.

The facts behind this page

36 facts from the two knowledge packs
  1. In a transformer every token looks at every other token, so compute grows with the square of the sequence length and memory grows with it. Krishna Prasad Srinivasan, AI Engineer · 2026-06-29 · State space models
  2. A state space model keeps a single state and updates it token by token, so compute grows only linearly and memory stays constant. Krishna Prasad Srinivasan, AI Engineer · 2026-06-29 · State space models
  3. Albert Gu (Cartesia, CMU) frames a transformer as a database (its KV cache writes down every token and can look back exactly) and an SSM as a brain (a fixed-size state that compresses what it saw). The price of the fixed state is weak fine-grained recall and retrieval. stanford · 2026-04-27 · State space models
  4. A hybrid keeps attention layers among state-space layers on purpose: NVIDIA says pure SSMs struggle with precise associative recall, finding one specific fact buried in long context, and the interleaved attention layers keep that retrieval working. nvidia · 2026-03-11 · Transformers
  5. The number of key and value vectors grows with the input: ten tokens need ten sets, a thousand tokens need a thousand sets. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  6. Without a cache each decode step recomputes keys and values for all earlier tokens (quadratic); the KV cache trades that compute for memory. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  7. Attention costs quadratic computation because every element of the sequence interacts pairwise with every other, and memory grows linearly with context on top of that. Max Ryabinin, AI Engineer · 2026-04-08 · Transformers
  8. Full attention caches and compares every earlier key and value, so the cost per token grows with context: in NVIDIA's words, processing the 10-millionth token takes a million times longer than the 10th. Sliding-window, Mamba and Gated DeltaNet layers cost a constant amount per token but lose information that would have predicted later tokens. nvidia · 2026-01-09 · Transformers
  9. The linear memory that forgot the far end. A lab built on continuous-time recurrent nets linearized them so they could scale and run in parallel. Applied to language, the state-space versions had trouble learning dependencies at long context: they computed efficiently, but their expressive power fell short of transformers. Latent Space · 2026-09-18 · State space models
  10. Some attention heads do the retrieval: LOCOS scores each head by how its output projects onto the answer token, and removing the top heads wipes out non-literal retrieval. Hugging Face · 2026-07-03 · Transformers
  11. 0.401 to 0.000: ROUGE-L of Qwen3-8B on a non-literal retrieval benchmark after ablating the top 50 heads found by LOCOS Hugging Face · 2026-07-03 · Transformers
  12. Recurrence brings the cost of reading more data down to sub-quadratic or near-linear, but only in theory until it can be run in parallel on GPUs. Ramin Hasani, Latent Space · 2026-09-18 · State space models
  13. Nonlinear recurrent networks are hard to parallelize on GPUs; transformers are matrix multiplications and scale on the hardware that exists. Ramin Hasani, Latent Space · 2026-09-18 · State space models
  14. Linear recurrences can be trained in parallel because linear operations are associative: a parallel scan turns L sequential steps into about log2 L parallel steps, so doubling the sequence adds one step. The cost, per Apple, is that a linear system can model fewer kinds of state evolution. apple · 2026-04-23 · State space models
  15. FlashAttention cuts the big matrices into small tiles that fit in fast memory and keeps running sums, so the softmax is computed online. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  16. 4 MiB per sequence per SSM layer: FP32 state of one SSM layer in NVIDIA's ReplaySSM analysis, against an FP8 KV entry of 0.5 KiB per token, so one SSM state equals the KV of 8K tokens; the model has five times as many SSM layers as attention layers, and at batch 256 the SSM layers are the largest part of the decode step up to 100K tokens (Nemotron-3-Super-NVFP4, one B300). nvidia · 2026-10-12 · State space models
  17. 131 KB per token: Key-value memory per token for the 7B model in the workshop (two vectors of 128 dimensions, times 32 layers, times the key-value heads) Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  18. The shelf that outgrew the card. The key-value shelf grows with context and with the number of users served at once. At a 4K context and 80 users it comes to about 42 GB, so a 24 GB card is already out of memory. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  19. State space models and recurrent nets suit sequential data such as time series and voice, where there is not much state to carry. Ramin Hasani, Latent Space · 2026-09-18 · State space models
  20. A document model chose a state-space backbone for long pages and accepted somewhat lossy recall to avoid the compute cost a transformer would impose. Krishna Prasad Srinivasan, AI Engineer · 2026-06-29 · State space models
  21. Division of labour inside a layer, as a Microsoft Research scientist puts it: attention works out which tokens refer to which in the context, while the feed-forward layers are where a modern model's stored knowledge mostly sits. Doug Burger, Subutai Ahmad, Nicolo Fusi, microsoft · 2026-03-23 · Transformers
  22. A new token is generated, goes back into the input, and the next one is generated, again and again. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  23. In attention the key-value cache is written before it is read, so stale data is overwritten; in Mamba a decode step reads the state first, so a stale slot corrupts the answer. Asaf Gardin, AI Engineer · 2026-07-02 · State space models
  24. The request that read someone else's state. During reinforcement learning on a hybrid model, about one request in a thousand came back as gibberish in one serving engine only, late in a run. The scheduler had sent a new request to decode before prefill, so decode read the state slot of an earlier request. Attention writes its cache before reading it; the state reads first. Asaf Gardin, AI Engineer · 2026-07-02 · State space models
  25. Bigger tiles made the attention kernel 18-43% slower. NVIDIA tuned a cuTile FlashAttention kernel by raising the tile from 64x64 to 256x128, expecting better memory use. Throughput fell 18-43% at every sequence length: compute throughput collapsed to 17.4% and the grid shrank to 512 blocks, because the separate multiply and add and precise math became the bottleneck. nvidia · 2026-03-05 · Transformers
  26. For long-horizon motion generation, bounded attention caches limit access to distant history; a Mamba-based model keeps resumable recurrent states plus a persistent content memory. Hugging Face · 2026-11-24 · State space models
  27. A fixed-size recurrent memory forces an online choice at every token: what to write and how strongly to overwrite what is already stored, before knowing what later queries will need. Hugging Face · 2026-09-09 · State space models
  28. In a comparison of three subquadratic designs, the one with a gated, correctable memory did best, because its gating makes memory correction more flexible and stable. Hugging Face · 2026-06-11 · State space models
  29. The hybrid that was cheaper to train but dearer to post-train. Olmo Hybrid gained about 2x in pretraining, but in post-training the results were mixed: gains in knowledge, losses in extended reasoning. Open-source inference kernels for hybrids were immature, so stable scores needed flags (--disable-cascade-attn, --enforce-eager, FP32 state cache) that cut throughput, and the 7B hybrid took more compute for RL than the 7B dense model. Nathan Lambert, Interconnects · 2026-03-05 · State space models
  30. 4x: Key-value compression when 8 key-value heads replace 32 (grouped-query attention), as computed in the workshop Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  31. Quantizing the key-value cache lets the same memory hold more key and value vectors, hence more tokens or users. Harshul Jain, AI Engineer · 2026-09-08 · Transformers
  32. In hybrids, long-range retrieval is mainly carried by the full-attention layers; the efficient layers shape how training proceeds. Hugging Face · 2026-06-17 · State space models
  33. A 550-billion-parameter hybrid Mamba-attention model with 55 billion active parameters was pretrained on 20 trillion tokens and extended to one million tokens of context. Hugging Face · 2026-06-16 · State space models
  34. about 10:1 earlier, now at least 3:1 or 4:1: Layer ratio of SSM to attention layers in hybrids: older papers independently found about 10:1 best by perplexity; Albert Gu says today's models use at least 3:1 or 4:1. stanford · 2026-04-27 · State space models
  35. Does a model need a very long context, or is a short one with frequent compaction enough? A very long context is worth building: a hybrid with a one-million-token context suits long-running autonomous agent tasks. Hugging Face · 2026-06-16 · State space models
  36. Does a model need a very long context, or is a short one with frequent compaction enough? Frequent compaction keeps task accuracy with short contexts, so long-context models may be unnecessary and a memory of compacted state could do instead. Hugging Face · 2026-11-04 · State space models

Cite this page

the version of 2026-12-02
APA
Han, R. (2026, December 2). State space models vs Transformers: what is the difference?. Frontier Foundry. https://www.ryanhan.ai/compare/state-space-models-vs-transformers
BibTeX
@misc{han2026-compare-state-space-models-vs-transformers,
  author       = {Han, Ryan},
  title        = {{State space models vs Transformers: what is the difference?}},
  howpublished = {Frontier Foundry},
  year         = {2026},
  month        = dec,
  url          = {https://www.ryanhan.ai/compare/state-space-models-vs-transformers}
}

More comparisons

all of them