Test-time training is a linear attention operator in disguise
A small reproduction of a 2026 paper showing that key-value-binding TTT unrolls into a linear-attention state, plus sweeps for extra inner steps, query mismatch, gradient sign, and momentum.
The February 2026 paper Test-Time Training with KV Binding Is Secretly Linear Attention makes a useful claim against a tempting story.
The tempting story: a TTT layer receives a key, optimizes a small network so that the key maps to a value, then later retrieves that value with a query.
The paper's claim: for the key-value-binding version of TTT, the inner update is better read as a linear-attention operator. If the fast network has a bias-free final layer,
f(x) = phi(x) W
W <- W + phi(k)^T g(k)
out(q) = phi(q) Wthen unrolling the sequence gives the same shape as linear attention:
out_t = qhat_t (S_0 + sum_i khat_i^T vhat_i)The effective "value" is not necessarily the paper's original value vector. It is the negative gradient of the binding loss with respect to the fast model output. That small algebraic shift explains why better key-value fitting is not guaranteed to improve the sequence model.
Repro code path: test-time-training-linear-attention.
The controlled reproduction
I implemented a tiny fast-weight TTT layer in NumPy:
- keys, values, and noisy queries are synthetic but fixed by seed
- the hidden feature map phi is a fixed tanh projection
- only the final fast-weight matrix W is updated
- outputs are computed two ways: literal sequential TTT updates and the unrolled linear-attention state
This is not a reproduction of LaCT or ViTTT performance. It isolates the mechanism used in Theorem 5.1 and 5.2 of the paper.
The two implementations matched exactly at the scale of the run:
| Check | Value |
|---|---|
| Max output error | 0.0 |
| Max state error | 0.0 |

My analysis 1: query-key similarity is not the right diagnostic
Under a retrieval story, a query close to its key should be the central object. Under the linear-attention view, the query and key play different roles: one probes the accumulated state, the other wrote into it.
I tested that by making queries noisy versions of the keys. When the query was exactly the key, the mean cosine between output and current value was 0.7924. With noisy queries it dropped to 0.4746, and the raw query-key cosine explained only part of the output alignment: correlation 0.4454.
That does not refute retrieval by itself, but it shows why "are Q and K in the same semantic space?" is a weak test for TTT-KV binding. The operator can still be well-defined when query and key distributions differ.

My analysis 2: more fitting can move the operator
The paper reports that extra inner-loop steps can lower the binding loss while hurting downstream performance. I reproduced the mechanism in miniature by treating the one-step operator as the reference behavior and then taking more squared-loss update steps per token.
| Inner-step result | Value |
|---|---|
| One-step seen-key binding MSE | 0.1452 |
| Best seen-key binding MSE | 0.1272 at 2 steps |
| Largest drift from one-step outputs | 0.2166 MSE at 32 steps |
This is the core mismatch: improving the local key-value fit changes the accumulated attention state. If the downstream model was trained around the one-step operator, better local memorization can be the wrong intervention.

Gradient ascent is less mysterious in the linear view
The paper highlights a surprising empirical result: replacing inner-loop gradient descent with gradient ascent does not destroy pretrained TTT models. In my dot-product toy, ascent simply flips the effective values. With zero initial state, the outputs are exact negatives:
| Comparison | Mean cosine |
|---|---|
| Descent vs ascent | -1.0000 |
| Descent vs negative ascent | 1.0000 |
That is weaker than the paper's trained-model result, because my toy does not learn a downstream layer that can absorb the sign. But it does make the algebraic point plain: ascent changes the linear operator's value channel; it does not create an impossible "anti-memory" object.

Momentum changes what the state remembers
The paper extends the unrolling to momentum. I plotted the implied contribution multiplier by token age. With momentum alpha near 0.90, a token reached half of its eventual contribution after about 6 later updates. At alpha 0.98, the newest contribution was only 0.0276 of the oldest accumulated multiplier at the final readout.
That is a concrete way to see momentum in this setting: it is not just optimizer smoothing. It changes the age profile of the linear-attention state.

The state as it accumulates
The animation shows the fast-weight state matrix accumulating rank-one writes over the sequence. The still below tracks the top singular direction; by the end, the top singular component held 0.3573 of the singular energy in this run.

Open the state-evolution animation.
What the paper claims vs. what I found
| Question | Paper | This repro |
|---|---|---|
| Is TTT-KV binding literally unrollable as linear attention? | Yes, for a broad class with a bias-free final layer. | Yes, in the isolated final-layer setting; max output and state error were 0.0. |
| Does lower binding loss necessarily mean a better sequence operator? | No; extra inner steps can hurt real models. | No in the toy: binding MSE improved from 0.1452 to 0.1272, while output drift reached 0.2166 MSE. |
| Is gradient ascent fatal to the mechanism? | No; trained models can remain effective. | Not fatal algebraically, but my toy only shows sign symmetry, not recovered task accuracy. |
| Does this prove the paper's large-model claims? | The paper evaluates LaCT and ViTTT. | No. This is a mechanism check, not a benchmark reproduction. |
Run it
cd test-time-training-linear-attention
uv sync
uv run python -m ttt_linear_attention.run --out-dir figures
uv run pytest