Skip to content
The Daily Triptych215 / 365
Cost versus sequence length

Quadratic growth typical of full attention contrasted with the linear trend of a structured state-space layer as sequence length increases. Vertical scale is relative compute, not a measured benchmark.

II · THE IDEA · ARTIFICIAL INTELLIGENCE

State Space Models for Long Sequences

architectures · arXiv 2111.00396 · structured state spaces (S4) · long sequence modelling

▶ Listen · narrated

Attention grows expensive as context lengthens. A structured state-space layer offers another path: long-range memory through linear-time recurrence and an equivalent convolutional form for training.

At a glance

Core idea
A continuous-time state space turned into a discrete sequence layer
Two views
Same model as linear recurrence or as a global convolution
Scaling
Linear in sequence length for both training and inference paths
Structure
Constrained state matrices make long kernels tractable
Target
Long-range dependencies without quadratic attention cost

Think of a notebook with a fixed number of pages. Each time a new word arrives, you update those pages by a simple rule, then write down a summary line. You never rescan the whole book—only the notebook—so the work per word stays roughly constant even if the story is huge.

That notebook is the state. Structured state-space models define the update rule with ideas borrowed from control and signal processing: a hidden state changes smoothly under a matrix, driven by the input, and an output is read from the state. For computers, the continuous rule is turned into discrete steps that match token sequences.

Because the rule is linear and does not change with time, two shortcuts appear. You can apply it one token after another (the recurrence), which is handy when generating text. Or you can precompute how a single impulse would echo through the system and apply that echo pattern to the whole sequence at once (the convolution), which is handy when training on long passages in parallel. Structure on the state matrix keeps those computations affordable when sequences get very long.

Unlike attention, the model is not comparing every word to every other word. It is compressing the past into the notebook and letting the notebook’s dynamics decide what survives.

Look closer

  1. One system, two algorithms

    The underlying object is a linear state-space model: a hidden state evolves under a matrix A driven by the input, and an output is read out from that state. After discretisation, the same dynamics can be unrolled step by step as a recurrence, which is natural at generation time, or collapsed into a single convolutional kernel over the whole sequence, which suits parallel training. The mathematics is shared; only the evaluation order changes.

  2. Why the state matrix must be structured

    A naïve state-space layer on long sequences is still too costly if the state transition is a dense unstructured matrix. Structured parameterisations keep the continuous-time system expressive enough to remember distant signals while making the discrete kernel computable in near-linear time. Without that structure, the convolutional view loses its practical advantage over attention.

  3. Memory lives in the kernel, not in pairwise scores

    In attention, every position re-scores every other position. In a structured state-space layer, long-range influence is carried by the impulse response of the discretised system—the convolutional kernel—whose shape is determined by A, B and C. Distant tokens interact because the state was designed to retain them, not because a separate weight was learned for each pair.

The story

Sequence models face a stubborn tension. You want each new token to be able to depend on a long history, yet you also want training and inference to remain affordable as that history grows. Self-attention resolves the first demand directly—every position may look at every earlier one—but pays for it with cost and memory that grow quadratically with length. Recurrent networks keep cost linear, yet standard forms struggle to carry information across thousands of steps, and their step-by-step nature is awkward for modern parallel hardware during training.

Structured state-space models attack the same tension from a different tradition: continuous-time linear systems. In that setting a hidden state evolves under a differential equation driven by the input signal, and a linear map produces the output. The continuous system is then discretised so that it can consume a token sequence. Once discrete, two computationally useful identities appear. Unrolling the update gives a recurrence whose cost per step is independent of total length, which is attractive when producing tokens one by one. Expanding the same recurrence gives an explicit convolutional kernel; applying that kernel to the full input can be done with fast convolution, so training need not step through time.

The practical difficulty is that a generic state transition does not yield a cheap kernel when sequences are long and the state is wide. The structured state-space approach therefore restricts the continuous transition matrix to families that remain expressive—especially for retaining information over long horizons—while admitting stable, efficient algorithms for the discrete kernel. The layer that results can be dropped into deep networks much as a convolution or attention block would be, but its asymptotic behaviour with length follows the linear recurrence and convolution path rather than pairwise attention.

What you give up is the content-dependent routing that attention provides at every layer: the state-space kernel is linear and time-invariant in its basic form, so which past signals survive is governed by the learned system dynamics rather than by a fresh similarity score between every pair of positions. What you gain is a route to very long context in which the dominant costs scale with length rather than its square, and in which the same learned parameters serve both the recurrent and the convolutional implementations. The design is less a replacement for every attention layer than a distinct inductive bias: history compressed through a structured dynamical state, readable either online or in batch.

Why it mattered then

When structured state spaces were proposed for deep sequence modelling, the field had clear evidence that many tasks needed far longer context than ordinary recurrent nets handled reliably, while full attention on those lengths was already straining memory and compute. Benchmarks built around long-range dependencies made the gap visible: models either truncated history, paid quadratic cost, or failed to propagate signals across the full span. A layer that could be trained as a convolution yet run as a linear-time recurrence offered a concrete architectural alternative at the moment when sequence lengths in language, audio and other modalities were being pushed hard against hardware limits. It reframed long memory as a systems-identification problem—design a state that retains what matters—rather than only as a sparse or approximate attention problem.

Why it matters now

Context windows have continued to grow, and with them the bill for quadratic attention. Linear-time and sub-quadratic sequence layers therefore remain central to anyone training or serving models on long documents, high-rate sensor streams or multi-modal timelines. Structured state-space ideas, and the broader family of models they helped popularise, matter because they keep an explicit, inspectable notion of state: a fixed-size summary updated by each new input, paired with a convolutional view that hardware can train efficiently. Even where practitioners mix these layers with attention rather than discarding attention entirely, the lesson stands—long-range capacity need not always be bought with pairwise scores at every depth. Understanding the recurrence–convolution duality also clarifies later variants and hybrids that show up in open-weight stacks aimed at long context on limited hardware.

The surprising detail

The same learned parameters define both a step-by-step recurrent filter and a single global convolutional kernel. Training can use the convolutional form for parallelism; deployment can switch to the recurrent form without re-learning weights. That duality is not an implementation trick bolted on afterwards—it is a direct consequence of discretising a linear time-invariant state space. The modelling choice (a linear dynamical system) and the systems choice (two evaluation orders) are the same fact viewed twice.

What is disputed

The source material for this lesson is the structured state-space sequence model line of work centred on efficient long-sequence modelling with recurrent and convolutional dual forms. Specific benchmark scores, later model variants, and comparisons to subsequent architectures are outside the facts used here and should not be read into the prose. The second listed paper concerns numerical methods for diffusion models and is not relied on for the claims above.

Remember this

A structured state-space layer stores history in a dynamical state that can be read either as a linear recurrence or as one convolutional kernel—long range at linear cost, without pairwise attention.

Test yourself

You must train on sequences of tens of thousands of steps and then generate token-by-token with a small memory budget. In the basic structured state-space setup, which computational form do you want during training, which during generation, and what has to be true of the layer for those two forms to stay equivalent?

Go deeper

Image: Original diagram, The Daily Triptych. Licence: Original work. Source.

← Back to day 215