Fast weights on the loop axis

attention
reasoning
looped-transformers
Giving looped Transformers an editable fast-weight scratchpad across passes doubles Sudoku-Extreme solve rate (21.0% → 42.6%) with zero lost boards at 13.3× test depth.
Published

December 1, 2026

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:

  1. 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 at N = 3, and blows up linearly in memory at N = 160 (13.6 MB → 1,098 MB in our A100 benchmark).
  2. Latent overthinking. All T tokens 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 tiny fp32 fast-weight scratchpads — S_attn for attention updates and S_mlp for 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:

  1. Fixed N across 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 all N passes. 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 while err = v - k @ S -> 0 keeps their stored state steady.
  2. Autoregressive decode (T = 1 column loops; past tokens stay frozen). Sudoku has no token-by-token generation: all 81 squares enter together ([B, 81, D]), attend bidirectionally, loop N times, and output 81 digits at once (pure prefill). In a causal language model like Inkling-2 Mini (N = 3 Core passes), decoding tok 3 looks 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 3 loops. Past tokens tok 0..2 do zero compute.
  • Horizontally (K, V cache): Because input features change from pass to pass, K_pass0 != K_pass1 != K_pass2. Each (layer, pass) visit caches its own K, V row (M × N KV rows total — the same KV cache size as an unlooped M·N-layer model, with N× fewer layer weights).
  • Vertically (S or bank): Lives strictly inside tok 3’s column across Pass 0 → N-1, and is thrown away as soon as tok 3 emits tok 4 (0 bytes added to long-context KV cache). And the only causal mask in the entire model is standard s <= t inside token Softmax Attention during prefill (S never mixes token t with t', and passes run sequentially in for p in range(N)).

Loop Architectures on One M × N Map

Every looped model answers two routing questions:

  1. Vertical (m = 0 .. M-1, within one pass): how layers inside one pass hand activations down.
  2. Horizontal (p = 0 .. N-1, across passes): what state crosses from Pass p-1 into Pass p.
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:

Vertical Axis (Within Pass p)
Horizontal Axis (Across Passes 0..p-1)

      

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 = x

Why err = v - k @ S Stops Overthinking

Compare what happens on Pass 95 when an already-solved square emits v:

  • Additive EMA (InfiLoop / LOOM / MeSH): updates num = 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): computes pred = k @ S first and only writes the discrepancy err = v - pred along rank-1 direction k (leaving all dk - 1 orthogonal directions in S untouched). Whenever v agrees with pred, err = 0 and the write vanishes on its own. (We also test A4, which subtracts rms_norm(pred) @ w_p inside beta as 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 (2 layers): qkv, QK^T, PV, W_o = 16·D² + 8·T·D (4.59M FLOPs / token)
  • MLP matmuls (2 layers): gate_up and down = 36·D² (9.44M FLOPs / token)
  • Backbone total per block call: 52·D² + 8·T·D = 14.01M FLOPs / 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×3 boxes).
  • Controlled CRN setup. Every arm shares the exact same 6.8M-parameter M = 2-layer backbone (D = 512, H = 8, seed 991231), trained for 14,400 steps (B = 384, 1,000 base puzzles augmented to 1M) using 12 segments (504 layer visits).
  • Test-time rollout (2,048 held-out puzzles, 1 to 160 segments):
    • 1× (12 segments), 4× (48 segments), 13.3× (160 segments = 6,720 layer visits): test loop count relative to training (12 segments), reporting Exact Board % (all 81 / 81 squares right).
    • Lost@160 ↓ (Overthinking): out of boards already solved at 1×, what % get broken by looping out to 160.
    • Gained@160 ↑ (Extra Reasoning): out of boards still unsolved at 1×, what % get newly solved by looping out to 160.

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:

  1. Additive step-routers fail past N_train: MeSH loses −4.85% of cells (72.49% → 67.64%) as its additive slot state drifts 10.2× off-manifold (0.59 → 6.04).
  2. State-blind EMAs overthink: InfiLoop and LOOM corrupt ~1 in 12 already-solved boards (Lost@160 = 7.7%–8.1%), whereas state-comparing delta updates (last_lookup, kda_loop) cut Lost@160 by 15× (0.42%–0.50%).
  3. Why kda_loop (v1) stalled at 20.85% (bfloat16 state underflow): Auditing kda_loop (v1)’s tensors showed that storing S in bfloat16 (ulp(1.0) = 2^-7 ≈ 0.0078) rounded 66%–97% of small delta updates down to exact zero whenever step sizes dipped below 0.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:

  1. B0 (InfiLoop baseline, 21.04%): Peaks at 3× depth (21.68%), then regresses to 21.04% at 160 segments (Lost@160 = 3.41%) while individual cell accuracy collapses −9.06% (74.30% → 65.24%).
  2. A1 (1 shared S at pass end, 5.32%): Dumping the combined post-pass vector x into a single S outside the residual stream collides Attention’s cross-square routing updates with MLP’s digit-deduction updates — cell accuracy stays 72.92%, while flipping 1–2 hard squares per board drops 81/81 exact solve to 5.32%.
  3. A1 → A2 (Split into S_attn + S_mlp inside residual stream, 5.32% → 25.73%): Giving Attention and MLP separate fast-weight matrices — still updated only once per pass — jumps 13.3× accuracy by +20.41 pts, beats B0 by +4.69 pts, and cuts Lost@160 4× (3.41% → 0.83%).
  4. A2 → A3 (Write & read at every sublayer, 25.73% → 42.63%, +0 params): Letting Layer 0 write to S_attn, S_mlp and Layer 1 immediately read them inside the same pass (6,885,416 params — identical to A2, +1.1% FLOPs) adds another +16.90 pts:
    • More than 2× InfiLoop (42.63% vs 21.04%).
    • 39× FLOP efficiency: By Segment 4 (114 GFLOPs/board), A3 already solves 33.64% of puzzles — 12.6 pts higher than InfiLoop at Segment 160 (4,566 GFLOPs/board, 21.04%).
    • Zero latent overthinking (Lost@160 = 0.00%): Across all 827 puzzles solved at 1× depth, not a single board breaks out to 160 segments (6,720 layer visits), while extra passes newly crack +46 harder boards (40.38% → 42.63%, Exact == Oracle at every depth).
  5. A3 → A4 (Does beta need - pn @ w_p? No — 39.11% vs 42.63%): On a tiny 150-step 4×4 sanity test, subtracting rms_norm(pred) @ w_p inside beta helped early steps (65.6% vs 46.9%). Over full 14,400-step 9×9 training, however, standard textbook Gated-Delta (A3) already achieves Lost@160 = 0.00% because err = v - k @ S naturally shrinks to zero as v converges to S. Adding a second brake inside beta (A4) keeps Lost@160 = 0.00% too, and slightly dampens late multi-hop gains (Gained@160 = 2.35% vs A3’s 3.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.