Diagonal SSMs (S4D) and Stability Analysis
S4D — the diagonal simplification of S4 that drops kernel cost from O(N²L) to O(NL) and makes stability guaranteed by construction via log-parameterized eigenvalues.
On this page
From Full to Diagonal
Week 4’s S4 stores as a full matrix (HiPPO-LegS initialization). The kernel computation requires matrix powers — even with a naive implementation.
S4D’s insight: any diagonalizable SSM with distinct eigenvalues can be transformed to an equivalent diagonal form. “Diagonal” here means the state matrix is a diagonal matrix (all off-diagonal entries zero), not a reference to any architectural name. The key result comes from the DSS (Diagonal State Space) paper Gupta et al. (2022) : the change-of-basis that diagonalizes via eigendecomposition can be absorbed into and without changing the system’s input-output behavior.
If with distinct eigenvalues , then the SSM has the same transfer function as . The transfer function captures the complete input–output behavior of the system — two SSMs with the same transfer function produce identical outputs for any input.
The transfer function is . Substituting : where and .
Initialization variants
S4D stores eigenvalues as complex numbers: where (decay) and (oscillation frequency). Three initialization schemes:
S4D-Lin (default)
for . [Convergence] S4D-Lin is the default initialization in the S4D, S5, and mamba-minimal reference codebases; other schemes are empirical variants.
Constant decay rate , linearly spaced frequencies. The simplest formula — one line of code. Each eigenvalue captures a different frequency band of the input signal. S4D-Lin is not the best performer on long-range tasks, but its simplicity makes it ideal for understanding the diagonal structure.
Four complex-conjugate pairs . All share decay rate but span frequencies through . With ,
so every channel’s state decays by ~5% per step. The phase rotation is radians per step: , , , . Each channel acts as a bandpass filter centered on its frequency, and their sum reconstructs any bandlimited signal the eight-dimensional basis can resolve.
S4D-Inv
for .
Inverse frequency spacing concentrates resolution at low frequencies, which is better for long-range dependencies.
S4D-LegS
Extract the diagonal of the HiPPO-LegS eigendecomposition from Week 4: compute and use the eigenvalues with most negative imaginary part.
Complex-valued state and stability by construction
S4D uses complex eigenvalue conjugate pairs. A conjugate pair means: if is an eigenvalue, then is also an eigenvalue (same real part, negated imaginary part). We only need to store one of each pair and reconstruct the other. This halves the parameter count and, crucially, guarantees real-valued output through the identity . The output uses this conjugate symmetry trick:
With the parameterization and , all continuous eigenvalues satisfy for any finite parameter values. ZOH discretization then maps these inside the unit disk: .
for all . The ZOH stability preservation follows from [?w4:prop:zoh-stability].
This is a crucial difference from Week 4: S4’s HiPPO initialization happens to be stable, but training could push eigenvalues out of the left half-plane. S4D’s log-parameterization makes continuous eigenvalue instability impossible by construction under this parameterization. [Official] The log-parameterization originates in the S4D paper Gu et al. (2022) and reproduces across S5, Mamba-1, and Mamba-2 reference code. Finite-precision accumulation, gradient overflow, and extreme- artifacts are still possible; stability-by-construction fixes only the sign of .
Element-wise computation
With diagonal , all matrix operations collapse to element-wise:
For diagonal , the convolution kernel is:
where absorbs the ZOH correction. This is vs. for full .
Since is diagonal, . The matrix product decomposes into independent scalar products. The log-space computation avoids explicit power iteration.
The recurrence also simplifies:
def ssm_recurrent_diag(Ab_diag, B, C, D, u):
def step(h, u_t):
h_new = Ab_diag * h + B * u_t # element-wise
y_t = 2 * jnp.real(jnp.sum(C * h_new)) + D * u_t
return h_new, y_t
h0 = jnp.zeros_like(Ab_diag)
_, y = jax.lax.scan(step, h0, u)
return y
Stability region analysis
The [DYN] exercise: compare learned eigenvalue positions against integrator stability boundaries.
Reflections
What transfers
- Diagonal = element-wise: The single most impactful simplification in the S4 lineage. Every subsequent architecture (S5, Mamba) uses diagonal state.
- Stability by construction: The log-parameterization eliminates a class of training failures. This pattern reappears in LRU Orvieto et al. (2023) and Mamba.
- Phase portrait analysis: Eigenvalue position → memory timescale is the key diagnostic for understanding what an SSM has learned.
What requires adaptation
-
Complex arithmetic overhead. The conjugate-pair trick halves parameters but introduces complex-valued computation throughout the forward pass. JAX handles complex64 natively, but a common failure mode is dtype mismatch: a function expecting
float32receivingcomplex64(or vice versa) produces silent wrong results or cryptic shape errors. Always check dtypes at module boundaries. -
Loss of the HiPPO interpretation. Full S4’s state vector has a clean theoretical meaning: each entry is a Legendre coefficient of the input history. Going diagonal discards this — the state becomes a collection of independently decaying oscillators with no polynomial approximation guarantee. This is an explicit theory-for-speed trade-off: the output is empirically similar, but the interpretability of the state is lost. S4D-LegS partially recovers the connection by initializing from HiPPO eigenvalues, but training immediately drifts away from the Legendre structure.
-
Initialization choice becomes empirical. Unlike Week 4’s HiPPO (one principled answer derived from approximation theory), S4D offers three variants with different frequency-resolution trade-offs: S4D-Lin (uniform resolution), S4D-Inv (low-frequency emphasis), and S4D-LegS (HiPPO-derived). [Practitioner] Choosing between them requires benchmarking on your target task — there is no single “correct” initialization. This is the first point in the curriculum where design becomes empirical rather than principled.
Forward map
- Week 6: S5 replaces
lax.scanwith associative scan for parallel depth. The diagonal structure from this week is required. - Week 7: Mamba makes input-dependent, breaking the convolutional view. The diagonal state and log-parameterization carry over.
- Week 18: Lyapunov analysis of the eigenvalue dynamics during training — tracking how the learned eigenvalues drift over optimization steps.