Sam Babichenko

Reading notes / Efficient sequence models

Context stored in weights

Tandon et al., 2025; Wang et al., 2026

End-to-End TTT
NNcontext length in tokens; the paper writes TT
xtx_ttoken tt of the context, t=1,…,Nt=1,\dots,N
WWfast weights, the weights written at test time; the MLPs of the last quarter of blocks
wwattention window, 8K tokens in the main runs; the paper writes kk
pWp_Wthe model's next-token distribution with fast weights WW
ℓt(W)\ell_t(W)−log⁡pW(xt∣x<t)-\log p_W(x_t\mid x_{\lt t}), the next-token loss at token tt
bbmini-batch size of the test-time steps, 1K tokens
BiB_ithe ii-th mini-batch of bb consecutive tokens
η\etalearning rate of the test-time steps
W0,W_0, WiW_istarting fast weights, learned in training; fast weights after ii steps
L(W0)\mathcal L(W_0)outer loss: each token's loss under the fast weights held when it arrived
Encoding context (Wang et al.)
cjc_jchunk jj of the context, at most 1,024 tokens; the paper writes ctc_t
uju_jrandom identifier of chunk jj; the paper writes iti_t
rjr_jsentence from a fixed template naming chunk jj as conversational context; the paper writes btb_t
WWalso the fast weights here, the final MLP layer by default; the paper writes ϕ\phi
In-Place TTT (Feng et al.)
WidownW^{\rm down}_ioutput matrix of an MLP after ii chunks; the paper writes Wdown(i)W^{(i)}_{\rm down}
ZiZ_iMLP hidden activations of chunk ii, one row per token
V^i\hat V_itargets of chunk ii, a learned convolution and projection of token embeddings

Context. A transformer stores every earlier token's key and value so it can attend back to any detail. Memory and step time grow with context length. attention whose exponential score is replaced by a product of feature maps of query and key, so that the past is summed into one matrix of fixed size, updated by one outer product per token (Katharopoulos et al., 2020) and state-space layers hold a fixed-size state instead, at the cost of long-range accuracy. training a model on the input it is currently processing, while it makes its predictions; for a sequence, gradient steps on the tokens already read (Sun et al., 2024) takes a third route. As the model reads the context, it takes gradient steps on those tokens and writes the context into a subset of its weights, called the weights that are changed at test time for the current input and reset before the next one; all other weights stay as training left them. Per-token cost stays constant, as in a recurrent layer, while the state can be as large as the chosen weights.

Storing context in weights compresses it, and compression loses exact recall. End-to-End test-time training (End-to-End TTT; Tandon et al., 2025) adds next-token gradient steps to a transformer with an 8K sliding attention window. Its starting weights are meta-learned for those updates. At 3B parameters, its loss drops from 8K to 128K tokens about as much as full attention's while keeping per-token cost constant. Yet at 128K tokens it retrieves a single hidden string only 6% of the time, against 99% for full attention. That matches the 6.25% chance that an evenly placed string lands inside its 8K window.

Wang et al. (2026) write context into released models with no meta-training. On three Qwen3.5 models, the address under which a chunk is written largely decides whether the model can use it. After a plain next-token write of a short statement, the models answer a direct question about it in at most 6.1% of cases. Writing each chunk after a random identifier and a sentence naming it as context, then listing the identifiers in the prompt, makes the text retrievable. On the same written weights, the correct identifier retrieves a single string hidden in repetitive filler in 84% to 100% of cases, against 1% to 8% for a decoy identifier of the same length. Weights work as gist memory, not as lookup. Unaddressed, a write keeps exact strings only on that easy task, and even addressed writes fall well short of in-prompt context on harder needles and real documents.

Setting: End-to-End TTT. Write x1,…,xNx_1,\dots,x_N for a context of NN tokens and WW for the fast weights, here the MLP weights of the transformer's last quarter of blocks. All other weights stay fixed while the model reads the context. The model reads earlier tokens through causal attention restricted to the last ww tokens, so each head caches at most ww keys and values (Beltagy et al., 2020) over the last ww tokens (8K in the main runs) and through WW. Write pWp_W for the next-token distribution under fast weights WW, and ℓt(W)=−log⁡pW(xt∣x<t)\ell_t(W)=-\log p_W(x_t\mid x_{\lt t}) for the loss at token tt. The context splits into mini-batches B1,B2,…B_1,B_2,\dots of bb consecutive tokens (1K in the main runs). At test time, the inner loop takes one gradient step with learning rate η\eta per mini-batch. During training, the outer loss scores each token with the fast weights held when it arrived:Wi=Wi−1−ηb∑t∈Bi∇ℓt(Wi−1),L(W0)=1N∑i∑t∈Biℓt(Wi−1).\begin{aligned}W_i&=W_{i-1}-\frac{\eta}{b}\sum_{t\in B_i}\nabla\ell_t(W_{i-1}),\\ \mathcal L(W_0)&=\frac1N\sum_i\sum_{t\in B_i}\ell_t(W_{i-1}).\end{aligned}

Training minimizes L\mathcal L over W0W_0 and the fixed layers by differentiating through the inner updates. That requires gradients of gradients, as in model-agnostic meta-learning: the starting point of a few gradient steps is trained by differentiating the loss after those steps with respect to it (Finn et al., 2017). Every token in mini-batch BiB_i is scored with Wi−1W_{i-1}, which has seen none of its own mini-batch. The attention window must therefore be at least as long as a mini-batch, why: without it, tokens early in a mini-batch would be invisible to later tokens of the same mini-batch, since the weights update only after it ends.

Meta-learning the starting weights makes the test-time steps useful. continuing to train an ordinary pretrained language model on the test text as it is read, with no change to how it was trained (Krause et al., 2018) takes the same kind of test-time steps, but trains W0W_0 as if no update will follow. For b=1b=1, the two training objectives differ only in which weights score token tt:Lnaive(W0)=1N∑tℓt(W0),L(W0)=1N∑tℓt(Wt−1).\begin{aligned}\mathcal L_{\rm naive}(W_0)&=\frac1N\sum_t\ell_t(W_0),\\ \mathcal L(W_0)&=\frac1N\sum_t\ell_t(W_{t-1}).\end{aligned}In a two-block transformer stripped of attention so it sees only the previous token, the naive objective barely improves over no memory. Meta-learning through L(W0)\mathcal L(W_0) brings the model close to the same model with full attention.

The written state must be large enough to hold long context. Past the 8K window, tokens reach predictions only through WW. In a 760M model with 24 blocks, updating the MLPs of only the last 1 or 3 blocks fails to keep pace with full attention as context grows. Updating 6 or 12 blocks does keep pace, and 12 does no better than 6. The paper therefore updates the last quarter of blocks at every scale.

Loss tracks full attention across context lengths. Each 3B model is pretrained on DataComp for Language Models, a filtered web-text corpus; the runs use its 3.8T-token DCLM-Baseline subset, keeping documents of at least 8K tokens at 8K tokens and fine-tuned separately on a standard academic corpus of long books, used here for long-context fine-tuning and, through a held-out part, for evaluation at each length from 8K to 128K. Evaluation measures mean next-token loss in nats on held-out books. From 8K to 128K, End-to-End TTT's loss falls from 2.314 to 2.249 and stays 0.012 to 0.014 nats below full attention at every length. Every other fixed-cost architecture tested has a higher loss at 128K than at 32K. That includes sliding-window attention alone and hybrids mixing sliding windows with a state-space layer that keeps a fixed-size state with a learned, input-dependent decay (Dao and Gu, 2024), a linear-attention layer whose update reads the value stored under the current key and moves it toward the new value, with a learned decay (Yang et al., 2025), or test-time training with key-value binding: each block has its own small network, trained at test time to map each token's key projection to its value projection; with a linear network this is DeltaNet's update (Sun et al., 2024; Zhang et al., 2025). process the given context before the first new token is generated time per token stays flat with length, running 2.7 times faster than full attention at 128K on an H100.

The loss advantage of End-to-End TTT over full attention is largest early in the context and is already there before the first weight update. On the 128K model, End-to-End TTT sits below full attention at every token position, by about 0.05 nats over the first 1,000 tokens and about 0.01 past 32K. No update occurs before token 1,024, so both models attend over the exact same tokens with different trained weights. That early gap comes from the meta-learned weights rather than stored context. Past the 8K window, the writes do carry context. Sliding-window attention nearly flattens past 8K, while End-to-End TTT keeps falling alongside full attention. Its lead over the window-only model widens from about 0.04 nats before 8K to about 0.06 past 32K. Weighted by token count, about half of the 128K model's average lead over full attention still comes from tokens past 32K, by a rough integration of the curves computed here.

On exact recall, End-to-End TTT matches its sliding window and adds nothing measurable. On the simplest single-needle task of a synthetic long-context benchmark whose needle-in-a-haystack tasks hide a key and a value in filler text and ask for the value at the end (Hsieh et al., 2024), a numeric pass key hidden in repeated filler, every 3B model fine-tuned at 128K scores at least 0.98 at 8K. Beyond 8K, retrieval falls in step with the fraction of evenly placed needles landing inside the last 8K tokens (bottom row, computed here).
Single-needle retrieval, fraction of 1
Model16K32K64K128K
Full attention1.001.001.000.99
Sliding window0.500.260.130.07
End-to-End TTT0.460.240.130.06
8K ÷ length0.500.250.1250.0625
End-to-End TTT retrieves about as often as the needle lands in its 8K window, matching the window alone. The weight updates add nothing measurable to exact recall.Mamba 2 and Gated DeltaNet follow the same pattern, scoring 0.07 at 128K.The authors suggest that compression discards details that look irrelevant, such as an isolated pass key.

Plain writes into released models rarely answer direct questions. Wang et al. (2026) instead write context into already-released models with no meta-training. They split a context into chunks c1,c2,…c_1,c_2,\dots of at most 1,024 tokens and update the fast weights, by default the final MLP layer. On each chunk, Adam steps minimize the next-token loss −log⁡pW(cj)-\log p_W(c_j) until every token's loss falls below 0.1 or 256 steps finish. The text is then removed from the prompt. Their recall test uses 197 synthetic 11-token statements such as "The registry code of Korvustre Wharf is GC-483". When the statement stays in the prompt, Qwen3.5 models at 4B, 9B, and 27B answer "What is the registry code of Korvustre Wharf?" nearly perfectly. After a plain write, they answer correctly in only 1.5% to 6.1% of cases.

Addressable writes raise recall by pairing an identifier with a context sentence. ACE, the method of Wang et al. (2026): each chunk is written conditioned on a random identifier and on a sentence that names it as conversational context, and the prompt at question time lists the identifiers (ACE) assigns chunk jj a random identifier uju_j, such as ctx-573277c6, and prepends a framing sentence rjr_j from a fixed template. The template reads: "The following text is a context chunk from the current conversation at [time], identified by [uju_j]. It has been encoded into the model and should be treated as conversational context whenever it is invoked:" The write loss sums two terms:−log⁡pW(cj∣uj)−log⁡pW(rj,cj).\begin{aligned}&-\log p_W(c_j\mid u_j)\\&-\log p_W(r_j,c_j).\end{aligned}The first trains the chunk to follow its identifier, and the second trains it to appear with the framing sentence. Listing the identifiers in the prompt with an instruction to use them lifts recall from at most 6.1% to between 35.5% and 75.6%, depending on the model and wording. Both terms are necessary. Dropping either cuts recall, and an identifier trained with only the first term and named without an instruction leaves recall at 0.5% to 5.6%.

Fixed-weight decoy test: the identifier gates retrieval. Wang et al.'s sharpest control holds the ACE-written weights fixed and swaps only the cue on RULER's simplest needle task, across 100 cases of 1,024 tokens with no instruction prompt. On Qwen3.5-4B, 9B, and 27B, the correct identifier retrieves 84% to 100% of needles, while a decoy identifier of equal length retrieves 1% to 8%. The needle sits in the weights in both runs. Yet the wrong cue scores far below a plain write read with no identifier, which retrieves 85% to 98% of needles on the same models and task.

Harder needles and real documents expose the gap to in-prompt context. RULER's two harder needle tasks use more realistic filler and more complex needles. Plain writes retrieve 7% on the first and at most 1% on the second, while ACE reaches 17% to 40% and 15% to 29%, against 100% with the text in the prompt. On 100 a benchmark of question answering over long documents; this test uses 100 questions with contexts of 2K to 7K tokens, scored by the word overlap (F1) between answer and reference (Bai et al., 2024) questions, ACE reaches 9.0 to 9.8 F1 on Qwen3.5, barely above plain writes at 7.9 to 8.8 and about half the 18.9 to 20.8 with the document in the prompt. A 30B model from another family, Muse-Glimmer-30B, comes much closer at 19.2 against 21.2. At 64K tokens on RULER's simplest needle, written in roughly 1,024-token chunks, ACE retrieves 30% to 80% across three models against 100% with the full context. Every 64K score is a multiple of 10 points, suggesting roughly ten cases per model.

A contradicting write seems to override a known fact in most cases. In Wang et al.'s counterfactual test, the written statement contradicts world knowledge, such as "The capital of Peru is Arequipa." Asked for the capital according to the context, ACE models answer Arequipa in 86.5% to 96.0% of 200 cases. Asked with the same weights for the generally known capital while setting the context aside, they answer Lima in only 25.5% to 39.0% of cases. On paired control questions about uncontradicted facts, they answer correctly in 76.0% to 82.5% of cases. Dropping the instruction prompt yields Lima in 29.0% to 35.5% of cases, so the prompt does not explain the drop.

In-Place TTT: additive chunk writes without reading the stored weights. Feng et al. (2026) add test-time writes to pretrained transformers that keep full attention. Their update modifies the MLP output matrix WdownW^{\rm down} in every sixth block. For chunk ii, write ZiZ_i for the MLP hidden activations, with one row per token. A learned convolution and projection map token embeddings to targets V^i\hat V_i that can look ahead to next tokens. After the model processes chunk ii with the current weights, one gradient step on −⟨Zi(Wdown)⊤,V^i⟩-\langle Z_i(W^{\rm down})^\top,\hat V_i\rangle writesWidown=Wi−1down+η V^i⊤Zi.W^{\rm down}_i=W^{\rm down}_{i-1}+\eta\,\hat V_i^\top Z_i.This step ignores what Wi−1downW^{\rm down}_{i-1} already holds. After ii chunks, the matrix equals W0downW^{\rm down}_0 plus a sum of outer products, matching a chunk-wise linear-attention state (observed here). The S←S−βk(k⊤S−v⊤)S\leftarrow S-\beta k(k^\top S-v^\top): read the value stored under the key kk, and move it toward the new value vv by a fraction β\beta (Schlag et al., 2021) instead reads what is stored under each key before replacing it.

When full attention stays in place, recall can rely on attention. Training and running with In-Place TTT still adds a few RULER points: on continually trained Qwen3-4B-Base at 64K, the score rises from 74.3 to 78.7. The writes matter more without full attention. A 4B model pretrained from scratch at 8K with sliding-window attention jumps from 9.91 to 26.80 on RULER at 8K when writes are added. It still trails the 38.09 of full attention without writes.

In practice. End-to-End TTT cannot replace attention when exact distant strings matter. The authors treat the fast weights as long-term memory paired with the sliding window as short-term memory. Meta-training is slow at short contexts because gradients of gradients rule out fused attention kernels. On an H200, it takes 3.4 times as long per token as full attention at 8K and turns 1.2 times faster only at 128K. To write a document into a released model's weights, Wang et al.'s results recommend pairing a random identifier with a framing sentence and naming that identifier at query time. Expect a contradicted world fact to return in only a minority of cases. Writing pays off only when many queries reuse the same context. On one LongBench v2 example, encoding costs 6 to 19 times the FLOPs of answering one question with full context and no cached prefill. Each subsequent query then costs 20 to 24 times fewer FLOPs (computed here from the paper's table).

What is well controlled. Tandon et al. run the recurrent baselines with their authors' code and configurations. They sweep the fine-tuning learning rate only for full attention and reuse it for every method, including End-to-End TTT, which if anything favors full attention. Setting bb to the 8K pretraining length switches off test-time updates and leaves the modified architecture at 2.825 against 2.827 for full attention. That isolates the gain to the updates and meta-learned weights. Both the needle collapse, which tracks the 8K-window share, and Wang et al.'s fixed-weight decoy swap are direct, large effects.

Where the evidence stops. Tandon et al.'s loss margins are small, with no repeated runs or error bars reported. Their results stop at 3B parameters and omit downstream tasks. Wang et al. test templated synthetic statements on four released models with no repeated runs and compare only against plain writes rather than prompt retrieval. They report the best of three instruction wordings, and the winner varies by model. On Qwen3.5-27B, recall reaches 75.6% with the shortest wording against 39.1% with the default. Their counterfactual test reports no score for unmodified models and does not distinguish erasing an old fact from outweighing it. In-Place TTT reports one training run per model and never separates test-time writes from training with them. None of these papers yet has an independent replication.

Terms

Test-time training
gradient steps on the context while reading it, so the context is stored in fast weights
End-to-End TTT
next-token loss in the inner loop; starting weights W0W_0 trained through the inner steps (gradients of gradients)
Outer loss
L(W0)=1N∑i∑t∈Biℓt(Wi−1)\mathcal L(W_0)=\frac1N\sum_i\sum_{t\in B_i}\ell_t(W_{i-1}); the naive recipe scores ℓt(W0)\ell_t(W_0)
Recipe
8K sliding window, one step per 1K tokens, MLPs of the last quarter of blocks updated
Loss scaling
3B: 2.314 to 2.249 from 8K to 128K, 0.012 to 0.014 below full attention at every length
Needle at 128K
full attention 0.99, End-to-End TTT 0.06, window alone 0.07; 8K/128K is 0.0625
Early-token gap
present before the first update at token 1,024, so that part comes from the trained weights
Plain write
−log⁡pW(cj)-\log p_W(c_j) on each chunk; a direct question about a short statement is answered in 1.5% to 6.1% of cases
ACE
−log⁡pW(cj∣uj)−log⁡pW(rj,cj)-\log p_W(c_j\mid u_j)-\log p_W(r_j,c_j), identifiers named in the prompt
Decoy test
same weights: correct identifier 84% to 100%, decoy of equal length 1% to 8%; a plain write gets this easy needle 85% to 98%
Harder tasks
harder needles: ACE 17% to 40% and 15% to 29%, against 100% in the prompt; LongBench F1 about half the in-prompt score
Overwrite
after a counterfactual write, the real fact comes back in 25.5% to 39.0% of cases
In-Place TTT
Widown=Wi−1down+ηV^i⊤ZiW^{\rm down}_i=W^{\rm down}_{i-1}+\eta\hat V_i^\top Z_i; additive write, update capped at norm 10−510^{-5} in evaluation

Sources

Connected notes

  • The ordinary residual stream already carries early layers forward. In an 8-layer model a value shortcut from layer 2 or later adds little, because H1H_1 is reachable through the stream, and it helps once the residual chain is started at H2H_2. Deep layers want the first-layer shortcut most, so a direct path helps where the single running sum no longer carries that information cleanly.

  • In five-step stress tests at width 64, the branch outputs of standard μ\muP add up to a residual stream with RMS about 33 at depth 1,000 at initialization, while Depth-μ\muP's branch multiplier 1/L1/\sqrt L holds it near 1.3 and gives the lowest loss at large depth after five updates. CompleteP's 1/L1/L holds it at 1.0 but overcorrects, since independently initialized blocks add like independent terms.

  • Sinkhorn-Knopp projects any positive matrix onto a unique doubly stochastic scaling DxADyD_xAD_y, which mHC runs for 20 iterations on the entrywise exponentials of its learned mixing matrices so multi-stream products stay bounded across depth.

  • PreNorm's unweighted running sum grows with depth and dilutes every earlier output, so Attention Residuals replace it with softmax-weighted averages over earlier block sums, bounding the mixed input by max⁡jRMS(vj)\max_j\mathrm{RMS}(v_j) while keeping direct shortcuts across depth without the matrix-product instability of multi-stream mixing.

Threads