Chapter 03One slot, cleanly overwritten

The delta rule: read before you write

Linear attention writes by adding. Once the state is full, adding is the same as corrupting. The fix is one extra line: before writing at a key, look up what is already there and subtract it. And that line is not a heuristic anyone chose: two independent requirements force it, a third derives it as gradient descent, and Widrow and Hoff published it in 1960.

The constraint

A \(d\times d\) state holds at most \(d\) clean associations. Beyond that, purely additive writes make every readout a mixture of the value you wanted and every value you ever stored. Nothing ever leaves the state, so capacity is spent and never reclaimed.

Schlag, Irie and Schmidhuber named this the overcapacity regime, and argued the point directly: a model operating past its storage limit must be able to interact with its own memory — to decide which key–value associations to keep and which to delete. Adding new associations forever to a memory of fixed size will, they observed, inevitably hit a wall. Which is a precise description of chapter 2's ending.

The mechanism, in three lines

Linear attention's write was one line: S += kᵀv. The delta rule makes it three.

Axis names — used in every code block in this series b batch h head n sequence position i query position j key position dk key / query width dv value width dm model width = h·dv
from einops import einsum
# S : b h dk dv — the state is a linear map from keys to values, one per head

k_t         = F.normalize(k[:, :, t], dim=-1)                # b h dk   unit length, see below
v_t, beta_t = v[:, :, t], beta[:, :, t]                    # b h dv , b h

v_old = einsum(k_t, S,   'b h dk, b h dk dv -> b h dv')    # 1. read: contract dk away
u     = einsum(beta_t, v_t - v_old, 'b h, b h dv -> b h dv')# 2. the delta, scaled by β
S     = S + einsum(k_t, u, 'b h dk, b h dv -> b h dk dv')  # 3. rank-one outer-product write

The einsum strings are the whole explanation. Line 1 contracts the dk axis and leaves dv — a read, entering on the key side and exiting on the value side. Line 3 contracts nothing and produces both axes — an outer product, the only shape of write this state accepts.

Line 3 is unchanged from chapter 2. The entire difference is that the thing being written is no longer \(v\), but the discrepancy between \(v\) and what the memory already believes about this key. If the memory already says the right thing, \(u \approx 0\) and nothing is written. If it says something wrong, the wrong part gets cancelled out on the way in.

1 · READ THE BOARD AT THIS KEY k v_old = k S 2 · FORM THE CORRECTION v v_old u = β(v − v_old) Only the part the board does not already know. 3 · WRITE IT clean The row now holds exactly v. No trace of what was there before, and every other row untouched.
Read, subtract, write. The delta rule does not add a new association on top of the old one — it removes the old one in the same operation. Crucially the removal is targeted: the transform leaves every direction orthogonal to k completely unchanged, so correcting one fact cannot damage another.

Where this update comes from

Written cold, \(u = \beta\,(v - kS)\) looks like a heuristic somebody tried and kept. It is neither arbitrary nor new. Two independent requirements force exactly this expression, a third derives it as gradient descent, and the rule itself dates to 1960.

The genealogy

YearWhoWhat they contributed
1949HebbCo-active units strengthen their connection. The origin of the outer-product write.
1972Anderson; KohonenCorrelation matrix memory: \(M = \sum_i k_i^{\top}v_i\), read by \(kM\). This is chapter 2's state, fifty years early. Kohonen names the crosstalk problem in the same work.
1972KohonenOptimal linear associative memory: the crosstalk-free solution is the pseudo-inverse \(M^\star = K^{+}V\) — least squares over all stored pairs. Correct, but it needs the whole set at once.
1960Widrow & HoffThe delta rule (LMS): \(\Delta w = \eta\,(\text{target} - \text{output})\,x\). The online version of the same correction — one sample at a time, converging to Kohonen's pseudo-inverse. Predates the problem it solves by twelve years.
1992SchmidhuberFast weight programmers: one network writes another's weights during the forward pass.
2021Schlag, Irie & SchmidhuberRecognise that linear attention is a correlation matrix memory, and therefore that the 1960 fix applies verbatim.

The name is literal: \(\delta\) is the discrepancy between what you wanted and what you got, and the update is proportional to it. The 2021 contribution was an identification, not an invention — which is what makes the lineage worth knowing. If your state is a correlation matrix memory, every pathology and every remedy from the 1970s associative-memory literature transfers unchanged.

Route 1 — exact readback forces it

Start from what the hardware allows. The recurrence adds one outer product per token, so whatever gets written has the shape \(k^{\top}a\) — the key is fixed by the token, and the only free choice is the vector \(a\):

\[ S_{\text{new}} \;=\; S \;+\; k^{\top}a \]

Now demand the property you actually want, which is that reading this key returns this value:

\[ k\,S_{\text{new}} \;=\; v \]

Substitute and solve. With \(\|k\| = 1\), so that \(k k^{\top} = 1\):

\[ \underbrace{kS}_{\text{what is already there}} \;+\; \underbrace{(k k^{\top})}_{=\,1}\,a \;=\; v \qquad\Longrightarrow\qquad \boxed{\,a \;=\; v - kS\,} \] 3.0

\(a\) is not chosen. It is solved for. Given a rank-one write at key \(k\) and a demand for exact readback, the delta is the only vector you can write. There is no design freedom left to exercise.

The line that reframes chapter 2

Linear attention writes \(a = v\). Compare with 3.0: that is correct if and only if \(kS = 0\) — that is, only when nothing is stored at this key yet.

Linear attention is the delta rule with the read term dropped. It is not a different algorithm; it is this algorithm under the assumption that memory is blank, which is true exactly once per key. Everything chapter 2 called interference is the accumulated cost of that assumption.

Route 2 — minimum disruption forces it too

Now drop the rank-one restriction entirely and ask a different question. Among all matrices \(S'\) that satisfy the new constraint, which one is closest to the memory you already have? This is the least-change principle, and it is the natural formalisation of "install this fact without breaking anything else":

\[ \min_{S'}\ \tfrac12\big\|S' - S\big\|_F^2 \qquad \text{subject to}\qquad k\,S' = v \]

Write \(\Delta = S' - S\) and \(r = v - kS\). The constraint becomes \(k\Delta = r\): an underdetermined linear system, whose minimum-norm solution is given by the pseudo-inverse of \(k\):

\[ \Delta \;=\; k^{+}r \;=\; \frac{k^{\top}r}{\|k\|^{2}} \;\;\overset{\|k\|=1}{=}\;\; k^{\top}\big(v - kS\big) \]

The same expression again, from a requirement that shares no vocabulary with the first one. And this route explains the property the worked example demonstrates below: the delta rule does not damage neighbouring memories because it is, by construction, the smallest possible change to \(S\) that installs the association. Not empirically gentle — provably minimal in Frobenius norm.

Route 3 — it is one step of gradient descent

Pose the same demand as a loss instead of a constraint. Map this key to this value, scored by squared error:

\[ \mathcal{L}(S) \;=\; \tfrac12\big\|\,kS - v\,\big\|^{2} \qquad\Longrightarrow\qquad \nabla_{\!S}\,\mathcal{L} \;=\; k^{\top}\big(kS - v\big) \]

Take one gradient step with step size \(\beta\):

\[ S \;\leftarrow\; S - \beta\,\nabla_{\!S}\mathcal{L} \;=\; S + \beta\,k^{\top}\big(v - kS\big) \]

Which is the update, with \(\beta\) revealed as a learning rate. Route 1 gets it by solving the constraint exactly; route 3 gets it by taking one step toward the constraint. They agree because for a single linear constraint, one step of size 1 lands on the solution.

So why β at all?

If exactness forces \(a = v - kS\), scaling it by anything less than 1 makes the readback inexact on purpose. That is the point:

β = 1 — full overwrite
The token's assertion is trusted completely. Readback returns \(v\) exactly and the previous contents of the slot are gone.
β = 0 — no write
\(M_t = I\), the state passes through untouched, the token contributes nothing to memory. This is a learned write gate, and it is the reason β must be data-dependent rather than a constant.
0 < β < 1 — partial update
Readback becomes a convex blend of old and new. The memory accumulates evidence about a key rather than replacing it, which is the right behaviour when a token is weak evidence rather than a definition.

And there is a stability reason, taken up immediately below: constraining \(\beta\) to \((0,1)\) with a sigmoid bounds every eigenvalue of the transition matrix, which is what keeps the recurrence from diverging over a hundred thousand steps.

What that update really is

Substitute the three lines into one another and the whole step collapses:

\[ \begin{aligned} S_t &= S_{t-1} + k_t^{\top}\,\beta_t\big(v_t - k_t S_{t-1}\big) \\[4pt] &= \big(\underbrace{I - \beta_t\,k_t^{\top}k_t}_{\textstyle M_t}\big)\,S_{t-1} \;+\; \beta_t\,k_t^{\top}v_t \end{aligned} \] 3.1

βt = σ(x Wβ) ∈ (0,1) is a per-token, data-dependent write strength; kt is normalised to unit length.

So this is still a linear recurrence — but the state is no longer just accumulated, it is multiplied by a transition matrix \(M_t\) first. And \(M_t\) is not an arbitrary matrix. It is the identity plus a rank-one correction, which makes its behaviour completely transparent.

Take any vector \(s\) and split it into the part along \(k_t\) and the part orthogonal to it. Since \(\|k_t\| = 1\):

Component of the stateWhat \(M_t = I - \beta_t k_t^{\top}k_t\) does to itEigenvalueHow many such directions
along \(k_t\)  (this key's slot)scaled by \(1-\beta_t\)\(1-\beta_t\)1
orthogonal to \(k_t\)  (every other slot)left exactly as it was\(1\)\(d-1\)

Three readings of the same matrix, all useful:

Geometrically
At \(\beta = 1\), \(M_t = I - k^{\top}k\) is the orthogonal projection onto the hyperplane perpendicular to \(k\). It deletes the key's slot and nothing else. At \(\beta = 0\) it is the identity — no write. Between them it interpolates.
Algebraically
\(I - \beta k^{\top}k\) is a generalized Householder transform. The classical Householder reflection is the \(\beta = 2\) case. The whole family for \(\beta \in [0,2]\) is non-expansive, which is why this recurrence is stable: every eigenvalue lies in \([-1, 1]\), so the state cannot blow up over a long sequence. Restricting \(\beta\) to \((0,1)\) with a sigmoid keeps everything in \([0,1]\) — a strict contraction along \(k\), identity elsewhere.
Statistically
One step of gradient descent on the read error, as derived above — with \(\beta_t\) as the learning rate.
What route 3 actually implies

If each token performs one SGD step on a regression problem, then the forward pass is a training loop. The state \(S\) is a one-layer linear network; the sequence is its dataset; the model emits the training examples \((k_t, v_t)\) and the learning rate \(\beta_t\) as it goes.

This is the sense in which the family is called fast weights — weights learned during inference, on data seen at inference, thrown away afterwards. It also marks out the obvious frontier: if one SGD step works, why one, and why SGD? More steps, momentum, or a preconditioner all give strictly more expressive write rules at strictly more cost, and several such variants already exist.

Checking that it works

Read the state back at the key you just wrote, using \(\|k_t\|=1\):

\[ k_t\,S_t \;=\; k_t\big(I-\beta_t k_t^{\top}k_t\big)S_{t-1} + \beta_t\,k_t k_t^{\top} v_t \;=\; (1-\beta_t)\,\underbrace{k_t S_{t-1}}_{\text{old value}} \;+\; \beta_t\, v_t \]

A convex blend of what was stored and what you are storing, controlled entirely by \(\beta_t\). At \(\beta_t = 1\) the readback is \(v_t\) exactly — the old value is gone with no residue. That is the property linear attention could not offer at any capacity.

Note where the unit-norm assumption earned its place. Without it, \(k S = \|k\|^2 v\), so readback is scaled by the key's squared norm and the effective learning rate becomes \(\beta\|k\|^2\), which can exceed the stability bound. Hence the two lines you always see:

q    = F.normalize(F.silu(q), dim=-1)   # b h n dk — unit length, so read-back is unscaled
k    = F.normalize(F.silu(k), dim=-1)   # b h n dk — unit length, so β is the true step size
beta = torch.sigmoid(self.w_beta(x))    # b h n    — per-token write strength in (0,1)

A worked example, small enough to check by hand

Two dimensions. Two tokens that use the same key with different values — the exact situation that breaks additive writes.

StepLinear attention  (chapter 2)Delta rule, \(\beta = 1\)  (this chapter)
Write 1
\(k_1=[1,0]\)
\(v_1=[2,4]\)
\(S_1 = k_1^{\top}v_1 = \begin{bmatrix}2&4\\0&0\end{bmatrix}\) nothing stored yet, so \(v_{\text{old}}=[0,0]\), \(u=[2,4]\)
\(S_1 = \begin{bmatrix}2&4\\0&0\end{bmatrix}\)  — identical
Write 2
\(k_2=[1,0]\) same key
\(v_2=[0,1]\)
\(S_2 = S_1 + k_2^{\top}v_2 = \begin{bmatrix}2&5\\0&0\end{bmatrix}\) \(v_{\text{old}} = k_2 S_1 = [2,4]\)
\(u = [0,1]-[2,4] = [-2,-3]\)
\(S_2 = \begin{bmatrix}0&1\\0&0\end{bmatrix}\)
Read at \(k_2\) \([2,5]\)  — which is \(v_1 + v_2\).
The old value was never removed.
\([0,1] = v_2\)  exactly.
Write 3
\(k_3=[0,1]\) orthogonal
\(v_3=[7,7]\)
\(S_3 = \begin{bmatrix}2&5\\7&7\end{bmatrix}\) \(v_{\text{old}} = k_3S_2 = [0,0]\), so \(u = [7,7]\)
\(S_3 = \begin{bmatrix}0&1\\7&7\end{bmatrix}\)
Read at \(k_2\) again \([2,5]\) — still wrong \([0,1]\) — still exact. Writing at an orthogonal key disturbed nothing.

The last row is the point people miss. The delta rule does not merely overwrite — it overwrites locally. Facts stored in orthogonal directions are provably untouched, because \(M_t\) has eigenvalue exactly 1 there.

The query as a learned pointer

Nothing so far explains how a later token knows which key to ask for. The answer is that \(W_q\) and \(W_k\) read the same residual stream. If the phrase that established a fact produced a key in some direction, the model can learn to make a later phrase that needs that fact produce a query in the same direction. The keys are not addresses assigned by the architecture; they are content-derived, and matching them is a learned behaviour on both sides.

The read is a plain linear map, \(o_t = q_t S_t\), with no denominator at all — the running normaliser \(z\) from chapter 2 is gone, replaced by unit-normalised \(q,k\) and an RMSNorm on the output. A query pointing exactly at one stored key returns that value; a query between two keys returns a blend, weighted by the cosine with each. Soft retrieval is still available; it just is not forced.

What it costs

StateFLOPs per tokenExtra work vs. chapter 2
Linear attention\(d^2\)\(\sim 4d^2\)
Delta rule\(d^2\)\(\sim 6d^2\)one extra \(d\times d\) matrix–vector product: the read \(k_tS_{t-1}\)

Fifty percent more arithmetic, identical memory, and the capacity ceiling from chapter 2 is no longer a hard wall — the state now reclaims a slot every time a key is rewritten. For the price of one matvec.

Two things this still cannot do

It cannot forget without a replacement. Erasure only happens as a side effect of writing something new at the same key. There is no operation for "this document is over, clear the board". Stale associations from 30,000 tokens ago sit there consuming capacity until some future key happens to point in their direction. That is chapter 5.

It cannot be trained the obvious way. Chapter 2's state was a running sum, so a whole sequence could be folded up with a prefix sum — trivially parallel. Now each step multiplies by \(M_t\), and \(u_t\) depends on \(S_{t-1}\), which depends on \(u_{t-1}\). Running 100,000 sequential steps on a GPU is not a training recipe, and a generic matrix scan would cost \(d^3\) per combine. Chapter 4 is about why the rank-one structure of \(M_t\) saves this, and it is the hardest idea in the series.