Core Cognition and Looped Transformers

draft
reasoning
architecture
looped-transformers
Maximizing accuracy per FLOP in a 6.8M 2-layer cognitive core via per-layer gated-delta memory and early stopping across Sudoku-Extreme (9×9) and Maze-Hard (30×30).
Published

December 1, 2026

Introduction

What Andrej Karpathy calls a cognitive core [1] strips away the billions of parameters spent memorizing static encyclopedic facts, leaving a small, dense engine dedicated purely to reasoning and spending extra test-time FLOPs by looping longer when a problem is hard. Looped Transformers are a natural fit for that core: Saunshi et al. [2] show that N loop iterations over shared layers can simulate N chain-of-thought steps in latent space, and recent models such as Huginn [3], Inkling 2 Mini [4], and InfiLoop [5] match or beat much larger unlooped Transformers on reasoning tasks at a fraction of the weight footprint.

Getting high accuracy per FLOP out of a small looped core comes down to two questions:

  1. How state flows from one loop to the next. Existing designs make very different choices: Huginn [3] overwrites a single hidden vector each pass; Inkling 2 Mini [4] passes the previous iteration’s block outputs through gated controllers; MeSH [6] adds step-routed vectors into a multi-slot buffer; and InfiLoop [5] keeps a confidence-weighted running average. (This cross-iteration axis is orthogonal to Attention Residuals [7], which mix earlier layers within a single forward pass to fix the Curse of Depth [8].) As iteration counts grow large, weak state flow leads to signal washout (forgetting useful intermediate work) and latent overthinking (corrupting tokens that were already solved on earlier passes) [9], [10].
  2. When to stop looping. Easy inputs settle in a few passes while hard inputs need dozens; running every input to a fixed maximum depth wastes FLOPs on solved problems and risks late-loop drift [10].

In this post, following InfiLoop [5], we hold a 2-layer cognitive core (6.8M parameters) fixed on Sudoku-Extreme (9×9, 81 tokens) [11] and Maze-Hard (30×30, 900 tokens) [12] and hillclimb accuracy / FLOP along both axes:

  • Introducing a gated-delta memory layer on Attention and MLP layers and updating this memory separately inside every layer (+1.5%–1.9% FLOPs/loop) [13] doubles exact solve rate on Sudoku-Extreme (21.0% → 42.6%) and raises 160-loop Maze-Hard solve rate from 5.3% to 19.4%. Putting both into one shared matrix collapses to 5.3% on Sudoku and 0.0% on Maze-Hard.
  • Zero latent overthinking. When looped 13×–27× past training depth (160–320 loops), 0.0% of already-solved Sudoku boards break, and training on 2× deeper loops (24 loops) climbs +14.3 points at test time to 54.8% (Appendix C).
  • By applying a simple stopping rule on this memory, we cut down FLOPs by 53%–87% and increase Maze-Hard performance by +2.7 points (19.2% → 21.9%). As a result, accuracy / TFLOP goes up 2.1×–2.3× on Sudoku (9.1 → 21.0% / TFLOP) and 8.6× on Maze-Hard (0.49 → 4.25% / TFLOP).
  • Further, we ablate across cross-loop designs (Carry-Last, LOOM, InfiLoop, MeSH, Window-8, and 1-Pass Bank Lookup), channel separation, update frequency, and training loop depth on the same 6.8M core across both tasks.

Information Flow Across Loop Iterations

When a small block of layers runs for dozens or hundreds of loop passes, keeping every earlier pass in memory for softmax attention grows linearly with loop count (>1 GB on Sudoku and >10 GB on Maze-Hard). Instead, looped Transformers compress past passes into a fixed-size state per token. Switch between the five designs below and hover any block in Pass 2 or Pass N-1 to see which earlier passes remain reachable:

Existing looped architectures compress cross-pass history in four main ways:

  • Carry-Last (Huginn) [3] passes only the last iteration’s output into the next pass, overwriting earlier intermediate steps.
  • Inkling 2 Mini [4] keeps block outputs from the immediately preceding pass and modulates how each layer reads them through attention-style gates, giving one-pass lookback.
  • MeSH [6] sums each pass’s output into a multi-slot memory buffer using step-indexed routers. Because those routers are tied to training step indices and writes only add without erasing, old guesses pile up when looping past training depth.
  • InfiLoop [5] keeps a confidence-weighted running average across all passes. Dividing by the running weight total keeps norms stable over hundreds of passes, but Attention and MLP collapse into one averaged vector without checking whether the token was already solved.

Our Design: Per-Layer Gated-Delta Memory

As covered in our earlier post on linear attention, Gated DeltaNet [13] replaces a growing cache with a fixed-size key-value matrix S ([dk, D]). Plain linear attention writes by simple addition (S += outer(k, v)), so writing twice under the same key piles the new value on top of the old one instead of replacing it. The delta rule fixes this in one line: it reads what S currently returns for key k (k @ S) and writes only the gap (v - k @ S), paired with two learned gates between 0 and 1: a forget gate alpha that fades stale rows of S, and a step size beta that sets how strongly to write.

We use this gated-delta matrix S as our cross-loop memory per token (dk = 8), with four design choices:

  • Separate memory for Attention and MLP (S_attn, S_mlp). Each Attention module and each MLP module keeps its own S matrix so peer-routing features and token-value deductions do not overwrite each other.
  • Update S at every vertical layer. During ablations (Appendix C), we found that updating S inside every vertical layer rather than once at pass end substantially improves accuracy at zero extra parameter cost, because Layer 1 immediately reads what Layer 0 just wrote.
  • Why (1 - g) * v + g * o appears on the loop axis. Unlike token-axis Gated DeltaNet, v here is fresh cross-token Attention/MLP work from the current pass while o = q @ S reads earlier passes from S, so a gate g preserves both (worked trace in Appendix A).
  • Equilibrium and early stopping. Once a token settles on an answer, the inflow beta * outer(k, err) balances the alpha decay so the net pass change S_after - S_before goes to zero (derivation in Appendix B).
def delta_step(v, S, cell):
    # v: [B, T, D] fresh sublayer output (Attention or MLP)
    # S: [B, T, dk, D] per-token loop memory matrix
    vn    = rms_norm(v)                                                    # [B, T, D]
    k     = F.normalize(vn @ cell.W_k.T, p=2, dim=-1)                      # [B, T, dk]
    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]
    beta  = torch.sigmoid(vn @ cell.w_b.T + cell.beta_bias)                # [B, T, 1]

    S     = alpha.unsqueeze(-1) * S                                        # decay old rows
    err   = v - torch.einsum('btk,btkd->btd', k, S)                        # gap vs. decayed state
    S     = S + beta.unsqueeze(-1) * torch.einsum('btk,btd->btkd', k, err) # write only the gap
    o     = torch.einsum('btk,btkd->btd', q, S)                            # read loop memory

    g     = torch.sigmoid(vn @ cell.w_g.T + cell.g_bias)                   # [B, T, 1] mix knob
    return (1.0 - g) * v + g * o, S                                        # blend fresh v + memory o

S_attn = torch.zeros(B, T, dk, D)
S_mlp  = torch.zeros(B, T, dk, D)
for p in range(N_passes):
    x = h + x0                                                             # re-inject input clues
    for m in range(M):
        v_attn         = layers[m].softmax_attn(x)                         # [B, T, D] fresh Attention
        u_attn, S_attn = delta_step(v_attn, S_attn, attn_cell)
        x              = rms_norm(x + u_attn)

        v_mlp          = layers[m].mlp(x)                                  # [B, T, D] fresh MLP
        u_mlp,  S_mlp  = delta_step(v_mlp,  S_mlp,  mlp_cell)
        x              = rms_norm(x + u_mlp)
    h = x

Tasks and Data Samples

We evaluate the identical 6.8M 2-layer core (D = 512, H = 8, seed 991231) on two grid reasoning tasks. Because 98%+ of FLOPs sit inside Attention and MLP, maintaining per-layer S_attn and S_mlp adds only +1.9% FLOPs per loop on Sudoku (29.2 GFLOPs/loop) and +1.5% FLOPs per loop on Maze-Hard (243 GFLOPs/loop).

1. Sudoku-Extreme (9×9, 81 Tokens)

Each Sudoku-Extreme [11] board pairs given clues (1..9) with blank squares (0) that often have 4–6 legal digits on Pass 0. Click through three held-out test boards below:

2. Maze-Hard (30×30, 900 Tokens)

Each Maze-Hard [12] grid has 900 tokens (11× longer than Sudoku) with shortest paths of 110 to 154 steps winding past 400+ dead-end decoy cells; exact solve rate requires all 900 tokens predicted simultaneously:

Results

Switch between Sudoku-Extreme (9×9) and Maze-Hard (30×30) below to compare exact solve rate, Acc / TFLOP, broken puzzles, and state memory across loop budgets (★ marks our design with the stopping rule on S):

1. Comparison With Prior Loop Designs

All seven cross-loop designs below run inside the same 6.8M 2-layer core under matched training compute (12 training loops, evaluated from 4 to 160 test loops):

Table 1. Comparison of cross-loop designs on 2,048 unseen Sudoku-Extreme boards and 1,000 unseen 30×30 Maze-Hard grids (Acc/T = solve % per TFLOP; component ablations and deeper training loops in Appendix C).
Design (6.8M core) State Sudoku @4 Sudoku @12 Sudoku @160 Sudoku Acc/T @12 Maze @4 Maze @12 Maze @160
Window-8 [8, D] 4.9% 11.3% 16.9% 32.9 7.1% 6.7% 4.2%
MeSH [6] [8, D] 8.8% 16.9% 16.3% 49.2 18.2% 20.6% 13.5%
LOOM [D]+1 11.7% 21.0% 20.4% 61.4 17.9% 18.6% 19.1%
Carry-Last (Huginn) [3] [D] 6.1% 18.5% 20.9% 54.0 16.6% 18.4% 18.5%
InfiLoop [5] [D]+1 10.7% 20.1% 21.0% 58.4 16.1% 17.9% 5.3%
1-Pass Bank (Inkling-style) [1, D] 12.7% 23.1% 27.2% 67.4 14.7% 17.5% 16.4%
Ours (S_attn + S_mlp per layer) 2×[8, D] 33.6% 40.4% 42.6% 115.3 18.4% 21.3% 19.4%
  • Per-layer delta memory ranks first across every loop budget on both tasks. On Sudoku, Ours at 4 loops (33.6%, 0.12 TFLOPs) already beats 160-loop InfiLoop (21.0%, 4.59 TFLOPs) using 39× fewer FLOPs, and loses 0.0% of solved boards at 160 loops.
  • Step-indexed buffers and single-vector averages degrade at deep loops. MeSH drops past N_train = 12 on both tasks (20.6% → 13.5% on Maze-Hard), while InfiLoop loses 74.3% of its 12-loop Maze solutions by loop 160 (17.9% → 5.3%).

2. Early Stopping with Memory S

Running every puzzle to 160 loops wastes compute on inputs that already converged, and on Maze-Hard extra loops begin overriding path tokens that were already solved on earlier passes (21.3% at 12 loops vs. 19.2% at 160 loops).

Instead of adding a learned halting head, calling the vocabulary head at every pass, or checking task-specific puzzle rules, we use the memory matrix S directly: we track how much S changes from the start of a pass to the end of a pass, and stop each puzzle once that change stays below a threshold for two passes (why pass-level change in S cancels the alpha decay leak is derived in Appendix B):

Table 2. Zero-shot early stopping using S on the 12-loop Ours checkpoints (Acc / TFLOP increases 2.3× on Sudoku and 8.6× on Maze-Hard).
Task Method Mean Loops TFLOPs Solve (%) Acc / TFLOP
Sudoku (9×9) Ours (160 loops) 160.0 4.67 42.7% 9.1
Sudoku (9×9) Ours + Stop on S 69.5 2.03 42.7% 21.0
Maze-Hard (30×30) Ours (160 loops) 160.0 38.88 19.2% 0.49
Maze-Hard (30×30) Ours + Stop on S 21.2 5.15 21.9% 4.25

Next Directions

  1. Scaling up the model. Here we held a 6.8M 2-layer core fixed to isolate cross-loop state flow and stopping. The main next step is scaling this cognitive core to larger Prelude–Core–Coda depth-recurrent language models (100M–1B+ parameters) paired with strided KV Replay [14], where S_attn and S_mlp live only on the single active token being decoded and add zero bytes to the past-token KV cache.
  2. Token-level early exit (Mixture-of-Recursions, MoR [15]). Puzzle-level stopping still runs all 81 or 900 tokens until the hardest token settles. Using per-token change in S to skip MLP (54%–66% of FLOPs) and state writes on settled tokens while keeping their latest K, V live in Attention can cut FLOPs inside partially solved inputs during both training and inference.

Appendix A: Why Loop-Axis Gated Delta Blends (1 - g) * v + g * o

Standard token-axis Gated DeltaNet [13] and our loop-axis cell use the same state update S = alpha * S + beta * outer(k, v - (alpha * k) @ S), yet only the loop-axis cell blends (1 - g) * v + g * o at the end. Comparing where v, k, and q come from shows why:

# 1. Token-axis Gated DeltaNet (REPLACES Softmax Attention across tokens t)
q, k, v = l2_norm(x @ W_q.T), l2_norm(x @ W_k.T), x @ W_v.T   # project input x
S = alpha * S + beta * outer(k, v - (alpha * k) @ S)          # S: [B, dk, D] across tokens
o = q @ S                                                     # sole cross-token output
x = rms_norm(x + o @ W_o.T)                                   # x is already kept by "x + ..."

# 2. Loop-axis Gated Delta (WRAPS Softmax Attention or MLP across passes p)
v  = sublayer(x)                                              # [B, T, D] NEW Attention or MLP work!
vn = rms_norm(v)
k, q = l2_norm(vn @ W_k.T), l2_norm(vn @ W_q.T)               # [B, T, dk] write & read addresses from v
S = alpha * S + beta * outer(k, v - (alpha * k) @ S)          # S: [B, T, dk, D] across passes
o = q @ S                                                     # past-pass memory readout
u = (1 - g) * v + g * o                                       # keep current-pass v AND past-pass o
x = rms_norm(x + u)

In token-axis Gated DeltaNet, v = x @ W_v.T is just a projection of x (already preserved on the residual stream), and o = q @ S is the only cross-token work. In our loop-axis wrapper, sublayer(x) runs first to compute fresh cross-token Attention or MLP work v that is not in x yet, and two learned [dk, D] matrices project v into a write address k and a read address q. Because W_k and W_q are separate (q != k), k can write pass p’s deduction into one row of S while q reads an earlier pass’s deduction from another row, leaving v absent from o:

# Toy trace for 1 token (D = 3, dk = 2 rows in S, alpha = 1, beta = 0.5, g = 0.5)
W_k = [[1., 0., 0.],   # dim 0 active -> write Row 0;  dim 1 active -> write Row 1
       [0., 1., 0.]]
W_q = [[0., 1., 0.],   # dim 1 active -> read Row 0;   dim 0 active -> read Row 1
       [1., 0., 0.]]
S   = [[0., 0., 0.],   # Row 0 (empty before Pass 0)
       [0., 0., 0.]]   # Row 1 (empty before Pass 0)

# Pass 0: sublayer(x) finds clue in dim 0 -> v = [10., 0., 0.]
k, q = l2_norm(v @ W_k.T), l2_norm(v @ W_q.T)  # k = [1., 0.] (Row 0), q = [0., 1.] (Row 1)
S    = [[5., 0., 0.], [0., 0., 0.]]            # writes 0.5 * v into Row 0
o    = q @ S                                   # reads Row 1 -> [0., 0., 0.] (v is missing!)
u    = 0.5 * v + 0.5 * o                       # -> [5., 0., 0.] (Pass 0's v survives into x)

# Pass 1: sublayer(x) finds clue in dim 1 -> v = [0., 20., 0.]
k, q = l2_norm(v @ W_k.T), l2_norm(v @ W_q.T)  # k = [0., 1.] (Row 1), q = [1., 0.] (Row 0)
S    = [[5., 0., 0.], [0., 10., 0.]]           # writes 0.5 * v into Row 1
o    = q @ S                                   # reads Row 0 -> [5., 0., 0.] (Pass 0 only!)
u    = 0.5 * v + 0.5 * o                       # -> [2.5, 10., 0.] (carries Pass 0 AND Pass 1)

Appendix B: Leaky-Bucket Derivation for Early Stopping on S

At first glance, halting when the delta prediction gap err = v - (alpha * k) @ S approaches 0 looks natural [10]. In practice, alpha < 1 turns S into a leaky bucket: even after a token has settled on its answer (v = 10.0 on every subsequent pass), alpha drains (1 - alpha) out of S mid-step, so err stays permanently non-zero just to refill that leak.

Compare err (measured mid-pass, after the drain and before the refill) against S_after - S_before (measured end-of-pass, after the refill puts back what leaked):

# 1-token converged trace (v = 10.0 forever, k = 1.0, alpha = 0.8, beta = 0.5)
# By Loop 20, S has already converged to 8.33:
S_before  = 8.33                        # 1. Start of pass: bucket sits at 8.33
S_decayed = 0.8 * S_before   # = 6.67   # 2. Mid-pass: alpha drains leak = 1.67 out
err       = 10.0 - S_decayed # = 3.33   #    -> raw err stays stuck at 3.33 > 0!
S_after   = S_decayed + 0.5 * err       # 3. End of pass: inflow = +1.67 refills -> 8.33

# Since S_after = S_before - leak + inflow, subtracting S_before cancels the leak:
net_change = S_after - S_before         # == inflow - leak == 1.67 - 1.67 == 0.00!

In our 2-layer core, Layer 0 and Layer 1 also write into overlapping slots of the shared S matrix (mean |cos(k_L0, k_L1)| ≈ 0.40), nudging S in opposite directions inside a pass (+d then -d). Measuring ||S_after - S_before||_F / ||S_after||_F across the full 2-layer pass cancels both the alpha leak and the within-pass push-pull (54.7% vs. 36.4% for raw err at ~155 mean loops on 24-loop Sudoku, with zero extra memory allocations because S_before is already the input tuple to Block.forward).

Appendix C: Component Ablations and Deeper Training Loops

1. Channel Separation and Update Frequency (B0 → A1 → A2 → A3)

Starting from InfiLoop (B0), each row below changes one piece of our design (12 train loops → 160 test loops). A2 and A3 have the exact same parameter count because Layer 0 and Layer 1 share attn_cell and mlp_cell weights:

Table 3. Component ablation on Sudoku-Extreme (2,048 boards) and Maze-Hard (1,000 mazes). Sharing one matrix between Attention and MLP (A1) collides at 160 loops on both tasks (5.3% and 0.0%).
Arm & Design Choice Sudoku @4 Sudoku @160 Sudoku Lost Maze @12 Maze @160 Maze Lost
B0: InfiLoop (1 running-avg vector) 10.7% 21.0% 3.4% 17.9% 5.3% 74.3%
A1: 1 shared matrix S (pass end) 15.4% 5.3% 70.9% 20.2% 0.0% 100.0%
A2: Split S_attn + S_mlp (pass end) 13.8% 25.7% 0.8% 12.3% 10.5% 26.0%
A3: Update S_attn + S_mlp per layer 33.6% 42.6% 0.0% 21.3% 19.4% 18.3%

2. Deeper Training Loops (12 → 24 → 36) on Sudoku-Extreme

Training on 24 and 36 loops per board (1,200 puzzle batches, rolled out to 320 test loops = 9.34 TFLOPs):

Table 4. Deeper training loops on Sudoku-Extreme (0.0% broken boards at 320 loops across all 24- and 36-loop 1,200-batch runs; early stopping on 24-loop Ours raises Acc / TFLOP 2.1× from 5.9 to 12.4).
Train Loops Batches (Steps) Method @Train @160 @320 Stop Loops Stop Solve Stop Acc/T
12 1,200 (14.4k) InfiLoop / Ours 20.1% / 40.4% 21.0% / 42.6% — 69.5 42.7% 21.0
24 600 (14.4k) InfiLoop / Ours 18.8% / 21.6% 19.5% / 22.5% 19.5% / 22.5% — — —
24 1,200 (28.8k) InfiLoop / Ours 31.3% / 40.5% 33.5% / 53.8% 33.6% / 54.8% 150.9 54.7% 12.4
36 1,200 (43.2k) InfiLoop / Ours 38.1% / 50.1% 42.8% / 53.9% 43.3% / 54.6% — — —

References

[1]
A. Karpathy, “Andrej Karpathy on the cognitive core (Dwarkesh podcast).” Dwarkesh Podcast, Oct. 2025. Available: https://www.dwarkesh.com/p/andrej-karpathy
[2]
N. Saunshi, S. Nishikawa, S. Singh, S. J. Reddi, and S. Kumar, “Reasoning with latent thoughts: On the power of looped transformers,” in International conference on learning representations (ICLR), 2025. Available: https://arxiv.org/abs/2502.17416
[3]
J. Geiping et al., “Scaling up test-time compute with latent reasoning: A recurrent depth approach,” arXiv preprint arXiv:2502.05171, 2025, Available: https://arxiv.org/abs/2502.05171
[4]
Thinking Machines Lab, “Introducing Inkling 2 Mini.” Thinking Machines Lab Blog, Nov. 2026. Available: https://thinkingmachines.ai/news/inkling-2-mini/
[5]
P. Li, D. Muhtar, Y. He, J. Su, L. Yin, and S. Liu, “Scaling to tens of thousands of test-time iterations with loop-native attention residuals,” arXiv preprint arXiv:2610.11570, 2026, Available: https://arxiv.org/abs/2610.11570
[6]
C. Yu et al., “MeSH: Memory-as-state-highways for recursive transformers,” in International conference on learning representations (ICLR), 2026. Available: https://arxiv.org/abs/2510.07739
[7]
Kimi Team, G. Chen, Y. Zhang, J. Su, et al., “Attention residuals,” arXiv preprint arXiv:2603.15031, 2026, Available: https://arxiv.org/abs/2603.15031
[8]
W. Sun, X. Song, P. Li, L. Yin, Y. Zheng, and S. Liu, “The curse of depth in large language models,” in Advances in neural information processing systems (NeurIPS), 2025. Available: https://arxiv.org/abs/2502.05795
[9]
S. Liu, “From model compression to looped transformers.” Blog post, Nov. 2026. Available: https://shiweiliuiiiiiii.github.io/blog/2026/from-model-compression-to-looped-transformers/
[10]
M. Le et al., “Looped transformers: Architecture, training, and inference,” arXiv preprint arXiv:2611.35712, 2026, Available: https://arxiv.org/abs/2611.35712
[11]
Sapient Intelligence, “Sudoku-extreme dataset.” Hugging Face Datasets, 2025. Available: https://huggingface.co/datasets/sapientinc/sudoku-extreme
[12]
Sapient Intelligence, “Maze-30x30-hard-1k dataset.” Hugging Face Datasets, 2025. Available: https://huggingface.co/datasets/sapientinc/maze-30x30-hard-1k
[13]
S. Yang, J. Kautz, and A. Hatamizadeh, “Gated delta networks: Improving Mamba2 with delta rule,” in International conference on learning representations (ICLR), 2025. Available: https://arxiv.org/abs/2412.06464
[14]
L. Licakova, N. Schmidinger, L. Hauzenberger, S. Böck, and S. Hochreiter, “Architectures and KV replay for depth-recurrent language models,” arXiv preprint arXiv:2611.19446, 2026, Available: https://arxiv.org/abs/2611.19446
[15]
S. Bae, A. Fisch, H. Harutyunyan, T. Ziarko, S.-Y. Kim, and T. Schuster, “Mixture-of-recursions: Learning dynamic recursive depths for adaptive token-level computation,” arXiv preprint arXiv:2507.10524, 2025, Available: https://arxiv.org/abs/2507.10524