Before you move a control in the demo, say what you expect to change.
Foundation reference
State Space Models & Hybrid Architectures: Mamba-2, Jamba, Griffin
State space models keep a fixed-size state instead of a key–value cache that grows with every token, so their memory and per-token cost do not grow with context length.
Study guide
Where to start
In what sense is an SSM "attention with a structured kernel", and what does that view leave out?
How to study this pagePredict · Check · Generalize · Continue
Compare what the demo shows with the key equation and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
Use the prerequisites and related concepts at the end of the page to fill the next gap.
Why It Matters for Modern Models
- State space models keep a fixed-size state instead of a key–value cache that grows with every token, so their memory and per-token cost do not grow with context length.
- Mamba-2's state space duality shows that SSMs and attention are two ways of computing structured weighted sums over the past, which lets SSM layers run largely as matrix multiplications on GPUs (Dao & Gu, 2024).
- Jamba interleaves Mamba and attention layers, adds mixture-of-experts layers, and reports strong results for contexts up to 256K tokens (Lieber et al., 2024).
- Griffin and RecurrentGemma mix gated linear recurrences with local attention, keeping a fixed-size state while still attending exactly to recent tokens (De et al., 2024; Botev et al., 2024).
- Selectivity, the input-dependent update, is what made SSMs competitive on language; without it the layer is a fixed linear filter whose weights cannot depend on token content (Gu & Dao, 2024).
Questions to Think About
- Why does a time-invariant SSM behave like a fixed convolution filter, and how do input-dependent parameters let it retrieve a specific earlier token?
- Why combine local attention for recent tokens with a recurrence for longer-range memory, instead of using either alone?
- A fixed-size state never grows, but it must compress everything seen so far; why does this make exact copying and recall from long inputs harder than for transformers (Jelassi et al., 2024)?
- Why do SSMs still need specialized GPU kernels, such as Mamba's parallel scan, and how does Mamba-2 recast most of the computation as matrix multiplication?
Interactive Demos
Core Math
If you prefer intuition first, try the demos above, then come back for the math.
A state space model (SSM) layer summarizes the past in a fixed-size state that is updated once per token, instead of attending over all previous tokens. Hybrid architectures interleave such layers with attention layers.
Discrete linear SSM:
The state has a fixed size, so generation needs constant memory per step and time for a sequence of length .
The same layer as a convolution:
Unrolling the recurrence from gives
so the output is a weighted sum over past inputs, as in attention, but with weights fixed by , and rather than computed from the content. Dao & Gu (2024) make the link precise: an SSM layer is a form of linear attention with a structured mask.
Selectivity:
In Mamba, , and the step size used to discretize are computed from the current input, while itself does not depend on the input (Gu & Dao, 2024). Input-dependent parameters let the layer decide what to store and what to forget, which a fixed kernel cannot do. The convolution view then no longer applies, and Mamba evaluates the recurrence with a parallel scan.
Hybrids interleave layer types:
with an MLP after each mixing layer. Jamba uses one attention layer for every seven Mamba layers (Lieber et al., 2024); Griffin alternates two gated-recurrence blocks with one local-attention block (De et al., 2024).