Fast Weights & Test-Time Memory
From fast-weight programmers and the delta rule to layers whose memory learns while reading.
A recurrent network's state need not be a vector. Make it a matrix, write to it with outer products and read from it with matrix–vector products, and the network is programming its own fast-changing weights. That idea, from the fast-weight programmers of the early 1990s, returns in linear attention, in the delta rule of DeltaNet, and in layers whose state is a small model trained by gradient descent on every token they read.
What you’ll learn
- Describe memory-augmented networks and fast weights, and show that causal linear attention is a fast-weight programmer whose state update is a Hebbian write.
- Derive the delta rule as one gradient step on , and analyze its transition matrix .
- Explain gated delta rules, and how DeltaNet is trained in parallel over the sequence despite its matrix-valued transitions.
- Describe test-time training layers and Titans as memories updated by online optimization, and the view of sequence layers as test-time regression.
Memory beyond a vector
In the mid-2010s several architectures separated computation from storage. The Neural Turing Machine (Graves, Wayne & Danihelka, 2014) couples a recurrent controller to a memory matrix that it reads and writes through differentiable heads, addressed by content and by location. Memory networks (Weston, Chopra & Bordes, 2015) store facts in memory slots and retrieve the relevant ones, at first with hard selection and supervision of which slots matter, then with soft attention trained end to end (Sukhbaatar et al., 2015), and the differentiable neural computer (Graves et al., 2016) adds learned allocation and links that record the order of writes. These models learned small algorithms, such as copying and sorting, and question answering over stories, but they were often delicate to train and never became the standard building block for large models.
A simpler idea is older. In a fast-weight programmer (Schmidhuber, 1992), a slow network, trained by gradient descent, emits at every step a change to the weights of a second, fast network; the fast weights hold short-term memory while the slow weights hold skills. Ba, Hinton, Mnih, Leibo & Ionescu (2016) revived it as a decaying Hebbian matrix, , used to "attend to the recent past". In its plainest form a fast-weight memory is a matrix written with outer products of keys and values:
Think first A recurrent network with a -dimensional state vector stores numbers. How many does a fast-weight matrix store, and what does that buy?
numbers, so up to about key–value pairs of dimension can be stored and retrieved with little interference, against about one -dimensional item for a vector state. Reading costs a matrix–vector product, per step, the same order as a vanilla RNN's step. That ratio of memory to compute is why matrix-valued states reappear in modern recurrent models, from xLSTM's mLSTM to DeltaNet.
Linear attention is a fast-weight programmer
Causal softmax attention computes with , and must keep every key and value. Linear attention (Katharopoulos, Vyas, Pappas & Fleuret, 2020) replaces the similarity by an inner product of feature maps, , and the sums collapse into a recurrence.
Pull the query's features out of the sums; what remains depends only on past keys and values:
The matrix and the normalizer are running sums, so they obey a recurrence with a fixed-size state:
Generation now costs per token and memory that does not grow with the context, while training can still run in parallel. Schlag, Irie & Schmidhuber (2021) pointed out that this is exactly a fast-weight programmer: the slow projections , , program the fast weight matrix with outer products, and reading it with is a forward pass of the fast network.
The purely additive write has two weaknesses. It never forgets: every pair ever written stays in . And it cannot revise: writing a new value for a key already in memory adds to the old value instead of replacing it. Multiplying by a data-dependent decay at every step, as Mamba-2 does in this form, fixes the first weakness by forgetting everything a little, but not the second. Schlag and colleagues traced the limited capacity of linearized attention to this and proposed a different write.
A linear-attention memory (no decay) first writes the pair and later with the same unit-norm key . What does reading with return (ignoring the normalizer)?
- , the most recent value
- , the first value
- : additive writes accumulate instead of replacing
- The zero vector, since the two writes cancel
Show the answer
C. : additive writes accumulate instead of replacing
, so . A memory that should hold the current value of a variable needs a write that replaces what is stored at a key: the delta rule.
The delta rule
Treat the memory as a linear model that should map each key to its value, and let every token take one step of online least squares. This is the delta rule of Widrow & Hoff (1960), the classic least-mean-squares update, applied to a fast weight matrix.
The memory's error on the current pair is a squared loss in , with gradient an outer product:
One gradient step of size from gives the delta rule: write the error , not the value itself:
With a unit-norm key and the write is exact: . Whatever was stored at is replaced, and directions orthogonal to are untouched.
The state transition is a generalized Householder matrix: eigenvalue along the key and 1 on its orthogonal complement. The memory forgets only in the direction it is about to write, and for no direction grows.
Starting from , the same pair with is written three times. Linear attention then returns . What multiple of does the delta rule with return?
Show the answer
0.875
Each write closes half of the remaining gap: goes . In general writes give , converging to rather than growing like . The delta rule is a regression that converges; the Hebbian write is a sum that grows.
Training in parallel. Because the transition is a full matrix rather than a diagonal one, the delta rule is not an elementwise scan. Yang, Wang, Zhang, Shen & Kim (2024) showed that products of such Householder-like matrices have a compact WY representation, which lets the recurrence be computed chunk by chunk with dense matrix multiplications, and trained DeltaNet (with L2-normalized keys and ) at 1.3 billion parameters on 100 billion tokens, where it outperformed Mamba and gated linear attention in perplexity and zero-shot evaluations. Gated DeltaNet (Yang, Kautz & Hatamizadeh, 2025) adds a data-dependent decay, which in the online-regression view is an adaptive weight decay: "gating enables rapid memory erasure while the delta rule facilitates targeted updates".
| Model | State update | As online learning |
|---|---|---|
| Linear attention | step on a linear score ; never forgets | |
| Mamba-2 (scalar decay) | the same, plus uniform forgetting | |
| DeltaNet | gradient step on | |
| Gated DeltaNet | decay, then the same gradient step |
Memories that learn at test time
If one step of least squares on a linear memory works, why not a more expressive memory and a better optimizer? Test-time training (TTT) layers (Sun et al., 2025) make the hidden state the weights of a small model , and update them with one gradient step of a self-supervised loss per token, using learned projections that are trained, like everything else, in the outer loop:
For speed, TTT takes its gradients in mini-batches of 16 tokens, all evaluated at the weights left by the previous mini-batch, which turns most of the work into parallel matrix products. Titans (Behrouz, Zhong & Mirrokni, 2025) make the memory a deeper MLP and add two optimizer features. Momentum accumulates "surprise", the gradient of the memory's loss , and a forgetting gate decays the memory, with data-dependent rates , , :
A fixed-size memory, however cleverly trained, has a fixed capacity: a matrix can hold only about clean associations, and a small MLP only so much more. Softmax attention escapes by keeping every key and value, at a cost that grows with the context. Hybrid Models & the Limits of Fixed-Size Memory compares the two on recall and copying, and shows why many recent architectures combine them.
Key takeaways
- Fast-weight programmers keep a matrix-valued state written with outer products and read with matrix–vector products (Schmidhuber, 1992); causal linear attention is one, with the Hebbian update (Schlag, Irie & Schmidhuber, 2021).
- The additive write never forgets and cannot revise a key's value. The delta rule is one gradient step on : it overwrites exactly at and forgets only along the key.
- DeltaNet trains in parallel through the WY representation of products of generalized Householder matrices; Gated DeltaNet adds a data-dependent decay, an adaptive weight decay in the online-regression view.
- TTT layers and Titans make the memory a small model trained by gradient steps (with mini-batches, momentum and forgetting) at test time; a linear TTT layer with online steps is the delta rule. All are instances of test-time regression, and all have a fixed capacity that attention's growing cache does not.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In what sense is causal linear attention a fast-weight programmer?
- It updates its slow weights , , by gradient descent at every token
- Its state is a matrix that the slow projections write with outer products and that is read as a linear layer applied to
- It stores every past key and value, like a KV cache
- It uses a softmax to choose one memory slot per step
Show the answer
B. Its state is a matrix that the slow projections write with outer products and that is read as a linear layer applied to
The sums in linear attention collapse into (plus a normalizer). acts as the weight matrix of a fast network that the slow, trained projections reprogram at every step (Schlag, Irie & Schmidhuber, 2021).
The delta rule is one gradient step of size on which objective?
- , the linear score that linear attention follows
- , a weight-decay penalty
- , reconstructing keys from values
- , the squared error of predicting the value from the key
Show the answer
D. , the squared error of predicting the value from the key
Its gradient is , so the step writes the prediction error rather than the value. That is why repeated writes of the same pair converge to instead of growing.
For a unit-norm key and , what does the transition do to the memory when it multiplies it from the right?
- It shrinks only the component of that acts on , by the factor , and leaves every direction orthogonal to unchanged
- It shrinks every direction by
- It rotates the memory by an angle
- It doubles the component along
Show the answer
A. It shrinks only the component of that acts on , by the factor , and leaves every direction orthogonal to unchanged
has eigenvalue along and 1 elsewhere. The delta rule therefore forgets precisely what is stored under the key it is about to write, a targeted erasure; a scalar decay would erase everything uniformly.
A TTT layer uses a linear inner model , the loss and one gradient step with rate per token. What is its update?
- Linear attention's Hebbian write,
- An exact least-squares fit to all past tokens at every step
- The delta rule with , keys and values
- A softmax attention over all past tokens
Show the answer
C. The delta rule with , keys and values
, so . TTT layers generalize this with richer models and mini-batched steps; with batch gradient descent from zero, Sun et al. show the linear case reproduces linear attention instead.
Further reading
- J. Schmidhuber, "Learning to control fast-weight memories: An alternative to dynamic recurrent networks," Neural Computation 4(1), 131–139 (1992).
- I. Schlag, K. Irie & J. Schmidhuber, "Linear transformers are secretly fast weight programmers," ICML (2021).
- S. Yang, B. Wang, Y. Zhang, Y. Shen & Y. Kim, "Parallelizing linear transformers with the delta rule over sequence length," NeurIPS (2024).
- S. Yang, J. Kautz & A. Hatamizadeh, "Gated delta networks: Improving Mamba2 with delta rule," ICLR (2025).
- Y. Sun, X. Li, K. Dalal, J. Xu, A. Vikram, G. Zhang, Y. Dubois, X. Chen, X. Wang, S. Koyejo, T. Hashimoto & C. Guestrin, "Learning to (learn at test time): RNNs with expressive hidden states," ICML (2025).
- A. Behrouz, P. Zhong & V. Mirrokni, "Titans: Learning to memorize at test time," NeurIPS (2025).