State-space models (SSMs, e.g. S4/Mamba) frame sequence modeling as a linear time-invariant system: continuous form
h˙(t)=Ah(t)+Bx(t),
y(t)=Ch(t); ZOH (zero-order hold) discretization gives
Aˉ=eAΔ,
Bˉ=(eAΔ−I)A−1B, so inference is the linear recurrence
ht=Aˉht−1+Bˉxt,
yt=Cht — an
O(1) state update per step with no KV cache. When time-invariant (
Aˉ,Bˉ,C independent of the input) it unrolls into a global convolution
y=Kˉ∗x with
Kˉ=(CBˉ,CAˉBˉ,…), enabling fully parallel training. The key of Mamba is the
selective mechanism:
Δt,Bt,Ct depend on the input
xt (e.g.
Δt=softplus(WΔxt)), acting like gating to decide per-token whether to remember or ignore — the cost is losing the convolution form, replaced by parallel scanning (associative scan) in training. Complexity: self-attention is
O(L2) in time and memory, Mamba is
O(L) in sequence length, giving a clear edge on long sequences.