esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

State-Space Models (e.g. Mamba) vs Transformers

How state-space models like Mamba compare with transformers, what each gains and gives up, and where hybrids fit, explained for your AI interview.

In short

State-space models like Mamba keep one fixed-size memory that they update as each token arrives, so long inputs stay cheap. Transformers look back at every earlier token, which keeps every detail within reach but costs more as the text grows.

10 min readAdvancedOccasional · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Most large language models are built on transformers. A transformer looks back at every earlier token each time it writes the next one. A state-space model, like Mamba, reads the text in order and keeps one fixed-size memory it updates as it goes. That keeps long inputs cheap. The cost is that it can lose a detail it never kept, so some designs, like Jamba, mix both.

What are state-space models, in plain words?

A language model reads text as a list of tokens, small pieces of words. Each new token depends on what came before, so the model needs a way to remember the past.

A transformer remembers by looking back. A state-space model remembers by keeping a running summary. Both answer the same question, but they keep very different amounts of the past.

Think of a night-shift nurse handing over a long ward. She could reread every patient's full chart each time someone asks a question, which is the transformer way. Or she could keep one notebook of key facts and update it every hour, which is the state-space way. The notebook is quick to use and never grows, but a fact she never wrote down is lost.

Here is the same idea in a model. Asked about a 300-page contract, a transformer looks back at every earlier word for each new word. A state-space model answers from one running summary of the contract so far.

Key words

Token
A small piece of text, often part of a word, that the model reads and writes one at a time.
Attention
The transformer step that compares the new token with the earlier tokens to decide what matters.
KV cache
The memory where a transformer keeps the keys and values of its past tokens, so it can look back while it writes.
State
A fixed-size summary that a state-space model updates as each token arrives.

How does each one remember what it has read?

A transformer keeps the whole past. Attention lets each new token look back over the window, which the Mamba paper describes as the ability to route information densely within a context window. The cost is memory: every past token has to be stored, so the cache grows with the text.

A state-space model keeps only a state of fixed size. The Mamba paper puts the trade-off plainly: a small state is efficient, but the state has to hold everything the model needs from the text. Mamba adds one idea on top. Its update depends on the current token, so the model can choose what to keep and what to forget. The paper calls this selection.

Two ways to remember the text

New token

the next piece of text to read

Transformer

Memory of every token

grows with each new token

Attention

compares with every stored token

State-space model

Update one summary

keeps what matters, drops the rest

Fixed-size state

the same size however long

Cost grows with length

each token scans a longer cache

Steady cost per token

each token: fixed-size update

  1. 1The new token goes to the transformer path, which keeps every earlier token.
  2. 2The same token goes to the state path, which updates one summary.
  3. 3Each new token on the transformer path scans a longer cache.
  4. 4The state path's work stays steady for each new token.
Same new token, two paths. The transformer keeps every past token, so each new token scans a longer cache. The state-space path keeps one fixed summary, so each token's update stays the same size.

What do you gain, and what do you give up?

  • Long input

    The state-space model wins on cost

    Its work grows in a straight line with the length of the text. Over a whole text, attention's work grows with the square of its length, and each new token scans a longer cache.

  • Exact recall

    The transformer keeps every detail

    It can look back at any token in its window. A state-space model can lose a detail that its summary dropped.

  • Track record

    Transformers came first

    Transformers have been the main architecture behind deep learning's success in language modelling. The 2024 Mamba-2 paper says state-space models have recently been shown to match or beat them, at small to medium scale.

  • “quadratic scaling with respect to the window length”

    Gu and Dao, Mamba paper (2023)

  • “state-space models (SSMs) such as Mamba have recently been shown to match or outperform Transformers at small to medium scale”

    Dao and Gu, Mamba-2 paper (2024)

Tip

Asked to pick one, name the cost you can afford: speed on long input, or exact recall across the whole text.

Why do some newer models mix both?

Some designs use both kinds of layers in one model. The Jamba paper from March 2024 studies how to combine Transformer and Mamba layers, and reports a model that gives high throughput and a small memory footprint.

  • “Jamba interleaves blocks of Transformer and Mamba layers, enjoying the benefits of both model families”

    Lieber and colleagues, Jamba paper (2024)

A hybrid stack, repeated

Text in

tokens from the prompt

Repeated blocks

Mamba layers

keep a fixed state per token

Attention layers

look back at stored tokens

Text out

the next token, from the whole stack

  1. 1The text enters the stack of blocks.
  2. 2The layers interleave: Mamba and attention blocks take turns, as the Jamba paper describes.
  3. 3The stack hands its result to the output.
A hybrid stack mixes Mamba layers and attention layers in one model. The mix is a design choice, and the paper studies how to combine the two kinds of layers.

How would you choose for a factory's sensor stream?

A factory has 400 compressors, and each one sends a reading every second. That is about 34.6 million readings a day, with no natural end. The team wants an alarm when a machine starts to drift.

  • State-space model

    Steady cost, a fixed memory

    It keeps one summary per machine and updates it with each reading. Cost per reading stays flat, so the stream can run for months.

  • Transformer

    Memory grows with the stream

    A full transformer keeps every past reading in its cache, so memory and work climb as the stream grows. Capping the window means dropping old readings.

I would start with the state-space model for the alarm. Then I would replay a year of past failures and check which ones it missed, before trusting it. If the team also needs to point at the earlier event behind a flagged reading, a hybrid or a transformer on a recent slice is worth testing.

Tip

Count the missed faults before you celebrate the low cost.

What does the interviewer want to hear?

A strong answer covers

  • Transformers look back at every token; state-space models keep a fixed-size state.
  • Over a whole text, attention's work grows with length squared; each new token scans a longer cache.
  • A fixed state can lose detail, so exact recall is the trade-off.
  • Name the papers: Mamba (2023), Mamba-2 (2024), and Jamba (2024) for hybrids.
  • Hybrids mix both kinds of layers, as a design choice.
  • Choose by the input, and test on your own data first.

Common traps

  • Trap"Mamba replaces transformers everywhere."

    BetterThe Mamba paper says foundation models are almost universally transformers. Mamba trades some exact recall for speed on long input.

  • Trap"A bigger state holds everything."

    BetterA bigger state holds more, but it is still a fixed summary. Hybrids add attention layers for exact lookup.

  • Trap"Linear cost always means faster."

    BetterCost per token helps long input. Speed also depends on the hardware, and Mamba needed a special hardware-aware algorithm to run fast.

Can you spot the right trade-off?

Spot the trade-off

A bank's fraud team must check one customer's five-year transaction history for a single question. Which design keeps every old detail within reach?

Quick check

A legal team must find one exact clause across 40,000 contracts. Why might it pick a hybrid like Jamba?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q068How does the final hidden state become the next token?9 min
  2. Q069What is an attention sink?13 min
  3. Q070How do long-context extensions like RoPE scaling work?11 min
  4. Q073Walk through one decoder block's forward pass.12 min
  5. Q074What uses memory at inference time?11 min

Last updated on 27 November 2026

Choosing a model for a long data stream?

I design and build AI products and agents, including the system behind them. Book a short call and say what you need: the data, how long it runs, and what a missed event costs.