S4: Efficiently Modeling Long Sequences with Structured State Spaces
A linear state space layer that keeps 64 numbers of state per channel and solved a 16,384-step task every earlier model failed.
The layer is a linear differential equation from control theory. The paper's contribution is an algorithm that builds a convolution kernel as long as the input sequence without ever raising the state matrix to a power.
Explaining the paperEfficiently Modeling Long Sequences with Structured State SpacesPath-X hands a model 16,384 pixels one at a time and asks whether two circles in the picture are joined by a path. Every model benchmarked on it before S4 scored 50%, the rate of guessing. S4 scored 96.35%.
Path-X is the hardest task in the Long Range Arena benchmark (Tay et al., 2020). The input is a 128×128 black-and-white image with two small circles and a tangle of dashed curves, and the label says whether one curve connects the circles. A convolutional network handed the 2-D image would find this easy. The benchmark does not hand over the image: it flattens it row by row into a sequence of 16,384 pixel values and feeds the model one value per position, so any 2-D structure has to be recovered from the sequence.
Flattening makes the task long. Two pixels directly above and below each other in the picture sit 128 positions apart in the sequence, and the two circles can be thousands of positions apart. Drag the teal circle in the figure and the strip below the picture shows the gap in tokens; one step down in the picture costs a full row.
The paper by Gu, Goel and Ré is mostly a numerical linear algebra paper. It takes the state space model, which control engineers have used since the 1960s, observes that nobody could compute it fast enough to train as a deep learning layer, and spends most of its length on an algorithm that does. That algorithm, and the initialization it was built to make affordable, are the starting point of the state space family that includes Mamba and Mamba-2.
The page follows the paper's order: what a state space model computes, how a step size turns it into a recurrence, which state matrix makes it remember long histories, why that matrix defeats the standard speed-up, the decomposition and algorithm that get around it, and then the layer, its cost, and the results.
Why sequence length is the hard part
To relate a token to one 16,000 positions earlier, the two standard architectures each have a problem. Attention scores every position against every other, so any token can read any earlier token directly, at any distance. The cost is scores per head per layer. At that is 268,435,456 scores, and a matrix of that size to store. FlashAttention later removed the storage by never materializing the matrix; the 268 million multiply-adds remain. The efficient-Transformer variants in Long Range Arena approximate the quadratic term with sparsity or low-rank structure. All of them scored 50.00 on Path-X, some because they ran out of memory or compute and some because they trained and did not learn the task.
A recurrent network carries a fixed-size hidden state forward and does a constant amount of work per step, so memory does not grow with length. For an input at step 1 to affect the output at step 16,000, its signal has to pass through 16,000 applications of the recurrent update, and the gradient back to it is a product of 16,000 Jacobians. A product that long either shrinks toward zero or blows up unless every factor stays very close to norm one, which is the vanishing and exploding gradient problem.
S4 is a recurrence too, but a linear one whose state matrix is chosen so that the decay over many steps is slow and controlled, and whose linearity lets the whole recurrence be computed as one convolution during training.
How a state space model works
The state space model is two equations:
is a scalar input signal that changes over continuous time. is a vector of numbers, the state. is a scalar output. The first equation gives the rate of change of each state coordinate: a linear combination of the current state through the matrix , plus the current input scaled by the vector . The second reads the output off the state with the vector , plus a direct copy of the input scaled by the number .
In control theory a state is a sufficient summary of the past: given and the inputs after time , the earlier inputs are never needed again. The numbers are therefore neither a window over recent inputs nor a cache of them. They are a fixed-size compression of the entire history, and the model can only use what survives the compression. S4 sets for the Long Range Arena experiments.
bypasses the state, so the paper sets in the exposition and treats it as a skip connection. The released code adds it back as a trained per-channel parameter.
Two properties of (1) drive the rest of the paper. It is linear: the response to the sum of two inputs is the sum of the two responses, because nothing in the equations is a gate, a , or any other nonlinearity. And it is time-invariant: do not depend on or on the input, so a spike at step 10 produces the same response as a spike at step 5,000, shifted by 4,990 steps. A system with both properties is called linear time-invariant, or LTI.
An LTI system computes a convolution. Write the input as a sum of single spikes, one per time step, each scaled by the input value there. By linearity the output is the sum of the responses to the individual spikes. By time-invariance each of those responses is one fixed shape, shifted to the spike's position and scaled by its value. Adding up shifted, scaled copies of one shape is convolution with that shape, which signal processing calls the impulse response.
To compute it, turn the ODE into a recurrence over discrete steps (the next section derives ) and unroll it from a zero initial state:
The bars mark discretized quantities. Each entry is a row times an matrix power times an column, so it is a single number, and is a filter of numbers, as long as the sequence. Feed in a 1 followed by zeros and the output is itself.
No approximation happens between (3) and (4). With the initial state at zero, which the paper assumes and the code does, the recurrence and the convolution compute the same function. S4 uses both: during training the whole sequence is available, so it computes all outputs at once with the convolution; during generation the next input does not exist yet, so it runs the recurrence at a fixed cost per token. The figure runs a two-state system both ways. Switch between the recurrent and convolutional views and compare the output rows digit by digit.
The smallest version can be computed by hand, with the HiPPO matrix introduced two sections below. Take , step size , and a readout that takes the first state coordinate:
The discretization formula of the next section gives
Since , the output is the first coordinate, whose update is , so the kernel is the geometric sequence :
Feed it the pulse . Unrolling the recurrence, convolving directly, or convolving by FFT all give
While the pulse is on, the output climbs toward 1; after it ends, the output falls by a factor of 3 per step. This is a leaky running average of recent input. At and , computing this way would mean 16,383 multiplications by a 64×64 matrix, which is the problem the rest of the paper solves.
Discretization and the step size Δ
Equation (1) is written in continuous time, and a sequence model receives . The bridge is one number, the step size , which says how much continuous time passes between consecutive tokens: . The data does not determine , so S4 learns it, one value per channel.
The simplest discretization is forward Euler, which replaces the derivative with a finite difference:
S4 uses the bilinear transform (Tustin, 1947) instead, which averages the derivative at both ends of the step, as the trapezoidal rule does:
This display carries the same number as the recurrence above because the paper prints them together as one equation group. The factor is a forward half-step, and the inverse is a backward half-step.
Why not Euler? Both discretizations are rational functions of , so each eigenvalue of maps to an eigenvalue of by the same scalar formula:
A continuous system is stable when every eigenvalue has negative real part. A discrete recurrence is stable when every eigenvalue of has magnitude below 1; otherwise that mode is multiplied by more than 1 at every step and grows without bound. The bilinear map sends the whole left half-plane into the open unit disk, for every . Euler sends to , which leaves the disk once .
The HiPPO matrix of the next section has eigenvalues exactly . At and , the top of S4's initialization range, Euler sends to ; that mode is multiplied by 5.4 per token, about over 1,000 tokens. The bilinear transform sends it to . At the small end, with goes to 0.9048. In the figure, the shaded band is the stable region. Sweep and switch : the amber Euler points fall out of the band once passes , while the teal bilinear points stay inside at every setting.
Besides stability, sets how far back the layer looks. The slowest mode of the HiPPO matrix has , and the bilinear map sends it to approximately , so it decays by a factor of over about tokens. The released code initializes one per channel, drawn log-uniformly from , which spreads those horizons from about 10 to about 1,000 tokens across the channels of a single layer.
The continuous-time view also explains a Speech Commands result. The dataset is recorded at 16 kHz. An S4 model trained at that rate scores 96.30% on test audio resampled to 8 kHz, with no retraining, after its is doubled. Halving the sample rate doubles the real time between samples, and doubling makes the discretization use that spacing, while the learned describe the same continuous system as before. The rescale is manual: someone has to know the new sample rate and change .
The HiPPO matrix
Everything so far holds for any , and most choices of train badly. The LSSL, the paper's immediate predecessor, reports 62% on permuted MNIST with a random, suitably normalized , against 98.76% with the matrix below.
That matrix comes from HiPPO (Gu et al., 2020), which asked a different question: with a budget of numbers, what is the best summary of a signal's history, and can it be updated online as new input arrives? HiPPO's answer is a running least-squares polynomial approximation. Keep the coefficients of the best polynomial approximation of the history so far, in an orthogonal polynomial basis. HiPPO proves that those coefficients obey a linear ODE, so they can be updated by integrating the ODE instead of refitting. For the scaled Legendre measure (LegS) the matrix is:
The square roots normalize the Legendre polynomials. The lower-triangular shape means coefficient is driven by the lower-degree coefficients . The diagonal entry is the decay rate of coefficient , so higher-degree coefficients, which carry finer detail, decay faster. Because the matrix is triangular its eigenvalues are its diagonal entries, , the eigenvalues used in Figure 3.
S4 changes one thing about how HiPPO uses this matrix, and the change alters what the state remembers. HiPPO's LegS system is time-varying. Written with the and of (2), it is
where the stretches the approximation window as time passes, so the coefficients always summarize the whole history from 0 to with uniform weight. S4 keeps the matrix and drops the , which gives back equation (1) with a constant : the system becomes time-invariant, which is what the convolution requires. Run equation (2) as a fixed linear system and its impulse response has a closed form,
where is the degree- Legendre polynomial. Its argument is , not : the time-invariant system fits polynomials to the past in a warped time variable in which recent history is stretched out and receives most of the resolution, and distant history is squeezed toward zero. The memory fades smoothly with age instead of weighting all of history equally. The S4 paper does not discuss the change; the closed form was worked out in the follow-up paper How to Train Your HiPPO.
The figure draws the input history on that warped axis, with "now" at the right edge and older input compressed toward the left. Raise from 1 and watch which part of the history the reconstruction resolves first.
The matrix also never amplifies the state, even briefly. Let , the same vector as . The symmetric part of (2) is
and a symmetric part bounded by gives for every . The norm of the state falls monotonically from any starting point. Many non-normal matrices first amplify the state by a large factor before it decays, which wrecks a recurrence in floating point; this one cannot. The vector returns two sections below as the low-rank part of the decomposition.
Why diagonalizing the HiPPO matrix fails
Building from (5) directly takes successive multiplications by an matrix: operations, and memory to keep the intermediate states for backpropagation. The LSSL used , and at that size it needed orders of magnitude more memory than an RNN or CNN of similar size, which kept it from being run at the sizes it needed.
The textbook speed-up is diagonalization. If with diagonal, then , and a power of a diagonal matrix is scalar powers. The change of basis costs nothing in the model. The paper's Lemma 3.1 states that
compute the same map from to , because in every pair cancels.
Equation (2) is diagonalizable. Its eigenvalues are real and distinct, distinct eigenvalues guarantee a full set of independent eigenvectors, and Lemma 3.2 even gives the eigenvector matrix in closed form, .
In floating point it fails anyway. The eigenvectors are independent but nearly parallel, so is badly ill-conditioned: writing an ordinary vector in that basis takes huge coordinates of opposite sign that nearly cancel, and float64 keeps about 16 significant digits, so the cancellation destroys the result. Lemma 3.2 bounds the entries of by , about at . The condition number of , which we computed in 260-digit arithmetic because float64 cannot measure it, is about at , at , at , and at . A condition number of means about 158 bits of precision are needed to diagonalize at S4's size, and float64 has 53.
Nothing overflows, the matrix is not defective, and the eigenvalues stay exact at every ; only the computed eigenvectors lose relative precision. The figure's meter shows it directly: it takes the left matrix apart into its exactly known eigenvalues and eigenvectors, multiplies them back together in float64, and reports the relative error. Move up and watch the error pass 100% at about .
The matrices that diagonalize safely form a known class. A matrix is normal when it commutes with its conjugate transpose, . The spectral theorem says a matrix can be diagonalized by a unitary (a rotation, with condition number 1, so nothing is lost to rounding) exactly when it is normal. Symmetric and skew-symmetric matrices are normal; equation (2) is not, and the figure's "not normal" readout measures by how much.
Normal plus low-rank
Requiring to be normal would rule out the HiPPO matrix. The paper asks for less: a normal matrix plus a low-rank correction. It calls this form NPLR, normal plus low-rank. After the unitary change of basis that diagonalizes the normal part it becomes DPLR, diagonal plus low-rank, which is the form S4 stores:
For the HiPPO matrix the correction has rank one, and the decomposition is exact. With , add to equation (2) and check the three kinds of entry. Above the diagonal, where is zero, the sum is half the outer-product entry, . Below the diagonal it is
which is the mirror entry with the opposite sign. On the diagonal it is in every row. So
A skew-symmetric matrix has purely imaginary eigenvalues and is normal, and adding a multiple of the identity keeps it normal and shifts every eigenvalue by that multiple. Every eigenvalue of the corrected matrix is therefore for some real . At they are , , and . All modes of the normal part decay at the same rate and differ only in how fast they oscillate. In the DPLR basis, holds these eigenvalues on its diagonal, and the original eigenvalues are recovered only once the rank-one term is subtracted back.
The trainable parameters of one S4 channel are , five complex vectors of length , which the paper counts as parameters. The released code differs in ways that matter when reading it: is tied to (the form from the SaShiMi paper), only one member of each complex conjugate pair is stored, and and are trained as well, outside the . The kernel is never a parameter; it is recomputed from these vectors on every forward pass. At Path-X scale, with channels, roughly 66,000 stored numbers generate a filter bank, 4,194,304 taps.
How S4 computes the kernel
Storing does not by itself make (5) cheap, because powers of a diagonal-plus-rank-one matrix do not stay diagonal plus rank one. Expand the square:
The part that is not has columns in the span of and , so it has rank two. In general the off-diagonal part of the -th power lives in the span of , so its rank grows by one per multiplication until it reaches and the matrix is effectively dense again. The paper puts it as "powering up this sum is still slow".
Inverses behave the opposite way. The Woodbury identity says that a rank- change to a matrix changes its inverse by rank , and the only new inverse needed is :
At the inner inverse is one scalar division. The figure computes both in float64 on an 8×8 example, with a real scalar : singular values of the off-diagonal part of on the left, and of the off-diagonal part of on the right. Step up and one more singular value rises above the rounding floor each time; move and the right panel keeps a single bar.
So S4 rewrites the kernel in terms of an inverse, using a generating function: put the kernel values into the coefficients of a polynomial in and evaluate the polynomial instead of computing the coefficients:
The right side is the finite geometric series, equal to , with the matrix in place of , valid wherever the inverse exists. The powers of have become one inverse and one fixed power . Two choices make the right side cheap to evaluate.
First, evaluate at the -th roots of unity, . At those points the values of are exactly the discrete Fourier transform of , so one inverse FFT recovers the kernel values with nothing lost. Also at those points , so the factor becomes the constant and can be absorbed into the output vector once:
S4 learns directly and never computes .
Second, expand the remaining inverse with Woodbury. With , the bilinear , and the substitution
the generating function at each root of unity reduces to
All four bracketed quantities have the form , and since is diagonal, each one is a sum of divisions:
Evaluating such a sum at points is multiplication by a Cauchy matrix, the matrix with entries , and numerical analysis has fast, stable algorithms for it. That is Theorem 3: the kernel reduces to four Cauchy multiplies, operations and memory, against and for the direct computation.
The divisions are also numerically safe. For on the unit circle, the node is , purely imaginary, and every has real part . So and no denominator comes near zero.
The whole algorithm, in NumPy:
# Algorithm 1: the length-L kernel from N diagonal poles plus a rank-one term.
# Lam, P, B, Ct are complex vectors of length N. Ct is the learned C-tilde.
z = np.exp(-2j * np.pi * np.arange(L) / L) # L-th roots of unity (minus sign)
s = (2 / dt) * (1 - z) / (1 + z) # bilinear image: purely imaginary
def cauchy(v): # sum_j v_j / (s - Lam_j), every s
return (v[None, :] / (s[:, None] - Lam[None, :])).sum(-1)
k00 = cauchy(Ct.conj() * B) # the four Cauchy sums
k01 = cauchy(Ct.conj() * P)
k10 = cauchy(P.conj() * B) # released code ties Q = P
k11 = cauchy(P.conj() * P)
Khat = 2 / (1 + z) * (k00 - k01 / (1 + k11) * k10) # Woodbury: one divide
K = np.fft.ifft(Khat).real # length-L kernel, time domainAlgorithm 1 prints the roots of unity as ; paired with its own inverse FFT that returns the kernel reversed in time, a filter that looks at the future. Lemma C.2 and the released code use , as above. And when is even, one node is , where divides by zero. The singularity is removable: goes to infinity there, the resolvent shrinks at the same rate, and the limit is , so that node keeps a finite value.
The of Theorem 3 assumes a fast-multipole Cauchy algorithm. Appendix A says those algorithms were not implemented for GPUs, and the release computes the Cauchy sums directly in time, with memory because the matrix is never stored. At that is a modest cost, and it is paid once per batch, since the kernel does not depend on the input.
The figure runs the listing above in the browser, on the HiPPO initialization at . The left panel is the resulting kernel; the right panel shows the 64 diagonal entries of after the bilinear map, the poles of the four Cauchy sums. Drag across the initialization range and past both ends. At small the kernel stretches over more than a thousand taps and the poles bunch near ; at large they spread around the circle and the kernel becomes a short, jagged burst. The poles stay strictly inside the circle at every .
The recurrent view needs the same structure. Appendix C.2 writes the bilinear as a product of two factors: the forward half-step , which is diagonal plus rank one, and the backward half-step , which Woodbury also turns into diagonal plus rank one. Multiplying a vector by each factor costs , so one generation step costs (Theorem 2). The readout during generation has to use , not the learned , which contains the factor meant only for the convolution. Recover it once by solving the definition of for , an linear system. The factor is far from the identity: at , , , the norm of is about 0.60.
# generation: the same parameters, run as a recurrence
AbarL = matrix_power(Abar, L) # once, before generating
C = solve((I - AbarL).conj().T, Ct) # undo C-tilde = (I - Abar^L)^* C
x = zeros(N, complex) # the whole memory of the past: N numbers
for u_k in stream:
x = Abar @ x + Bbar * u_k # O(N): Abar is a product of two DPLR factors
y_k = (C.conj() @ x).real + D * u_kThe S4 layer and its cost
One SSM maps a scalar sequence to a scalar sequence, and a network layer has to transform features per position. S4 runs independent SSMs, one per channel, each with its own parameters and its own ; mixes the channels with a position-wise linear layer; and applies a nonlinearity. This is the structure of a depthwise-separable convolution, one filter per channel followed by a convolution across channels, and the code builds the mixer as a kernel-size-1 Conv1d.
S4's per-channel filters differ from a CNN's in three ways. They are as long as the sequence. They are generated from about numbers per channel instead of stored tap by tap, so the parameter count does not grow with , and the same parameters can produce the filter at a different length or a different . And each filter has an equivalent recurrence, which a CNN filter does not.
The state update has no gate. In nothing depends on the input, so one fixed kernel can represent the layer. All of a deep S4 network's nonlinearity sits between SSM layers. Later S4 blocks add a GLU after the channel mixer, still outside the SSM. Mamba removes exactly this property: it makes the SSM's parameters depend on the input.
The convolution runs through FFTs, and the FFT computes a circular convolution, in which the end of the output wraps around and adds onto the beginning. Take and . The linear convolution is . The length-2 circular convolution is : the 8 wrapped around onto the 3. Zero-padding both signals to at least before the transform and keeping the first outputs gives the linear result; the code pads to . Without the padding, each early output picks up contributions from inputs near the end of the sequence, an error as large as the signal itself. Here is one layer on a Path-X batch, with shapes:
# one S4 layer on a Path-X batch: B=32 sequences, H=256 channels, L=16384
u = x.transpose(1, 2) # (32, 256, 16384) one scalar signal per channel
K = kernel(Lam, P, B, Ct, dt, L) # (256, 16384) one length-L filter per channel
U_f = rfft(u, n=2*L) # zero-pad to 2L: FFT convolution is circular
K_f = rfft(K, n=2*L)
y = irfft(U_f * K_f, n=2*L)[..., :L] + D[:, None] * u # (32, 256, 16384)
y = gelu(y)
out = W_mix @ y # (256 x 256) position-wise mix, a 1x1 convThe gradient flows through every line of that listing and through Algorithm 1 into and , plus and the mixer weights.
On cost: attention grows with the square of the length. The naive SSM was already linear in , so linearity was not S4's contribution. S4 removed the factor on the work and the of stored states. Slide the length in the figure and the three curves separate; switch to memory to see the naive SSM's problem.
Two qualifications on that chart. Training compute for S4 is because of the FFT; only memory and the per-token generation cost are linear and constant. And the paper's complexity table (Table 1) leaves out the channel mixer, which costs and is the larger of S4's two terms at realistic widths. At , , :
Against the LSSL at layer width 512, S4 takes 29.6× less time per training step and 392× less memory (the introduction rounds these to 30× and 400×). Against efficient Transformers, parameter-matched at length 4,096 on one A100, S4 runs 5.19× as fast as a vanilla Transformer on 9.1% of its memory, in the same range as the Performer (3.79×, 8.6%) and the Linear Transformer (5.35×, 6.7%).
Results
On Long Range Arena, S4 has the best score on all six tasks and averages 86.09%; every baseline averages under 60%, the best being Luna-256 at 59.37%. On Path-X the baselines are at 50.00, the score of a coin flip, and S4 is at 96.35. Pick a task in the figure to see the full column.
The paper is inconsistent about the 86.09. Section 4.2 still says 80.48%, the average from the first arXiv version; Table 4 reports 86.09; and the appendix table prints both rows. Appendix D.5 explains that the table was refreshed with results from the S4D and How to Train Your HiPPO follow-ups, for the same model with minor hyperparameter changes, and asks readers to read it before citing. The Path-X change behind 88.10 to 96.35 is the range, lowered from to . By the horizon estimate above, the slowest mode at keeps of its value across all 16,384 tokens, while at it keeps about . That calculation is our reading of why the change helps; the paper reports only the change and the score.
The other experiments test generality across data types:
- Raw speech (Speech Commands, 10 classes, 16,000-sample waveforms with no feature extraction): 98.32%, higher than every baseline that was given MFCC features, which are 100× shorter. A specialized audio CNN, the paper's improved WaveGAN discriminator, gets 96.25% with 26.3M parameters, almost 90× S4's 0.3M.
- Sequential CIFAR-10 (one pixel at a time, no 2-D structure): 91.13%, competitive with a 2-D ResNet-18 that has more parameters (11.0M against S4's 7.9M).
- CIFAR-10 density estimation: 2.85 bits per dimension with no 2-D bias, equal to PixelSNAIL, which uses 2-D convolutions and attention.
- WikiText-103 language modeling: 20.95 test perplexity at 249M parameters, against 20.51 for a 247M Transformer. S4 does not win here, and the paper describes the result as closing the gap. It is the best attention-free result by more than 2 perplexity (TaLK Convolution is next at 23.3). The prose says "within 0.8 ppl", which refers to an earlier run at 21.28; the retrained model's gap is 0.44.
The recurrent view makes generation fast. A Transformer producing token attends over all earlier tokens, so each token costs more than the last; S4 updates an -number state per channel at the same cost for every token. On WikiText-103 that gives 48,000 tokens per second against 800, a 60× speedup. On CIFAR the speedup ranges from 65.1× for the base model down to 10.5× for the large 2.85-bpd model. These are throughputs at the largest batch that fits on one A100, not single-sequence latency.
The ablation, S4D and Mamba
Section 4.4 asks which part of S4 produces the results, on sequential CIFAR-10 with models of at most 100K parameters. Random matrices in S4's NPLR form perform poorly. Training improves every initialization, and with trained every initialization reaches perfect training accuracy, yet their validation accuracies differ by more than 15 points. The models share a parameter count and an optimizer, so the starting matrix alone moves validation accuracy by that much. With 0.1 dropout added, the same trends hold, and full S4 with the HiPPO initialization reaches 84.27% test accuracy with 100K parameters. The paper concludes that the gains come mainly from the HiPPO initialization, not from the NPLR parameterization; NPLR makes that initialization affordable to compute.
Follow-up work simplified the parameterization within months. DSS (Gupta et al., 2022) and then S4D (Gu et al., 2022) dropped the low-rank term and kept only a diagonal initialized from the HiPPO spectrum, and landed within about a point of S4 on the LRA average. A diagonal state matrix turns the kernel into a Vandermonde product and removes the Woodbury correction, the Cauchy sums, and most of Appendix C. The simplification costs something on the longest task: S4D-LegS averages 84.89 against S4's 86.09 and trails by 4.4 points on Path-X (91.95 against 96.35), and S4D-Lin, whose eigenvalues have linearly spaced imaginary parts, fails Path-X outright.
The larger change went the other way. Everything in this paper depends on time-invariance: the same at every position, so one kernel represents the layer and one FFT computes it. A filter that applies the same weights at every position cannot down-weight one token or retain another based on its content, which is a plausible reason S4 trails Transformers on language. Mamba makes , and functions of the input. With parameters that change at every token there is no single kernel to FFT, so Mamba replaces the convolution with a hardware-aware parallel scan, and it discretizes with the exact exponential instead of the bilinear transform. Mamba-2 restricts the state matrix to a scalar times the identity so the scan can be computed with matrix multiplications, and Mamba-3 brings back a trapezoid-rule discretization of the input term.
Questions you might still have
If the recurrence and the convolution give the same numbers, why keep both?
They cost differently. The convolution computes all L outputs in one pass with FFTs, which suits training, when the whole sequence is in hand. The recurrence produces one output at a time from an N-number state at constant cost, which suits generation, when the next token does not exist yet. The parameters are shared; only the schedule differs. For generation the readout uses C-bar, recovered once from the learned C-tilde.
Why the bilinear transform and not forward Euler?
Forward Euler maps an eigenvalue λ of A to 1 + Δλ. The HiPPO matrix has eigenvalues −1 to −N, so Euler is unstable once Δ exceeds 2/N, which at N = 64 is 0.031, inside S4's initialization range of 0.001 to 0.1. At Δ = 0.1 the fastest mode would be multiplied by 5.4 per token. The bilinear transform maps every eigenvalue with negative real part inside the unit circle at any Δ. Mamba later used the exact exponential exp(ΔA), which is also stable at any Δ.
Does S4 have a gate, like an LSTM or Mamba?
No. The state update is linear and its parameters do not depend on the input, which is what lets a single fixed kernel represent the layer. Later S4 blocks put a GLU after the channel mixer, outside the state space model. Input-dependent parameters are Mamba's change, and they remove the convolutional view.
What exactly gets trained?
Per channel: the diagonal Λ, the low-rank vector P (Q is tied to P in the released code), B, the convolution readout C-tilde, the step size Δ, and the skip weight D; plus the position-wise mixing weights between channels. The length-L kernel is recomputed from these on every forward pass, and gradients flow back through the Cauchy sums, the Woodbury correction and the inverse FFT.
Was all the low-rank machinery necessary?
Less than it seemed in 2021. DSS and S4D dropped the low-rank term and kept a diagonal state matrix, landing within about a point on the Long Range Arena average and replacing the Cauchy kernel with a Vandermonde product. The paper's own ablation pointed the same way: random matrices in NPLR form still did poorly, so the HiPPO initialization carried the result. The remaining gap is on Path-X, where S4D-LegS trails by 4.4 points (91.95 against 96.35) and the linearly spaced diagonal initialization does not solve the task.
Why does the paper quote 80.48% on Long Range Arena when its table says 86.09%?
The 80.48% in Section 4.2 is left over from the first arXiv version. Table 4 was refreshed for v3 with results from the S4D and How to Train Your HiPPO follow-ups, same model with minor hyperparameter changes, and the appendix table prints both rows. The paper asks readers to see Appendix D.5 before citing the table. The current figure is 86.09.
How can 64 numbers of state cover 16,000 steps?
The state holds coefficients of a polynomial approximation of the past, in a time variable that gives recent history most of the resolution and compresses older history. Fine detail from thousands of steps back is lost; the coarse shape survives. With Δ around 0.0001, the slowest mode still keeps about 19% of its value after 16,384 tokens, so information from the start of the sequence still reaches the end. Each layer also runs H independent channels (256 on Path-X), each with its own state and Δ, and the model stacks several layers.
Footnotes & further reading
- The paper: Gu, Goel, Ré, Efficiently Modeling Long Sequences with Structured State Spaces (Stanford, ICLR 2022). Code. Equations, tables and numbers on this page are from the v3 arXiv source; code claims are from
models/s4/s4.pyandsrc/models/hippo/hippo.py. - The memory theory: Gu, Dao, Ermon, Rudra, Ré, HiPPO: Recurrent Memory with Optimal Polynomial Projections (2020), and its sequel How to Train Your HiPPO (2022), which works out the time-invariant version of HiPPO-LegS.
- The predecessor: Gu, Johnson, Goel, Saab, Dao, Rudra, Ré, Combining Recurrent, Convolutional, and Continuous-time Models with Linear State Space Layers (LSSL, 2021). The 62%-with-a-random-matrix figure is from its Section 5.4.
- The benchmark: Tay et al., Long Range Arena (2020). Path-X is the 128×128 version of Pathfinder. Tay et al. benchmarked eleven Transformer variants; Figure 9 shows the eight baselines the S4 paper carries into its LRA table (Table 4), three of which (FNet, Nyströmformer, Luna-256) postdate the benchmark paper.
- The simplifications: Gupta, Gu, Berant, Diagonal State Spaces are as Effective as Structured State Spaces (DSS, 2022), and Gu, Gupta, Goel, Ré, On the Parameterization and Initialization of Diagonal State Space Models (S4D, 2022), also the source of the refreshed LRA numbers and the Path-X step-size range.
- The parameterization the code uses: Goel, Gu, Donahue, Ré, It's Raw! Audio Generation with State-Space Models (SaShiMi, 2022), which introduced the Λ − PP* form.
- What came next: Mamba (Gu & Dao, 2023) makes the SSM parameters input-dependent and replaces the convolution with a parallel scan; Mamba-2 restricts the state matrix so the scan becomes matrix multiplication. The continuous-time framing connects to Neural ODEs, and the ODE-RNN baseline in the speech table comes from that line of work.
How could this explainer be improved? Found an error, or something unclear? I read every message.