6.1.11 · D1Scaling & Efficient Architectures

Foundations — State-space models (Mamba, S4)

3,189 words14 min readBack to topic

Before you can read the parent note, you must own every piece of notation it throws at you. This page builds each one from nothing, in the order they depend on each other. Nothing here assumes you have seen a matrix, an ODE, or a convolution before.


1. A sequence, its index , and its length

Why start at and not ? It is purely a bookkeeping choice — nothing mathematical hinges on it. Starting at lets us say " is the first real input" and, later, reserve a separate label for the memory before any input has arrived (that memory is , built in §5). If you preferred for the first input, you would just shift every subscript down by one; the formulas are identical.

The picture: imagine words on a page read left to right, or beads threaded on a string. Each bead sits at a position

Why the topic needs it: the whole point of these models is processing sequences — sentences, audio, DNA — where order matters. The counter lets us talk about "the past" (steps before ) and "the future" (steps after).

Figure — State-space models (Mamba, S4)

2. A vector — the state as a list of numbers

The picture: an arrow in space, or more simply, a set of dials each holding a value. If you can draw it as a point on a flat plane; if you can't draw it, but it's still "just a list".

Why the topic needs it: the model's memory — the hidden state — is a vector. Each of its slots stores one running summary of the past. Bigger = more memory capacity.


3. The hidden state and its dimension

The picture: a small whiteboard the model scribbles notes on. At each step it erases a bit, adds the new input's contribution, and keeps the board for next time.

Why the topic needs it: this single vector is the entire summary of everything the model has seen so far. That is what makes the model fast — it never re-reads the past; it only reads the whiskered-down summary .


4. A matrix and matrix–vector multiplication

The picture: feed an arrow in, get a rotated/stretched arrow out. See the figure below — the left dial-panel is , the grid is , the right panel is .

Why the topic needs it. The three letters are all matrices, and they do three different jobs:

  • mixes the old memory into the new memory (state → state).
  • injects the current input into the memory (input → state).
  • reads the memory out into an answer (state → output).
Figure — State-space models (Mamba, S4)

5. The recurrence, its initial state , and the output

Reading the bar. The overline marks the discrete (per-step) version of a matrix. So ("A-bar") is the discrete version of , and likewise ("B-bar") is the discrete version of . The un-barred are the continuous versions (§7 explains why they differ). needs no bar — it reads the state out the same way in both worlds.

The picture: a bucket of water starting empty (). Each step the bucket drains a fraction (that's , which keeps a portion of the old level) and you pour in a splash proportional to the input (that's ). The water level is the state; the reading on a gauge attached to it is .

Why the topic needs it: this pair of lines is the model at inference time. It runs in — one cheap update per token — which is exactly the linear-time promise state-space models (SSMs) make over the Transformer. Compare this to RNNs and LSTMs, which also carry a state forward step by step; SSMs are that idea with a cleaner, controllable update rule.


6. The derivative and the continuous law

The picture: the slope of the tangent line on a curve. Steep upward slope = growing fast; flat = holding steady; downward = shrinking.

Why the tool, and why not just differences? The parent's continuous law is the ordinary differential equation (ODE)

h'(t) = \mathbf{A}\,h(t) + \mathbf{B}\,x(t) \tag{$\star$}

— an equation that says "the change in is determined by where is now () plus the current input ()". We give it the label so we can point back to it. Physics and control theory have centuries of exact tools for such laws. Working continuously first, then converting to steps, gives an exact update rule instead of the crude approximation you'd get by naively subtracting neighbouring samples.


7. The step size and the matrix exponential

Why this specific tool? The solution of the ODE (with input held constant over a step) over one full step of width is exactly multiply-by-. So the discrete decay matrix is : it is the honest, exact answer to "if the state obeys this law, where is it one tick later?" A crude method (Euler's ) drops all the higher terms and drifts off over long sequences.

The picture — why decay: in the scalar case with is a number between and . Multiplying the state by it each step shrinks it — that is forgetting. The figure shows how the size of that number sets memory length: near ⇒ long memory, near ⇒ fast forgetting. This is exactly the worked example's (slow) vs. (fast).

Figure — State-space models (Mamba, S4)

8. Convolution and the kernel

The picture: a stencil dragged along the sequence; at every stop it multiplies-and-adds the values under it. This is the same operation at the heart of Convolutional Neural Networks — only there the stencil slides over an image, here over a time axis.

Why the topic needs it: unlike the step-by-step recurrence, a convolution can be computed for all positions in parallel, which is why the S4 model trains as a convolution but generates as a recurrence.

Recall Why two views of the same model?

Recurrence :::: cheap generation, one token at a time, no parallelism. Convolution :::: parallel over the whole sequence, ideal for training on GPUs.


9. Complex numbers and the diagonal (a light touch)

You do not need complex analysis to read D1; just hold onto these plain-word meanings.


10. Big-O notation — counting cost

Why the topic needs it: this is the scoreboard of the whole chapter. Transformers are ; SSMs are recurrent / convolutional. Linear Attention is another route to — SSMs are a cousin, reaching the same linear budget through a state recurrence instead of a reweighted attention sum.


How the foundations feed the topic

Sequence index k length L

Hidden state vector h

Vector in R^N

Matrix A B C

Recurrence h_k update

Initial state h_0 = zero

Derivative and the ODE

Discretization

Matrix exponential e^A Delta

Step size Delta

Stability negative real eigenvalues

Convolution kernel K

Diagonal Lambda structure

S4 fast kernel

Big-O cost counting

Mamba selective Delta per token


Equipment checklist

Read each cue, answer aloud, then reveal.

What does the subscript in mean, and what is ?
is the position/index in the sequence; is the sequence length (last step). We count .
What is the initial state and why do we need it?
The memory before any input — defined as the zero vector — so the recurrence has something to feed step ; it makes .
What is a vector ?
An ordered list of real numbers — the model's memory, one summary value per slot.
What are the three jobs of , , ?
A ages/mixes old state into new; B injects the current input into the state; C reads the state out into the output .
What does the overline in and signal?
The discretized (per-step) versions of the continuous matrices and .
What does measure, and what is equation ?
The instantaneous rate of change of the state; is the ODE .
Why use the matrix exponential for ?
It is the exact solution of the ODE over one step of width ; simpler methods drift over long sequences.
What stability condition makes the kernel decay?
Eigenvalues of must have negative real part, so each has size below 1.
In the scalar case, what does near vs. near mean?
Near 1 = long memory (slow forgetting); near 0 = fast forgetting.
What does control?
The gap between clock ticks / discretization step — effectively how fast the state forgets.
Why is the -th kernel entry ?
An input injected by , aged times by , then read by — the impulse response.
What are the entries of the diagonal matrix in S4?
Its eigenvalues — the per-direction scaling numbers; powers are cheap because you power each entry.
What does mean in ?
Conjugate transpose: turn the column into a row and flip the sign of each imaginary part.
What do and compare?
How compute grows with sequence length; SSMs are linear , Transformers quadratic .

Ready? Head back to State-space models (Mamba, S4) and the symbols will read like plain sentences.