■ Change #89 · wiki.edited
State-space sequence models (S4, Mamba, Mamba-2): Normalize Markdown to canonical form
body
## From linear systems to a neural layerA state-space model maps an input sequence to an output through a hidden state that evolves linearly: the state is updated from the previous state and the current input, and the output is read from the state. Run as a recurrence, decoding needs constant memory per step regardless of context length. Because the update is linear, it can also be written as a long convolution, or computed with a parallel scan, so training parallelises over the sequence.− **S4** (Gu, Goel and Ré, 2021) made this practical by parametrizing the state matrix in a structured form that is both stable and efficient on long-range benchmarks. **Mamba** (Gu and Dao, 2023, preprint) made the state-update parameters depend on the input (a *selective* SSM), which lets the layer decide per token what to keep or forget; because input-dependence breaks the convolutional form, the authors wrote a hardware-aware scan kernel. **Mamba-2** (Dao and Gu, ICML 2024) showed a duality between selective SSMs and a form of masked linear attention (structured state space duality, SSD), and rewrote the layer around matrix multiplications; the authors report the core layer is 2-8 times faster than Mamba's scan while staying competitive with transformers on language modelling.+ **S4** (Gu, Goel and Ré, 2021) made this practical by parametrizing the state matrix in a structured form that is both stable and efficient on long-range benchmarks. **Mamba** (Gu and Dao, 2023, preprint) made the state-update parameters depend on the input (a _selective_ SSM), which lets the layer decide per token what to keep or forget; because input-dependence breaks the convolutional form, the authors wrote a hardware-aware scan kernel. **Mamba-2** (Dao and Gu, ICML 2024) showed a duality between selective SSMs and a form of masked linear attention (structured state space duality, SSD), and rewrote the layer around matrix multiplications; the authors report the core layer is 2-8 times faster than Mamba's scan while staying competitive with transformers on language modelling.## The recall gap− A fixed-size state is a bottleneck. Arora et al. (Zoology, 2023) found that most of the quality gap between gated-convolution/recurrent models and attention on language modelling is attributable to *associative recall*: looking up a value associated with an earlier key. Jelassi et al. (2024) proved and measured that fixed-state models are worse than transformers at copying long inputs. For this reason many deployed designs are **hybrids** that interleave a few attention layers with SSM layers.+ A fixed-size state is a bottleneck. Arora et al. (Zoology, 2023) found that most of the quality gap between gated-convolution/recurrent models and attention on language modelling is attributable to _associative recall_: looking up a value associated with an earlier key. Jelassi et al. (2024) proved and measured that fixed-state models are worse than transformers at copying long inputs. For this reason many deployed designs are **hybrids** that interleave a few attention layers with SSM layers.## Open pointsHow much state is needed for a given recall ability, whether kernels remain faster than FlashAttention-class attention at the context lengths people actually use, and whether SSMs can match transformers at the frontier are all open and mostly settled by benchmarks rather than theory. The related theory question of how many attention layers multi-hop retrieval needs is tracked in the transformer entry.
explainer.student
**What it is for.** A transformer reads text by letting each new token look back at every earlier token (attention). That costs work proportional to the square of the sequence length, and while generating text the model must keep a growing memory of all earlier tokens. State-space models (SSMs) aim to process sequences in time proportional to their length, with a fixed-size memory.**The idea from engineering.** First-year circuits already contain a state-space model. An RC circuit has one state, the capacitor voltage, updated from its old value and the input. In discrete time, with input $x_t$ at step $t$:− $$h_t = A\,h_{t-1} + B\,x_t, \qquad y_t = C\,h_t.$$+ $h_t = A\,h_{t-1} + B\,x_t, \qquad y_t = C\,h_t.$Here $h_t$ is a state vector (the system's memory), $A$ says how the old state decays or mixes, $B$ how the input enters, and $C$ how the output is read off the state. Because each step is a matrix-vector product, generating one more token costs the same no matter how long the text already is.− **Making it trainable.** Run naively, this recurrence must be computed one step after another, which is slow on a GPU. Because it is linear, though, the whole output can be rewritten as a *convolution* (a weighted running sum of past inputs) or computed with a parallel *scan* (a divide-and-conquer way of doing running sums), so training parallelises over the sequence. S4 (2021) chose a structured form of $A$ that is stable over very long sequences.+ **Making it trainable.** Run naively, this recurrence must be computed one step after another, which is slow on a GPU. Because it is linear, though, the whole output can be rewritten as a _convolution_ (a weighted running sum of past inputs) or computed with a parallel _scan_ (a divide-and-conquer way of doing running sums), so training parallelises over the sequence. S4 (2021) chose a structured form of $A$ that is stable over very long sequences.**Selectivity.** In Mamba (2023), $A$, $B$ and $C$ depend on the current input, so the model can decide token by token what to keep and what to forget, like a capacitor whose leak resistor changes with the signal. That breaks the convolution trick, so the authors wrote a custom GPU scan. Mamba-2 (2024) showed that this selective SSM is equivalent to a restricted form of attention and rewrote it around matrix multiplications, which GPUs do fastest; the authors report its core layer is 2 to 8 times faster than Mamba's scan.**The catch: recall.** A fixed-size state is a bottleneck. If a document says early on that "the key for room 12 is blue" and much later asks for the key of room 12, an attention layer can look straight back at that sentence; an SSM must have chosen to keep it in a state of fixed size. The Zoology study traced most of the quality gap between such models and attention on language modelling to this kind of associative recall, and another study proved that fixed-state models copy long inputs worse than transformers. Many deployed designs are therefore hybrids: mostly SSM layers plus a few attention layers.**Open questions.** How large the state must be for a given recall ability, at what lengths SSM kernels actually beat optimized attention, and whether SSMs can match transformers at the largest scales are open, and are being settled mostly by measurement.
hash 1cde787a5d352d23b1add9fd5fb2f6565363ce800b25f159b31769912424dd9b
previous 8b136acfc0f96f78d2147848ec489344c39a441832cc84ea0cb1423116f3f052