Fast weights on the loop axis
Introduction
A looped Transformer runs the same small block of M layers for N passes on one input before reading out an answer. Instead of spelling out N chain-of-thought steps as text tokens, each pass refines the hidden state [B, T, D] in place — one loop pass per reasoning step (Saunshi et al., 2025; Geiping et al., 2025).
The catch shows up at test time when you keep looping well past the training budget (N_test >> N_train). Le et al. (2026) group the failures into two problems:
- Signal washout vs. memory blowup. Carrying only the latest vector
h[B, T, D]overwrites earlier hypotheses on every pass. Keeping all past passes on a shelf for softmax attention fixes recall atN = 3, and blows up linearly in memory atN = 160(13.6 MB → 1,098 MBin our A100 benchmark). - Latent overthinking. All
Ttokens in a sequence loop together. Easy tokens finish at Pass 4; hard multi-hop tokens need Pass 80. Dragged through 150 extra passes, state-blind update rules keep nudging already-solved tokens until right answers flip back to wrong.
Hypothesis. In Linear attention: a memory that is learned, we replaced a growing token KV cache with a fixed-size fast-weight matrix S [dk, dv] updated by the delta rule, S = a * S + b * outer(k, v - k @ S). Dropping softmax across tokens hurt exact sequence recall. Here we leave Softmax Attention across tokens T completely alone, and put S [dk, D] on the loop axis N instead:
- Across tokens (
T): ordinary Softmax Attention — tokens talk to neighbors sharply. - Across loop passes (
N): each token owns two tinyfp32fast-weight scratchpads —S_attnfor attention updates andS_mlpfor MLP deductions — updated inside every layer by the delta rule (err = v - k @ S).
On 9×9 Sudoku-Extreme rolled out to 13.3× training depth (6,720 layer visits), per-layer S_attn + S_mlp (A3) adds +2.0% FLOPs per pass, more than doubles exact board solve rate over InfiLoop (21.04% → 42.63%), already beats 160-segment InfiLoop by segment 4 (33.64% at 39× less compute), and loses 0.00% of already-solved boards (Lost@160 = 0.00%).
Mental Picture: Looping in Prefill vs. Autoregressive Decode
Before looking at equations, two common confusions are worth clearing up:
- Fixed
Nacross the sequence (not token-dropping MoR). Mixture-of-Recursions (Bae et al., 2025) physically drops easy tokens out of the batch early so each token runs a different loop count. Neither Inkling-2 Mini nor our model drops tokens: the full[B, T, D]sequence loops together for allNpasses. On a board or prompt, unfinished hard tokens at Pass 80 still need to attend to the already-solved easy tokens — so easy tokens stay in the batch whileerr = v - k @ S -> 0keeps their stored state steady. - Autoregressive decode (
T = 1column loops; past tokens stay frozen). Sudoku has no token-by-token generation: all81squares enter together ([B, 81, D]), attend bidirectionally, loopNtimes, and output81digits at once (pure prefill). In a causal language model like Inkling-2 Mini (N = 3Core passes), decodingtok 3looks like this:
Past tokens (frozen in KV cache) Current token (ONLY column running)
tok 0 tok 1 tok 2 tok 3
Prelude [ K,V ] [ K,V ] [ K,V ] -----> runs once (appends K,V)
|
Pass 0 [ K,V ] [ K,V ] [ K,V ] =====> runs Pass 0 (reads Pass-0 row, appends K,V)
| S (or bank)
Pass 1 [ K,V ] [ K,V ] [ K,V ] =====> runs Pass 1 (reads Pass-1 row, appends K,V)
| S (or bank)
Pass 2 [ K,V ] [ K,V ] [ K,V ] =====> runs Pass 2 (reads Pass-2 row, appends K,V)
|
Coda [ K,V ] [ K,V ] [ K,V ] -----> runs once --> emits tok 4
- Only
tok 3loops. Past tokenstok 0..2do zero compute. - Horizontally (
K, Vcache): Because input features change from pass to pass,K_pass0 != K_pass1 != K_pass2. Each(layer, pass)visit caches its ownK, Vrow (M × NKV rows total — the same KV cache size as an unloopedM·N-layer model, withN×fewer layer weights). - Vertically (
Sorbank): Lives strictly insidetok 3’s column across Pass0 → N-1, and is thrown away as soon astok 3emitstok 4(0bytes added to long-context KV cache). And the only causal mask in the entire model is standards <= tinside token Softmax Attention during prefill (Snever mixes tokentwitht', and passes run sequentially infor p in range(N)).
Loop Architectures on One M × N Map
Every looped model answers two routing questions:
- Vertical (
m = 0 .. M-1, within one pass): how layers inside one pass hand activations down. - Horizontal (
p = 0 .. N-1, across passes): what state crosses from Passp-1into Passp.
| Design | Cross-pass state | How it writes at pass p |
Behavior at N = 160 (13.3× train depth) |
|---|---|---|---|
| Huginn / Carry-last (Geiping et al., 2025) | [1, B, T, D] |
Overwrites h <- Block(h + x0) |
Prompt x0 stays sharp, but intermediate hypotheses from earlier passes get overwritten (20.85%). |
| MeSH (Yu et al., 2026) | [K, B, T, D] |
Step-indexed router W[p], additive M += w * h |
W[p] is undefined past N_train; + w * h piles up without bound (10× drift, 16.31%). |
| Inkling-2 Mini (AttnRes + 1-pass bank) | [2, B, T, D] |
Vertical Attention Residuals within pass; saves [B2, B3] from pass p-1 only |
Modulates Attention, K, V, and MoE separately via controllers, but overwrites bank every pass (Pass 0 is gone by Pass 2). |
| InfiLoop (Li et al., 2026) | [1, B, T, D] |
Confidence EMA num = b*num + w(z)*z |
Constant memory, but 1 vector blurs Attention & MLP updates and w(z) never checks what memory already holds (21.04%, Lost@160 = 3.4%–7.7%). |
Loop Gated-Delta (A3, Ours) |
2 × [dk, B, T, D] |
Per-sublayer S = a*S + b*outer(k, v - k@S) on S_attn & S_mlp |
Constant O(dk) memory, separate Attention/MLP subspaces, error-checked writes (v - k@S), 42.63% & Lost@160 = 0.00%. |
Switch between the four designs below and hover (or click to pin) any block in Pass 2 or Pass N-1 to trace which earlier passes stay reachable:
The Loop Gated-Delta Cell in Python
In our testbed we skip vertical shelves and 6-layer buckets completely: vertically, each pass is just M = 2 plain post-RMSNorm Transformer layers. Fast weights live strictly on the loop recurrence.
At every layer m inside pass p, Attention produces a_out [B, T, D], writes into S_attn [B, T, dk, D] in float32, and reads o = q @ S_attn right back (so Layer 1 immediately sees what Layer 0 just wrote inside the same pass):
def loop_delta_step(v, S, cell):
"""One write-then-read fast-weight step on S_attn or S_mlp (state math in fp32).
v: [B, T, D] sublayer output (a_out or m_out)
S: [B, T, dk, D] per-token fast-weight scratchpad (S_attn or S_mlp)
"""
vn = rms_norm(v) # [B, T, D]
k = F.normalize(vn @ cell.W_k.T, p=2, dim=-1) # [B, T, dk] ||k||_2 = 1
q = F.normalize(vn @ cell.W_q.T, p=2, dim=-1) # [B, T, dk]
alpha = torch.sigmoid(vn @ cell.W_a.T + cell.alpha_bias) # [B, T, dk] per-row retention
S = alpha.unsqueeze(-1) * S # [B, T, dk, D]
pred = torch.einsum('btk,btkd->btd', k, S) # [B, T, D] what S already holds at k
err = v - pred # [B, T, D] surprise (0 if v == pred!)
beta = torch.sigmoid(vn @ cell.w_b.T + cell.b0) # [B, T, 1] step size (A4 adds -pn @ w_p.T)
S = S + beta.unsqueeze(-1) * torch.einsum('btk,btd->btkd', k, err) # outer(k, err)
o = torch.einsum('btk,btkd->btd', q, S) # [B, T, D] q @ S
g = torch.sigmoid(vn @ cell.w_g.T + cell.g0) # [B, T, 1] blend gate
return (1.0 - g) * v + g * o, S # [B, T, D], [B, T, dk, D]And the full M × N pass is 12 lines:
S_attn = torch.zeros(B, T, dk, D, dtype=torch.float32)
S_mlp = torch.zeros(B, T, dk, D, dtype=torch.float32)
for p in range(N_passes):
x = h + x0 # [B, T, D] re-inject input clues
for m in range(M):
a_out = layers[m].softmax_attn(x) # [B, T, D] across T tokens
u_attn, S_attn = loop_delta_step(a_out, S_attn, attn_cell) # [B, T, D] across passes & layers
x = rms_norm(x + u_attn)
m_out = layers[m].mlp(x) # [B, T, D]
u_mlp, S_mlp = loop_delta_step(m_out, S_mlp, mlp_cell) # [B, T, D]
x = rms_norm(x + u_mlp)
h = xWhy err = v - k @ S Stops Overthinking
Compare what happens on Pass 95 when an already-solved square emits v:
- Additive EMA (
InfiLoop/LOOM/MeSH): updatesnum = b * num + w(v) * v.w(v)never looks at what memory already holds, and every pass keeps piling vectors into a single slot. - Delta rule (
A3): computespred = k @ Sfirst and only writes the discrepancyerr = v - predalong rank-1 directionk(leaving alldk - 1orthogonal directions inSuntouched). Whenevervagrees withpred,err = 0and the write vanishes on its own. (We also testA4, which subtractsrms_norm(pred) @ w_pinsidebetaas a second explicit brake — see Round 2 below for a nice surprise.)
FLOPs and State Size
The goal of looping is efficient reasoning: spending extra matmul FLOPs at test time only when a hard input needs them.
Count every matrix operation in one call of our M = 2-layer shared block (D = 512, T = 97 tokens, SwiGLU width 3D = 1536, dk = 8, 1 multiply-add = 2 FLOPs):
- Attention matmuls (
2layers):qkv,QK^T,PV,W_o=16·D² + 8·T·D(4.59MFLOPs / token) - MLP matmuls (
2layers):gate_upanddown=36·D²(9.44MFLOPs / token) - Backbone total per block call:
52·D² + 8·T·D=14.01MFLOPs / token (28.5 GFLOPs/ board / segment)
Adding the matrix ops inside each loop-memory rule (W_k, W_q, W_a, k @ S, outer(k, err), q @ S):
| Method | State kept / token | Extra loop-update FLOPs / token | Total FLOPs / token / call | Total over R calls |
|---|---|---|---|---|
carry_last |
D (512 nums) |
0 |
14.01M (1.00×) |
O(R) |
infiloop (B0) |
D + 1 (513 nums) |
7·D (3.6K) |
14.02M (1.00×) |
O(R) |
full_attn (attend all r calls) |
r · D (grows!) |
~2·r·D (grows every call!) |
17.45M @ r=3360 (1.25×) |
O(R²) |
gd_single_pass (A1) |
dk · D (4,096 nums) |
13·dk·D + 4·D (55.3K) |
14.07M (1.004×) |
O(R) |
gd_dual_pass (A2) |
2 · dk · D (8,192 nums) |
26·dk·D + 8·D (110.6K) |
14.12M (1.008×) |
O(R) |
gd_dual_layer (A3) |
2 · dk · D (8,192 nums) |
52·dk·D + 16·D (274.4K) |
14.28M (1.019×) |
O(R) |
gd_dual_layer_pred (A4) |
2 · dk · D (8,192 nums) |
52·dk·D + 24·D (278.5K) |
14.29M (1.020×) |
O(R) |
Almost all matrix ops sit in Attention and MLP (14.01M). Updating both S_attn and S_mlp at every sublayer (A3) adds +1.9% FLOPs per pass, while S (32 KB of fp32 per token) is small enough to stay in SRAM inside a fused Triton kernel. (In unfused eager/compiled PyTorch below, reading/writing fp32 S to HBM at every sublayer accounts for the wall-clock gap between B0 and A3.)
Experiments & Ablations on Sudoku-Extreme
Dataset and Metrics
We train and test on Sudoku-Extreme (from the same benchmark suite as Maze-Hard and ARC-AGI-2):
- 81 squares = 81 tokens. Each board has easy 1-hop squares (7–8 neighbors already filled, solvable on Pass 1) sitting right next to hard multi-hop squares (requiring a 20–40 step chain of eliminations across rows, columns, and
3×3boxes). - Controlled CRN setup. Every arm shares the exact same
6.8M-parameterM = 2-layer backbone (D = 512, H = 8, seed991231), trained for14,400steps (B = 384,1,000base puzzles augmented to1M) using12segments (504layer visits). - Test-time rollout (
2,048held-out puzzles,1to160segments):1×(12segments),4×(48segments),13.3×(160segments =6,720layer visits): test loop count relative to training (12segments), reporting Exact Board % (all81 / 81squares right).Lost@160↓ (Overthinking): out of boards already solved at1×, what%get broken by looping out to160.Gained@160↑ (Extra Reasoning): out of boards still unsolved at1×, what%get newly solved by looping out to160.
Round 1: Surveying 7 Baseline Loop Memories
Before building the full per-layer Gated-Delta ladder, our first 7-arm sweep tested existing cross-loop designs head-to-head (toggle Round 1 in the chart above):
| Loop Memory | State Shape | 1× (12) |
4× (48) |
13.3× (160) |
Lost@160 ↓ |
Gained@160 ↑ |
Drift@160 |
|---|---|---|---|---|---|---|---|
last_lookup (recursive 1-slot Δ) |
[1, B, T, D] |
23.14% | 27.00% | 27.20% | 0.42% | 5.40% | 0.205 |
kda_loop (v1) (8-slot bf16 Δ) |
[8, B, T, D] |
19.43% |
20.90% |
20.85% |
0.50% | 1.88% |
0.204 |
carry_last |
[1, B, T, D] |
18.46% |
20.70% |
20.85% |
0.00% |
2.93% |
0.372 |
infiloop (scalar additive EMA) |
[1, B, T, D] |
20.21% |
21.24% |
20.61% |
7.73% | 2.45% |
0.634 |
loom_ema (static uniform EMA) |
[1, B, T, D] |
21.04% |
20.61% |
20.41% |
8.12% | 1.36% |
0.825 |
window_8 (raw 8-step buffer) |
[8, B, T, D] |
11.33% |
15.87% |
16.89% |
0.00% |
6.28% |
0.067 |
mesh (step-indexed additive) |
[8, B, T, D] |
16.89% |
16.60% |
16.31% |
4.05% |
0.12% |
6.037 |
Round 1 surfaced three findings — and one crucial systems bug:
- Additive step-routers fail past
N_train:MeSHloses−4.85%of cells (72.49% → 67.64%) as its additive slot state drifts10.2×off-manifold (0.59 → 6.04). - State-blind EMAs overthink:
InfiLoopandLOOMcorrupt ~1 in 12 already-solved boards (Lost@160 = 7.7%–8.1%), whereas state-comparing delta updates (last_lookup,kda_loop) cutLost@160by15×(0.42%–0.50%). - Why
kda_loop(v1) stalled at20.85%(bfloat16state underflow): Auditingkda_loop(v1)’s tensors showed that storingSinbfloat16(ulp(1.0) = 2^-7 ≈ 0.0078) rounded66%–97%of small delta updates down to exact zero whenever step sizes dipped below0.004!
Round 2: The 5-Arm fp32 Gated-Delta Ablation Ladder
Moving S to strict IEEE-754 float32 (torch.autocast(..., enabled=False)) and using textbook rank-1 outer(k, v - k @ S) updates (dk = 8), we change one architectural piece per row:
| Arm | Loop Memory | S Split |
Write Granularity | beta Gate |
1× (12) |
4× (48) |
13.3× (160) |
Lost@160 ↓ |
Gained@160 ↑ |
Cell@160 |
|---|---|---|---|---|---|---|---|---|---|---|
| B0 | infiloop (baseline) |
1 scalar EMA | End of pass | w(v) only |
20.07% |
21.53% |
21.04% |
3.41% |
2.08% |
65.24% (−9.1%) |
| A1 | gd_single_pass |
1 shared S [8, D] |
End of pass | sigmoid(vn @ w_b) |
18.31% |
8.30% |
5.32% |
70.93% |
0.00% |
72.92% (−0.8%) |
| A2 | gd_dual_pass |
S_attn + S_mlp |
End of pass | sigmoid(vn @ w_b) |
23.49% |
25.54% |
25.73% |
0.83% |
3.19% |
75.82% (+0.3%) |
| A3 | gd_dual_layer |
S_attn + S_mlp |
Every sublayer (p, m) |
sigmoid(vn @ w_b) |
40.38% | 42.43% | 42.63% | 0.00% | 3.77% | 80.89% (+0.4%) |
| A4 | gd_dual_layer_pred |
S_attn + S_mlp |
Every sublayer (p, m) |
sigmoid(vn@w_b − pn@w_p) |
37.65% |
38.92% |
39.11% |
0.00% | 2.35% |
80.18% (+0.2%) |
Every step on the ladder tells a clean story:
B0(InfiLoopbaseline,21.04%): Peaks at3×depth (21.68%), then regresses to21.04%at160segments (Lost@160 = 3.41%) while individual cell accuracy collapses−9.06%(74.30% → 65.24%).A1(1sharedSat pass end,5.32%): Dumping the combined post-pass vectorxinto a singleSoutside the residual stream collides Attention’s cross-square routing updates with MLP’s digit-deduction updates — cell accuracy stays72.92%, while flipping 1–2 hard squares per board drops81/81exact solve to5.32%.A1 → A2(Split intoS_attn + S_mlpinside residual stream,5.32% → 25.73%): Giving Attention and MLP separate fast-weight matrices — still updated only once per pass — jumps13.3×accuracy by+20.41 pts, beatsB0by+4.69 pts, and cutsLost@1604×(3.41% → 0.83%).A2 → A3(Write & read at every sublayer,25.73% → 42.63%,+0params): LettingLayer 0write toS_attn, S_mlpandLayer 1immediately read them inside the same pass (6,885,416params — identical toA2,+1.1%FLOPs) adds another+16.90 pts:- More than
2×InfiLoop(42.63%vs21.04%). 39×FLOP efficiency: By Segment4(114 GFLOPs/board),A3already solves33.64%of puzzles —12.6 ptshigher thanInfiLoopat Segment160(4,566 GFLOPs/board,21.04%).- Zero latent overthinking (
Lost@160 = 0.00%): Across all827puzzles solved at1×depth, not a single board breaks out to160segments (6,720layer visits), while extra passes newly crack+46harder boards (40.38% → 42.63%,Exact == Oracleat every depth).
- More than
A3 → A4(Doesbetaneed- pn @ w_p? No —39.11%vs42.63%): On a tiny150-step4×4sanity test, subtractingrms_norm(pred) @ w_pinsidebetahelped early steps (65.6%vs46.9%). Over full14,400-step9×9training, however, standard textbook Gated-Delta (A3) already achievesLost@160 = 0.00%becauseerr = v - k @ Snaturally shrinks to zero asvconverges toS. Adding a second brake insidebeta(A4) keepsLost@160 = 0.00%too, and slightly dampens late multi-hop gains (Gained@160 = 2.35%vsA3’s3.77%). Simpler wins.
Papers
- Saunshi, Nishikawa, Singh, Reddi, Kumar, “Reasoning with Latent Thoughts: On the Power of Looped Transformers”, arXiv 2502.17416, ICLR 2025.
- Geiping et al., “Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach (Huginn)”, arXiv 2502.05171, 2025.
- Bae et al., “Mixture-of-Recursions: Learning Dynamic Recursive Depths for Adaptive Token-Level Computation (MoR)”, arXiv 2507.10524, 2025.
- Yang, Kautz, Hatamizadeh, “Gated Delta Networks: Improving Mamba2 with Delta Rule”, arXiv 2412.06464, ICLR 2025.
- Schlag, Irie, Schmidhuber, “Linear Transformers Are Secretly Fast Weight Programmers”, arXiv 2102.11174, ICML 2021.
- Yu et al., “MeSH: Memory-as-State-Highways for Looped Transformers”, ICLR 2026.
- Li, Muhtar, He, Su, Yin, Liu, “Scaling to Tens of Thousands of Test-Time Iterations with Loop-Native Attention Residuals (InfiLoop)”, arXiv 2610.11570, 2026.
- Le et al., “Looped Transformers: Architecture, Training, and Inference”, arXiv:2611.35712v2, 2026.