36 · S4 — Structured State Space Sequence Model

SSM Sequence Model Gu et al. · 2021
arXiv:2111.00396

上一代的问题:RNNs have O(L) complexity but fixed-size memory (can't recall long-range). Transformers have O(L2) cost. SSMs existed but couldn't handle long-range dependencies — they either failed on the Copy task or needed prohibitively large state dimensions.

这代改了什么:S4 introduces the HiPPO theory for structured state matrices (Legendre polynomials) that capture long-range memory. Combined with Normal Plus Low-Rank (NPLR) decomposition for efficient computation. Shows that a properly parameterized SSM can match or exceed Transformers on long-range tasks.

效果:First SSM to achieve Transformer-level performance on Long Range Arena (LRA) benchmark. Average score 86.09 vs Transformer 62.05. Direct predecessor to Mamba.

一、核心背景

1.1 什么是 State Space Model

State Space Models (SSMs) originate from control theory. They model a system's dynamics through a latent state that evolves over time:

h'(t) = A · h(t) + B · x(t)
y(t) = C · h(t)
Continuous-time SSM: state evolution and observation equations

Where A is the state transition matrix (N x N), B is the input projection (N x 1), and C is the output projection (1 x N). The state h(t) is a vector that compresses the entire history of the input signal.

1.2 Discretization for Deep Learning

To use SSMs in a discrete deep learning setting, we discretize using the Zero-Order Hold (ZOH) method with step size Δt:

A_bar = exp(Δt · A)
B_bar = (exp(Δt · A) - I) A-1 · B
ZOH discretization: A_bar is matrix exponential, B_bar integrates the input over [0, Δt]

This gives us the recurrent form used in neural networks:

ht = A_bar · ht-1 + B_bar · xt
yt = C · ht
Discrete-time SSM: recurrent update

1.3 Convolution View

Since the SSM is linear and time-invariant, the recurrence can be unrolled into a convolution, enabling parallel training:

y = x * K, where Kj = C · A_barj · B_bar
SSM as convolution: K is the impulse response (kernel)

This dual representation is key: recurrent for fast inference, convolutional for parallel training.

二、核心数学框架

2.1 The Long-Range Dependency Problem

Previous SSMs struggled with long-range dependencies because the state matrix A was either diagonal (exponential decay, no memory retention) or dense (prohibitively expensive O(N2) computation). The Copy task was the litmus test: can the model remember a token from position 1 and reproduce it at position L?

Traditional SSMs either failed entirely (diagonal A loses signal exponentially) or required state dimension N proportional to sequence length L (defeating their efficiency advantage).

2.2 HiPPO Theory

The key insight of S4: certain structured matrices have ideal properties for capturing long-range dependencies. The HiPPO (High-Order Polynomial Projection Operators) framework provides a theoretical foundation for designing state matrices that compress history optimally.

The HiPPO matrix (also called the Legendre matrix) is defined as:

Ank = -(2n+1)1/2(2k+1)1/2 for n > k
Ank = -(n+1) for n = k
Ank = 0 for n < k
HiPPO matrix: encodes a sliding window of input history using Legendre polynomial basis

This matrix encodes a sliding window of the input history using orthogonal polynomial basis functions. The state vector h(t) stores coefficients of the projection of the input signal's history onto Legendre polynomials. As new input arrives, the coefficients update to maintain the projection over a sliding window.

Intuition: Think of HiPPO as Fourier transform for memory — instead of representing the signal in frequency space, it represents the signal's history in Legendre polynomial space. The state vector holds the coefficients of this representation, and the A matrix ensures they update correctly as the window slides.

2.3 Normal Plus Low-Rank (NPLR) Decomposition

The HiPPO matrix is special: it can be decomposed into a normal matrix (unitarily diagonalizable) plus a low-rank term:

A = V Λ V* + P QT
NPLR decomposition: normal (diagonalizable) + low-rank (rank typically 1-2)

This decomposition is the computational key that makes S4 tractable:

K = C · (B + (I - A_bar)-1 A_bar · B)
Woodbury-accelerated kernel computation: O(N log N) instead of O(N2)

三、训练与推理

3.1 Training Mode (Convolution)

For training, S4 uses the convolution view: the entire kernel K is computed in one shot using the SSM's structure, and then the output is computed via FFT convolution (O(L log L)):

# S4 training: compute kernel once, convolve
# N = state dimension, L = sequence length
K = compute_ssm_kernel(A_bar, B_bar, C, L)  # O(N log N + L)
y = FFT_convolve(x, K)                       # O(L log L)

3.2 Inference Mode (Recurrence)

At inference time, the SSM unrolls as a recurrence, requiring O(1) per step regardless of past history:

# S4 inference: constant-time per step
h = zeros(N)           # state initialization
for t in range(T):
    y_t = C @ h        # output from current state
    h = A_bar @ h + B_bar * x_t  # state update

四、实验结果

4.1 Long Range Arena (LRA)

S4 was the first SSM to achieve competitive results on all LRA tasks:

TaskTransformerLSTMS4Improvement vs Transformer
ListOps36.3749.2358.35+21.98
Text (IMDb)64.2365.9386.82+22.59
Retrieval (AAN)89.7955.9990.90+1.11
Image (CIFAR-10)42.4455.8087.26+44.82
Pathfinder70.7261.3386.05+15.33
Path-X88.6967.5887.12-1.57
Average62.0564.8486.09+24.04
Remarkable: Path-X (16k x 16k pixel sequences) was considered nearly impossible for non-Transformer models before S4. S4 achieved 87.12%, only slightly below Transformer's 88.69%, while being dramatically more efficient (O(L) vs O(L2)).

五、局限性

5.1 Time-Invariance: The Fundamental Gap

S4 is a Linear Time-Invariant (LTI) system. Its parameters A, B, C, and Δ are learned during training but fixed at inference. This means:

This is the fundamental weakness that Mamba would later address.

5.2 Other Limitations

六、上下游关联

上一篇:HiPPO (Gu et al., 2020) — introduced the polynomial projection theory for memory. S4 is the practical application of HiPPO theory to deep learning.

下一篇:Mamba (Gu & Dao, 2023) — S4 + input-dependent selectivity (B, C, Δ become functions of x). Inherits HiPPO initialization, NPLR decomposition, and the convolutional-recurrent duality from S4.

引用/采用:S4 spawned the entire structured SSM family: S4D (diagonal S4), DSS, Mega (simplified gated SSM), and ultimately Mamba and Mamba-2. It is also a key building block in state-space vision models.

七、个人思考

S4 is a pivotal paper not because it achieved the best numbers (Mamba later surpassed it), but because it proved the SSM hypothesis: that a well-designed recurrent model can match Transformers on long-range tasks. Before S4, the community largely believed that attention was necessary for long-range reasoning. S4 showed that the bottleneck was not the architecture but the parameterization of the state transition.

The NPLR decomposition is the most technically beautiful part: it's a textbook example of using mathematical structure (normal matrix theory + Woodbury identity) to turn an O(N2) algorithm into O(N). This type of "structure-aware algorithm design" is what separates groundbreaking ML papers from incremental ones.

The lesson for future researchers: don't blame the architecture class, fix the parameterization.