Foundations to Frontier
Tests
E. Deep Learning › E17 State-Space and Recurrent-Revival Models

S5

S5 (Simplified State Space layers; Smith, Warrington and Linderman, ICLR 2023) replaces S4's bank of single-input single-output SSMs with one multi-input multi-output SSM with a diagonalised state matrix. It computes the recurrence with a parallel associative scan instead of a convolution. Because the scan does not need a fixed convolution kernel, S5 handles time-varying step sizes, such as irregularly sampled data, and it paved the way for Mamba's input-dependent dynamics. It matches S4 on the Long Range Arena. This page covers MIMO SSMs, diagonalisation and the parallel scan. In the exercises you implement the associative operator and check associativity, then compare a parallel scan with the sequential loop on time-varying recurrences of up to 16,384 steps. The scan matched to 5 × 10⁻¹⁵ in 14 parallel rounds instead of 16,384 sequential steps. A fixed convolution kernel would have been 12% off.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

One shared memory, updated in parallel

S4 runs many small independent memories, one per channel, and computes them as convolutions. S5 uses a single, larger memory shared by all channels and computes it with a parallel scan: a trick that combines steps in a tree, so a sequence of 16,000 steps needs only about 14 rounds of parallel work. The scan also works when the update rule changes from step to step, which convolutions cannot handle. The demo shows how an input-dependent step size changes what a memory keeps.

State-space lab
Final state 0.532. With an input-dependent step, the important token at t = 10 is written strongly and then held. This is Mamba's selection mechanism.
Why engineers care

Real sensor data is often irregularly sampled (dropped packets, event-driven sensors). S5’s scan handles a different time step at every sample without resampling.

📝 Quick check (Level 0)
0/3 answered
  1. 1. S5 uses…
  2. 2. S5 computes the recurrence with…
  3. 3. The scan works even when…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • MIMO SSM: x_k = Āx_(k−1) + B̄u_k with state size P shared by all H input channels, and y_k = Cx_k + Du_k.
  • Diagonalisation: A = VΛV⁻¹, then work in the eigenbasis, so Ā = e^(ΛΔ) is diagonal. S5 initialises from a diagonalised HiPPO-N matrix.
  • Associative operator on pairs (a, b): (a₁, b₁) • (a₂, b₂) = (a₁a₂, a₂b₁ + b₂).
    • Folding it over the sequence gives the final state of x_t = a_t x_(t−1) + b_t.
    • Example: (0.5, 1) • (0.5, 2) = (0.25, 2.5).
  • Parallel scan: associativity allows tree evaluation.
    • Hillis–Steele uses ⌈log₂ L⌉ rounds (14 for L = 16,384), with work L·rounds − (2^rounds − 1), 212,993 combines for 16,384;
    • Blelloch uses O(L) work and 2 log₂ L rounds.
  • Time-varying steps: with a different Δ_k at each step, a_k = e^(λΔ_k) varies. There is no single convolution kernel, but the scan still works.
📝 Quick check (Level 1)
0/3 answered
  1. 1. (0.5, 1) • (0.5, 2):
  2. 2. Parallel rounds for L = 1024:
  3. 3. A convolution kernel exists when…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

S5 in code

Exercise 1.

  • Folding the operator reproduced the recurrence.
  • The operator was associative.
  • Parallel rounds were ⌈log₂ L⌉.

Practice.

  • In JAX, jax.lax.associative_scan implements the parallel scan directly. In PyTorch, use custom kernels (as in Mamba) or a chunked scan.
  • Initialise from a block-diagonal HiPPO-N, learn Λ, B̃, C̃ and log Δ, and take real outputs (conjugate symmetry).
  • For irregular sampling, pass each step’s elapsed time as its Δ_k.
import jax, jax.numpy as jnp
def binop(e1, e2):
    a1, b1 = e1; a2, b2 = e2
    return a1 * a2, a2 * b1 + b2
Lambda_bar = jnp.exp(Lambda * dt[:, None])                  # (L, P): per-step decay, may vary with time
Bu = (Lambda_bar - 1) / Lambda * (u @ B_tilde.T)            # (L, P)
_, xs = jax.lax.associative_scan(binop, (Lambda_bar, Bu))   # all states in O(log L) depth
y = (xs @ C_tilde.T).real + u * D
🐍 Exercise 1: the associative operator
Implement the linear-recurrence operator, fold it over a sequence and count scan rounds.
📝 Quick check (Level 2)
0/3 answered
  1. 1. JAX function for parallel scans:
  2. 2. For irregular sampling, Δ_k is…
  3. 3. S5 initialises from…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why associativity enables parallelism.

  • A linear recurrence composes affine maps: step t maps x to a_t x + b_t. Composing affine maps is associative, so any grouping of the composition gives the same result.
  • A tree of pairwise compositions computes all prefixes in O(log L) depth, the same idea as parallel prefix sums.

Scan versus convolution.

  • Convolutions need a fixed kernel, so they apply only to time-invariant systems.
  • The scan applies to any linear recurrence, including time-varying a_t, at O(L) work (Blelloch) and O(log L) depth.
  • It also gives all intermediate states, which recurrent inference and state passing between chunks need.

MIMO versus SISO. S4’s H independent SISO SSMs (each with N states) are mixed afterwards by a linear layer. S5’s single MIMO SSM with P states couples channels inside the state and can use a smaller total state. With matching initialisation, the two are closely related; S5 is simpler to implement.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A linear recurrence step is…
  2. 2. Composition of affine maps is…
  3. 3. Scans apply to…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does the parallel scan really reproduce the recurrence, and what does it buy?

History.

  • G. Blelloch, “Prefix sums and their applications” (1990).
  • J. T. H. Smith, A. Warrington and S. W. Linderman, “Simplified state space layers for sequence modeling” (S5, ICLR 2023).
  • E. Martin and C. Cundy (ICLR 2018) parallelised linear RNNs with scans.

Exercise 2.

  • Recurrences: time-varying diagonal recurrences x_t = a_t x_(t−1) + b_t with 8 channels, a different decay a_t ∈ (0.82, 1) at every step, and random inputs, at L = 64, 1024 and 16,384.
  • Methods: a Hillis–Steele parallel scan, compared with the sequential loop and with the best time-invariant model (mean decay), which is all a convolution kernel could represent.
L max abs difference parallel rounds sequential steps scan work fixed-kernel relative error
64 1.8 × 10⁻¹⁵ 6 64 321 0.097
1024 3.6 × 10⁻¹⁵ 10 1024 9217 0.122
16,384 5.3 × 10⁻¹⁵ 14 16,384 212,993 0.125
  • Exact: the scan reproduces the sequential recurrence to floating-point precision at every length.
  • Short critical path: 14 rounds instead of 16,384 steps, about 1170 times shallower. The price is more total work (L log L for Hillis–Steele; Blelloch’s variant brings work back to O(L)).
  • Time-varying dynamics need the scan: a fixed convolution kernel using the average decay is 10–12% off, even for these mildly varying decays. Input-dependent dynamics (Mamba) make the gap much larger.
🐍 Exercise 2 (research): does the parallel scan really reproduce the recurrence, and what does it buy?
Compare a parallel associative scan with the sequential loop on time-varying recurrences, counting rounds and work.

S5 in AI, robotics and aerospace

  • Irregular telemetry: event-driven or packet-dropping sensors handled natively with per-step Δ.
  • Hardware efficiency: scans map well to GPUs and accelerators for long sequences.
  • Design lesson: when an operation is associative, it can be parallelised with a scan. Look for such structure before accepting sequential computation.

References

  1. J. T. H. Smith, A. Warrington and S. W. Linderman (2023). “Simplified state space layers for sequence modeling.” ICLR.
  2. G. E. Blelloch (1990). “Prefix sums and their applications.” Technical report CMU-CS-90-190.
  3. E. Martin and C. Cundy (2018). “Parallelizing linear recurrent neural nets over sequence length.” ICLR.