TL;DR
A state space model describes a system by a hidden state that changes over time by a fixed linear rule, plus a readout that turns that state into an output. The state is a short memory of everything the system has seen so far. Once the rule is written as a discrete recurrence, the model can process a sequence one step at a time or all at once as a convolution.
Modern sequence models, such as S4 and Mamba, use this structure as a long-range memory that is cheaper than attention when the sequence gets long. The price is that the basic version applies the same rule at every step, so it cannot decide what to remember based on the input.
Where you'll see it: in the S4 and Mamba families of language and audio models, and in the Kalman filter that tracks the position of a moving object from noisy readings.
Intuition
A notebook that gets rewritten at every tick
Picture a sound engineer who keeps a short notebook while a song plays. At each moment she reads the new sample, updates a few numbers in the notebook, and then reads off a value from the notebook as her output. The notebook is the state. It is much smaller than the whole song, but it has to carry enough to predict what comes next. The update rule is the same at every moment, and the readout is the same at every moment. That is the whole model.
The reason to want this structure is memory. A recurrent network also keeps a state, but its update is a nonlinear function that is hard to analyse and slow to train on long inputs. A state space model keeps the update linear. A linear update can be unrolled in closed form, and the closed form can be computed in parallel. That is the source of the efficiency claims in the S4 and Mamba papers.
The idea is older than deep learning. Control engineers have used state space form since the early 1960s. Kalman's 1960 filter, which fuses noisy measurements into a running estimate of position and velocity, is a state space model with Gaussian noise on top.
The continuous picture first
A continuous state space model maps an input signal to an output signal through a hidden state that is a vector of numbers:
Here is the rate of change of the state, is an matrix saying how the state evolves on its own, says how the input pushes the state, and says how the state is read out. This is a linear ordinary differential equation with an input forcing term, which is why the ODE lesson is the first prerequisite.
The plot below shows the simplest case, one state with and (solid) or (dashed), when the input is a unit step that switches on at time zero. The state rises toward , which is 1 and 0.5 here, and levels off. The speed at which it gets there is set by .
- state h(t), A = -1
- state h(t), A = -2
Why we discretise
Computers see sequences as samples, not as continuous curves. Text tokens and audio samples arrive one step at a time. So the continuous rule has to be turned into a rule over steps. Writing the step size as , a common recipe is the zero-order hold (ZOH), which assumes the input stays constant between samples:
Once you have and , the model is a discrete recurrence:
The notation with a bar means "the discrete version of ". The step size has a physical meaning: a large means each sample covers a long stretch of the continuous signal.
flowchart LR P[Continuous parameters A, B, C and step size Delta] --> D[Discretise: A-bar, B-bar] D --> R[Linear recurrence over steps] D --> K[Convolution kernel built from C, A-bar, B-bar] R --> Y1[Output y_t, one step at a time] K --> Y2[Output y, whole sequence at once]
The math
Definition
A discrete state space model is a map from an input sequence to an output sequence , defined by a hidden state and fixed matrices , and , by the recurrence with , and the readout .
Here is the sequence length, is the state size, and means the state starts empty. The symbols , and are the same for every step, which is what makes the model linear time invariant (LTI).
Unrolling the recurrence
Start from and apply the recurrence step by step:
Multiply by to get the outputs. The pattern is that is a weighted sum of all past inputs, where the weight on is . Write this weight as a kernel . Then the whole output is a convolution:
This is the same kernel structure as the ordinary Convolution of signal processing, with a kernel that is fixed and does not depend on the input. Two computation modes follow. The recurrence runs one step at a time and needs only the current state, which is cheap at inference. The convolution computes every output at once with a fast transform, which suits training on whole sequences. This is the dual view the Mamba paper describes: the model can be computed as a linear recurrence or as a global convolution, and the choice is a matter of efficiency.
Scalar example of the discretisation
Take , , , , and .
- Compute .
- Compute .
- Check against the integral: should equal . It does.
- Feed a constant input from .
- , and .
- The closed form gives . Matching.
The interpretation: the discrete recurrence reproduces the continuous system exactly at the sample times, provided the input is held constant between samples. That is the assumption ZOH makes.
Kernel example
Take , , , and a single impulse input .
- The kernel is , so .
- Run the recurrence: , , , .
- Read out: .
- The convolution with this impulse input gives as well.
The two modes agree. The impulse response is the kernel itself, which is why the kernel is the model's memory profile.
Cost of the full state
In the Mamba paper's notation, each channel of a sequence has a state of numbers. With channels, batch size and length , the full state over the sequence has entries. A realistic setting for illustration: , , , . Then numbers. Materialising that in fast GPU memory is the bottleneck the paper's hardware-aware scan is designed to avoid. The formula is from the paper; the numbers are an illustration of it, not a measurement.
Worked examples
A system with , , receives input for every , starting from .
- .
- .
- .
- .
- The steady state is . The state approaches 1 but more slowly each step.
Interpretation: the state is a leaky running sum. Its memory of old inputs decays by a factor of each step, so inputs more than about ten steps back contribute little.
Let , , , and . This means one state dimension forgets quickly and the other slowly.
- Impulse input .
- The kernel entry at lag is .
- At lag 0 that is . At lag 1 it is . At lag 2 it is .
- The output is .
Interpretation: the fast dimension dominates the first step, and the slow dimension keeps the tail alive. Real models use in the tens and learn the entries of , so a mix of time scales is learned rather than hand-picked.
Tradeoffs and failure modes
The basic LTI model is fast and well understood, but it has a specific weakness. Because its parameters are fixed, it treats every input token the same way. It cannot choose to ignore filler and keep a key fact. The Mamba paper calls this a fundamental limitation of LTI models and makes the parameters depend on the input to fix it.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Long continuous signals such as audio or sensor data | LTI models do well here; the continuous prior fits | Stay with LTI state space models and the convolution mode |
| Discrete data such as text or DNA, where the model must decide what to keep | A fixed kernel cannot select content, so recall of a specific earlier token degrades | A selective SSM such as [[selective-state-space-model |
| Short sequences where a few thousand tokens are enough | Overhead of discretisation and scanning buys nothing | A Transformer with ordinary attention |
| Autoregressive inference with a long prompt | Attention caches grow with length | A recurrent form of the SSM, which keeps a fixed-size state |
| Choosing a step size without care | Too large and the discrete model misses fast dynamics; too small and training wastes steps | Learn per channel and check with a known impulse response |
Other failure modes: the eigenvalues of must stay inside the unit circle for the state not to blow up, so parameterisations that enforce stability are part of practical work. Initialisation of matters a lot; poorly chosen values give models that forget too fast or too slowly. The stability condition is a direct use of eigenvalues.
History
The state space form is much older than deep learning. Rudolf Kalman's 1960 paper gave a recursive filter for linear systems with noise, and the state space description it used became standard in control engineering during the 1960s. It solved the problem of estimating a hidden state from noisy measurements, which is still the core of navigation and tracking.
Machine learning took up the form slowly. Linear recurrent units and older state space ideas appeared in signal processing and in some sequence models, but they did not match transformers on language. In 2021 Gu, Goel and Re introduced the structured state space sequence model, S4, which parameterised with a special structure and computed the convolution efficiently. It showed strong results on long-range benchmarks. In late 2023 Gu and Dao introduced Mamba, which made the parameters input-dependent, gave up the fixed convolution for those layers, and used a hardware-aware scan to keep the cost linear in sequence length. It caught on because the paper reported transformer-quality language modelling from a model whose cost grows linearly with sequence length.
Check yourself
QuestionRecall: what does the matrix control in the recurrence ?Show answer
It controls how the existing state carries over from one step to the next. It is the memory part of the update. controls how much the new input is written into the state, and controls how the state is read out. alone decides how quickly old information fades.
QuestionComputation: with , , , and input , what is ?Show answer
Use with . For the terms are . So . Checking with the recurrence: , , , so .
QuestionWhy: why does the ZOH discretisation use rather than just ?Show answer
The exact solution of the continuous system over a step of length , with the input held constant, multiplies the state by . The simpler is only the first-order approximation of that exponential. It drifts for large or for large eigenvalues of , and the exact form keeps the discrete model faithful to the continuous one.
QuestionApplied: a team wants a model that must recall a fact stated 5,000 tokens earlier in a text document. Would a fixed-parameter LTI state space model be a good choice, and why?Show answer
Probably not on its own. An LTI model applies the same kernel regardless of content, so it cannot decide that a particular token is worth keeping. It can carry information over long distances in principle, but it cannot select the relevant token. A selective SSM, which makes the update depend on the input, or a hybrid with attention is a better fit. The team should test recall on a retrieval task before committing.