Structured State Spaces: HiPPO & S4
Continuous-time memory, discretization and long convolution kernels.
S4 began as a question about memory: if a recurrent state must summarize an entire history in numbers, what is the best summary, and can it be kept up to date online? HiPPO's answer, project the history onto orthogonal polynomials, produces one specific matrix with remarkable properties. S4 made that matrix usable at scale by finding the right algebra for its convolution kernel. Then the field discovered how much of the machinery was really needed.
What you’ll learn
- Define the HiPPO online projection problem, state the HiPPO-LegS dynamics exactly, and prove its timescale equivariance.
- State HiPPO-LegS's guarantees (linear-time updates, gradients of order , approximation error that falls with smoothness) and explain what changes when the matrix is used in a time-invariant layer.
- Explain why the HiPPO matrix cannot be diagonalized in practice, and derive S4's kernel algorithm from the generating function, the Woodbury identity and Cauchy kernels.
- Explain why diagonal state matrices suffice (DSS, S4D), how and the initialization set the time scales, and what the linear recurrent unit showed about the ingredients that matter.
Memory as online function approximation
A recurrent state of numbers must summarize an unbounded history. HiPPO (Gu, Dao, Ermon, Rudra & Ré, 2020) turns "summarize" into a precise approximation problem, and solving that problem produces the state matrices that S4 later used.
| Measure | Dynamics | What it remembers |
|---|---|---|
| LegT: uniform on the window | time-invariant; and scale with | the last units of time; recovers the earlier Legendre Memory Unit |
| LagT: on | time-invariant | an exponentially fading past; with and an Euler step, , a leaky integrator, which becomes a gated RNN when depends on the input |
| LegS: uniform on | time-varying, scaled by | the whole history, with equal weight; no timescale hyperparameter |
With the only basis function is , so is the running mean of the input. Differentiating it gives the theorem with and . The higher coefficients follow from the same differentiation together with derivative identities of the Legendre polynomials.
Proposition (timescale equivariance). If for some , then . Proof. Each basis function on is a rescaling of one on , with . Substitute :
Speeding the input up or slowing it down only re-times the coefficients, so LegS needs no prior on the time scale of the data. Even its Euler discretization contains no step size:
A LegS memory with has read the input on . What is its state ?
Show the answer
C.
With one coefficient, LegS keeps the mean of the whole history under the uniform measure: . Higher coefficients add the history's linear, quadratic, … trends, measured against Legendre polynomials on .
What LegS guarantees, and what the time-invariant version means
Part (b) is the contrast that matters for learning. A mode of an LTI system, or a contracting RNN, passes gradient back with a factor like , exponentially small in the distance. LegS's gradient depends only on and shrinks polynomially, because every past moment keeps the same weight in the uniform measure. Part (c) says what buys: smoother histories compress better, and the error grows with because the same coefficients must cover a longer past.
From time-varying to time-invariant. The Linear State-Space Layer (LSSL; Gu, Johnson, Goel, Saab, Dao, Rudra & Ré, 2021) dropped the and used the HiPPO matrix as the constant of an LTI system with a learned step size. On sequential MNIST, replacing a random by the HiPPO matrix raised accuracy from 60% to 98%. Without the , however, the system no longer computes LegS projections, and for a while no one could say what it did compute. Gu, Johnson, Timalsina, Rudra and Ré (2023) answered: the time-invariant system projects the history onto Legendre polynomials under an exponentially warped time axis, and sets the length of the dependencies it captures.
Think first LegS is equivariant to time scale, yet S4 learns a step size for every channel. Why does a time-invariant layer need at all?
Time invariance and scale invariance conflict. LegS achieves scale invariance with the factor, which makes the system time-varying: its memory window grows with . A convolution requires fixed dynamics, and fixed dynamics have fixed time constants, , measured in units of the step . Learning , and spreading it across channels, restores a range of time scales that LegS got for free.
The S4 kernel: generating functions, Woodbury and Cauchy
An LTI layer of sequence length needs the kernel . Powering a dense matrix costs time and memory, which is what the LSSL paid. With a diagonal matrix the kernel would be a cheap Vandermonde product. But conjugating to diagonal form (, , leaves the input–output map unchanged) is numerically impossible for this matrix:
For , the largest entry of over is about . What is ?
Show the answer
25.3
The largest entry is about , consistent with the bound . Single-precision floats carry about 7 significant digits and double precision about 16, so products with such a matrix lose everything to rounding.
Evaluate the kernel's generating function at the -th roots of unity . The geometric series of matrices sums to a resolvent, and removes the dependence on from everything but a modified output vector :
With the bilinear discretization, the discrete resolvent becomes a continuous one at a point , as direct substitution of and shows:
For the Woodbury identity reduces the resolvent to the diagonal one, :
Every term is now a sum of the form below, a Cauchy kernel evaluated at the points : directly, with fast algorithms for Cauchy matrices. An inverse FFT of at the roots of unity returns .
With this kernel, S4 solved Path-X of the Long Range Arena (88% where every earlier model was at chance), reached 91% on pixel-by-pixel CIFAR-10 without data augmentation, and generated autoregressively about 60 times faster than a transformer in the paper's benchmark. Its own ablations pointed at the source: random NPLR matrices trained poorly, so the gains came from the HiPPO initialization, not from the NPLR parameterization.
Simpler is enough: diagonal SSMs, initialization and Δ
Gupta, Gu and Berant (2022) simply dropped the low-rank term and kept the diagonal part of LegS's normal component. The resulting diagonal state space (DSS) model matched S4 on the Long Range Arena. Gu, Gupta, Goel and Ré (2022) explained why: the diagonal restriction recovers S4's kernel in the limit of infinite state size. Their S4D computes its kernel in a few lines, as a Vandermonde product, and needs only a good initialization of the eigenvalues, for example
the first a damped Fourier basis and the second an approximation of LegS's diagonal. Mamba later used real eigenvalues, (S4D-Real), for text.
sets the time scales. With , a mode remembers for about steps. S4D initializes across channels in a range such as , so different channels start with memories from about 20 to about 2,000 steps; for Path-X the range was moved toward smaller , longer memories.
An S4D-Lin mode with runs with step . What percentage of its magnitude, , remains after steps?
Show the answer
8.2 %
, about 8%. The memory is steps to fall by a factor , so 500 steps is 2.5 memories. With the same mode would keep .
The view from recurrent networks. S5 (Smith, Warrington & Linderman, 2023) used one multi-input, multi-output diagonal SSM per layer and computed it with a parallel scan instead of a convolution. Orvieto et al. (2023) then started from a plain RNN and asked which changes close the gap to S4 on the Long Range Arena. Their linear recurrent unit keeps the recurrence linear and diagonal over ; writes each eigenvalue as , so that for every value of the trained parameters; initializes the eigenvalues uniformly on a ring just inside the unit circle, with radii up to about 0.99; and rescales the input of each mode. The rescaling follows from one line: for white-noise input, a mode with accumulates variance
which explodes as , so the input is multiplied by . With a small initial phase for Path-X, the linear recurrent unit matched S4, S4D and S5 on every task. The continuous-time derivation explains good initializations and the role of , but it is not needed to obtain them.
Key takeaways
- HiPPO maintains the optimal polynomial approximation of the input history under a chosen measure; for the uniform measure on (LegS) the coefficients obey with an explicit lower-triangular .
- LegS is equivariant to time scale, updates in , has gradients of order rather than exponentially small ones, and approximates smooth inputs with error falling in ; used as a constant matrix, it projects onto exponentially warped Legendre polynomials, with setting the time scale.
- The HiPPO matrix's eigenvectors are exponentially ill-conditioned, so S4 wrote it as normal plus rank one and computed the kernel through its generating function at roots of unity, the Woodbury identity and Cauchy kernels, in .
- Diagonal state matrices suffice when well initialized (DSS, S4D), sets each channel's memory, and a stable, normalized linear RNN (the LRU) matches S4: the essentials are linearity, eigenvalues near the unit circle and careful parameterization.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The same signal is played twice as fast: . How are the HiPPO-LegS coefficients of related to those of ?
- They are unrelated: the step size must be retuned
Show the answer
D.
Substituting turns into : by time the fast signal has played what the slow one plays by , and LegS sees the same history, compressed in time.
How does behave for HiPPO-LegS, for ?
- It decays exponentially in , like a vanilla RNN's gradient
- It is , independent of how far back lies
- It grows with , because the state accumulates the history
- It is exactly zero once exceeds a window length
Show the answer
B. It is , independent of how far back lies
Under the uniform measure on every past moment has weight , so the sensitivity to shrinks only polynomially with the current time and not with the lag. That is why LegS-based memories avoid the exponential vanishing of gradients.
Why did S4 not simply diagonalize the HiPPO matrix and compute its kernel as a Vandermonde product?
- Its eigenvector matrix has entries growing like , so the change of basis is numerically useless
- The HiPPO matrix has no eigenvalues
- A diagonal state matrix cannot produce a convolution kernel
- Diagonalization would change the input–output map of the layer
Show the answer
A. Its eigenvector matrix has entries growing like , so the change of basis is numerically useless
In exact arithmetic diagonalization is fine: conjugation leaves the layer's input–output map unchanged. But the eigenvectors are so badly conditioned that and cannot be computed accurately. S4 instead conjugated by a unitary matrix to a diagonal-plus-rank-one form.
Which conclusion is best supported by S4's ablations and the diagonal models that followed (DSS, S4D, LRU)?
- The normal-plus-low-rank parameterization is essential: without the low-rank term, SSMs fail on long-range tasks
- Any linear recurrence works on long-range tasks, whatever its initialization
- Initialization and parameterization of the eigenvalues matter most; diagonal state matrices suffice when initialized well
- Only continuous-time models can learn dependencies thousands of steps long
Show the answer
C. Initialization and parameterization of the eigenvalues matter most; diagonal state matrices suffice when initialized well
Random NPLR matrices trained poorly in S4's ablations, DSS and S4D matched S4 with diagonal matrices, and the linear recurrent unit matched them as a discrete-time linear RNN with a stable parameterization, an initialization near the unit circle and input normalization.
Further reading
- A. Gu, T. Dao, S. Ermon, A. Rudra & C. Ré, "HiPPO: Recurrent memory with optimal polynomial projections," NeurIPS (2020).
- A. Gu, K. Goel & C. Ré, "Efficiently modeling long sequences with structured state spaces," ICLR (2022).
- A. Gu, A. Gupta, K. Goel & C. Ré, "On the parameterization and initialization of diagonal state space models," NeurIPS (2022).
- A. Gu, I. Johnson, A. Timalsina, A. Rudra & C. Ré, "How to train your HiPPO: State space models with generalized orthogonal basis projections," ICLR (2023).
- J. T. H. Smith, A. Warrington & S. W. Linderman, "Simplified state space layers for sequence modeling," ICLR (2023).
- A. Orvieto, S. L. Smith, A. Gu, A. Fernando, C. Gulcehre, R. Pascanu & S. De, "Resurrecting recurrent neural networks for long sequences," ICML (2023).