tezvyn:

State-Space Models Replace Quadratic Attention

AI-drafted, machine-checkedintermediate

State-space models replace attention with recurrent linear dynamics, scaling linearly with sequence length. They excel at long DNA, audio, and video modeling. The footgun is naive discretization, which collapses stability on long sequences.

WHY IT EXISTS: Transformer self-attention scales quadratically with sequence length, making it prohibitively expensive for very long inputs like raw audio waveforms, genomic sequences, or high-resolution video. State-space models were invented to escape this bottleneck by returning to recurrent mechanics, but with stable gradients and training parallelization that classic RNNs lacked.

THE MENTAL MODEL: Picture a reservoir with thousands of spigots. Instead of comparing every drop of water to every other drop, which is what attention does, water flows through the reservoir in a fixed pattern. The internal water level at any moment summarizes the entire history of what has flowed in. You read the output by tapping the spigots. The engineering trick is designing the pipe geometry so that both recent inputs and salient ancient inputs influence the current level, while the flow equations remain simple enough to compute in parallel across time.

HOW IT WORKS: An SSM is defined by a continuous state equation where the hidden state derivative equals a matrix times the current state plus an input term, and an output equation that projects the hidden state to observations. For deep learning, this continuous system is discretized into a recurrence. The breakthrough comes from imposing structure on the state matrix. Early methods like S4 use a normal plus low-rank matrix initialized via HiPPO theory to preserve historical information over long horizons. More recent selective variants like Mamba make the input and transition matrices input-dependent, allowing the model to selectively remember or forget tokens. Because the recurrence is linear, training can be parallelized using convolution across the sequence, while inference proceeds autoregressively like an RNN.

WHEN TO USE IT: Reach for an SSM when sequence length explodes beyond what fits in accelerator memory with dense attention. Genomics with hundreds of thousands of tokens, raw audio generation at high sample rates, and long-form video modeling are prime candidates. They are also valuable when you need fast autoregressive generation without a key-value cache that grows with every token.

WHEN NOT TO USE IT: Avoid SSMs for short sequences or tasks requiring fine-grained pairwise token comparisons, such as precise syntactic alignment or complex retrieval patterns where exact attention weights matter. The ecosystem is also less mature than Transformers, meaning fewer pretrained checkpoints and less tooling.

ONE CANONICAL EXAMPLE: Mamba demonstrates the selective state-space approach by letting each input token dynamically control the discretization step and the transition matrices across hidden channels. On long-range arena tasks and DNA modeling with context lengths reaching one million tokens, it achieves throughput and memory efficiency that dense attention cannot match without aggressive approximation.

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.