Article · Transformers · 28 Nov 2026 · 18 min read

Looped transformers, from the ground up

In short: A looped transformer applies the same block to its own output several times, instead of passing data through a stack of different blocks. This post is about why it works, how to train it, and some of the trade-offs. The idea dates from 2018, and has drawn new interest since small looped models reached competitive scores on ARC-AGI puzzles.

Contents
  1. 1The idea
  2. 2Refresher: what one block does
  3. 3Tying the weights
  4. 4What is the benefit of looping?
  5. 5Input injection
  6. 6Example: parity
  7. 7Training
  8. 8When to stop
  9. 9Inside the loop
  10. 10Looping and chain of thought
  11. 11The family tree
  12. 12Looped language models
  13. 13In PyTorch
  14. 14Trade-offs
  15. 15Further reading

The idea

A standard stack next to a looped block.

Both sides run the same number of block passes, so they cost the same compute. The left side learns a separate transformation for every pass, while the right side learns one and repeats it.

Two consequences follow:

  • The model can be made deeper without being made bigger.
  • The number of passes T is a tunable parameter.

Other names for the same idea include weight-tied, recurrent-depth, recursive, or Universal Transformer.

Refresher: what one block does

A transformer block takes a matrix of n token vectors and returns a matrix of the same shape.

Inside the block, two things happen in sequence. Attention lets every token pull information from other tokens. Then an MLP lets every token process what it gathered. The calculations are added back to the input (residual stream).

inxresidual streamnormattentiontokens attendto each otherx = x + attention(norm(x))+normMLPeach token alonex = x + mlp(norm(x))+out
One transformer block: two updates, each added to the residual stream, with the code for each.

The horizontal line is the residual stream. Each sublayer reads from it and writes to it.

Because output and input have the same shape, the output of a block is always a valid input to a block. A standard transformer feeds it to the next block. A looped transformer feeds it back to the same one.

Tying the weights

The difference between the two architectures can be boiled down to a subscript.

standard
hℓ+1 = f(hℓ; θℓ)
looped
ht+1 = f(ht; θ)

Unrolling the loop gives an ordinary deep network. The only unusual thing about it is that every layer is a copy of the same one.

12 distinct blocks12 blocks of weights · 12 passesθ₁θ₂θ₃θ₄θ₅θ₆θ₇θ₈θ₉θ₁₀θ₁₁θ₁₂1 block looped 12 times1 block of weights · 12 passesθ2 blocks looped 6 times2 blocks of weights · 12 passesθ₁θ₂
The loop unrolled over 12 passes, with the weights that feed each pass.

There is a similarity with RNNs. While an RNN steps through the sequence one token at a time, a looped transformer recurs over depth. Every pass still sees the whole sequence at once, in parallel.

Not every looped model ties all of its weights. Some keep a few ordinary layers before and after the looped block, since the first and last layers of a language model do different work from the middle ones.

What is the benefit of looping?

Looping can help when the problem is iterative. Arguably, a share of reasoning fits this pattern.

For example, adding numbers, sorting a list or following a chain of “A implies B implies C”. They all need a defined step and a for loop.

But within one forward pass, a standard transformer has no for loop. Depth is the only place it can do sequential computation, so each layer has to learn its own copy of the step. And when the stack ends, the computation ends. The one way to continue is to write a token and run the whole network again, which is chain of thought (more below).

The following results hint at the benefits of learning one step well and repeating it:

  • Saunshi et al. (2025) compared k layers looped L times with a full kL-layer model on tasks like addition and multi-hop induction. The looped model nearly matched it, which suggests that these tasks do not need separate weights for every layer.
  • Yang et al. (2023) trained looped models to fit a function to examples given in the prompt, such as linear regression. Classical methods solve these tasks by repeating one update step, as gradient descent does. The looped models matched a standard transformer with under 10% of the parameters.

Input injection

After enough passes in a naive loop, the model can lose track of what it was asked. The standard fix is to add the original input back in before every pass.

In the plain loop, the input enters at the starting state. Every later pass sees only the previous pass’s output. Anything the block failed to carry forward is gone. Yang et al. point out that as passes accumulate, the influence of the initial input fades.

Plain loopPpass 1pass 2pass 3pass 4pass 5pass 6Later passes see only what earlier passes carried forward.With input injectionPh = 0+Ppass 1+Ppass 2+Ppass 3+Ppass 4+Ppass 5+Ppass 6
Input injection: the original input feeds every pass, not only the first.

Input injection splits the loop’s input in two:

  • P, the embedded input, is the problem.
  • h, the hidden state, is the working solution.

Addition is the simplest way to inject. Some designs concatenate the input, and some let the state attend to it.

Example: parity

Parity is a simple task that illustrates the idea. Given a string of bits, the model has to say whether the number of ones is odd or even.

The simplest algorithm keeps one running value. It reads a bit, flips the value if the bit is 1, and repeats until the bits run out.

Passes: 0Running value: even

Parity as a loop: one pass per bit, one running value.

A looped transformer can solve it the same way. Each pass finds the next unread bit, combines it with the running value, and marks the bit as used. Four bits need four passes, and forty bits need forty passes of the same block.

Suppose a model is trained only on strings of up to 20 bits, then tested on 40. A fixed-depth model has no clean way to extend, since what it learned was fitted to its depth and the lengths it saw. A looped model that learned the single step can run it more times. This is called length generalization.

Fan et al. (2024) trained looped models with the number of passes tied to the input length, and supervised the output only after the right number of passes. On copy, parity and addition, the models generalized to longer inputs than they were trained on.

Training

A looped transformer is trained with ordinary backpropagation on the unrolled network. The difference is that the gradients from every pass land on the same weights and add up.

Backpropagation needs the activations of every pass kept in memory, so memory grows linearly with the number of passes. Thirty passes cost thirty blocks’ worth of activations, even with one block’s worth of weights. The three common training schemes differ in how they handle this.

1. Loss at the endall 6 passes kept in memoryL2. Truncated backproppasses 1–3 without gradients; 3 keptL3. Deep supervisiona loss per segment; 2 keptLLLone passlossgradientstate detached
Three ways to train a loop of six passes: where the loss attaches, and how far gradients travel.
  1. Loss at the end: run all passes, compute one loss, and backpropagate through everything. It is simple and exact, but the most expensive, and gradients have to travel back through every pass.
  2. Truncated backpropagation: run the early passes without tracking gradients, then backpropagate only through the last few. Yang et al. train with a loss over a window of recent passes.
  3. Deep supervision: attach a loss after every segment, so each segment gets its own training signal. On its own this does not save memory. The Tiny Recursive Model (TRM), a small looped model for grid puzzles described below, and its predecessor, the Hierarchical Reasoning Model (HRM), both train this way, and detach the state before the next segment begins, which keeps memory constant. They also truncate within each segment. TRM backpropagates only through the last loop of a segment, and HRM only through the last step.

Some loops settle, meaning that after enough passes the state stops changing. For these there is a fourth option. Deep Equilibrium Models compute the gradient from the settled state alone, without storing the passes that led to it.

In addition, two practices make the trained model less dependent on the number of passes. Varying the number of passes during training keeps the model from overfitting to one value of T. Supervising more than the last pass gives a usable answer at every stopping point.

When to stop

There are three common approaches to deciding how many passes to run.

short, easyshort, hardlong, easylong, hardFixed: 6 passes4 extra1 extra2 extra3 short24 passes in allTied to length1 extra2 short4 extra1 short22 passes in allLearned halting1 extrarightrightright21 passes in allneeded and runneeded, not runrun, not needed
Three ways to decide how many passes to run. The inputs and their needs are made up for illustration.

The simplest is a fixed number of passes. It keeps the parameter savings, but ignores that some inputs are harder than others.

Tying the number of passes to the input size works when the scaling of the work is known. Fan et al. use this for length generalization, with more passes for longer inputs. The rule has to be known in advance.

Learned halting lets the model decide. A simpler alternative needs no extra component, and stops when the state stops changing or when the output is confident enough. Huginn, a looped language model described below, stops when its predictions barely change between two successive passes.

Learned halting

Several lines of work show that models can learn to spend more passes on harder inputs. Most use the mechanism of Adaptive Computation Time (ACT), from Graves (2016).

easy input2 passespass 10.50pass 20.50 (rest)stophard input8 passespass 10.03pass 20.06pass 30.09pass 40.12pass 50.15pass 60.18pass 70.21pass 80.16 (rest)stopvotes so farvotes so farthreshold
Adaptive halting: stop votes accumulate until they cross a threshold, and the last pass takes the rest. The votes are made up.

After every pass, a small head looks at the state and outputs a number between 0 and 1 that says how ready it is to stop. The votes add up, and the loop ends when they cross a threshold. The output is an average of the states after every pass, weighted by the votes, with the last pass taking the weight that remains. An easy input collects large votes and exits after two passes, while a hard one collects small votes and keeps looping. A small penalty on the number of passes, the “ponder cost”, keeps the model from using more passes than it needs.

The Universal Transformer keeps these votes separately for every token, so easy positions stop early while ambiguous ones keep refining. PonderNet instead treats halting as a probability distribution over steps, which gives unbiased gradients. HRM and TRM also use a learned halting signal, mainly to stop early during training. In TRM it is trained to predict whether the current answer is already correct.

Learned halting has two limits.

First, tuning is fragile. The ponder cost sets the trade-off between speed and accuracy. Graves notes that “the behaviour of the network is quite sensitive to its value”, and the PonderNet authors call ACT unstable for the same reason. Set too high, the model always stops at once; set too low, it never stops.

Second, learned halting has so far been shown only within one task at a time. Models spend more passes on harder or longer instances of the same task family. A general-purpose model that budgets its own passes across very different tasks has not been clearly demonstrated.

Inside the loop

A looped transformer is a dynamical system, one function applied repeatedly to its own output. Run for many passes, it typically does one of three things.

Three long-run behaviours, in a two-dimensional toy loop. Each dot is the state after one pass.

In the well-behaved case, the state settles and approaches a fixed point, where the block returns its own input. Deep Equilibrium Models, mentioned above, treat this fixed point as the output and solve for it directly, as if the network had infinitely many layers.

The state can also cycle, returning close to the same few states over and over. A related pattern shows up in multi-layer loops. A 2026 mechanistic study finds that in many looped language models each layer of the loop converges to its own fixed point, so every pass repeats the same path through the block.

Finally, the state can blow up, which mostly shows up as a training problem. Fu et al. (2026) report that at high loop counts, training often suffers from oscillating gradients and exploding residual streams, and can collapse.

Keeping the scale of the residual stream in check is harder in a loop, because any growth per pass compounds over many passes. Looped models handle it in different ways. Some normalize the state after every residual add (the Universal Transformer, HRM, TRM). Huginn does the same, and normalizes once more at the end of every pass. Ouro normalizes what each sublayer reads and what it writes, and the state itself only once at the end of every pass. Others keep the standard block and instead design the loop so it cannot amplify the state (Parcae).

Each of the techniques above addresses one of these problems. Normalizing the state between passes keeps its scale in check, input injection keeps the trajectory tied to the problem, and truncated gradients and deep supervision shorten the path that gradients travel back through.

Looping and chain of thought

Chain-of-thought reasoning is also a loop, but it runs through a different channel.

When a language model “thinks step by step”, it runs the whole network, emits one token, appends it to the context, and runs again, so more thinking means more tokens. A looped transformer instead gets its extra computation by passing the hidden state through the block again, without producing any tokens.

Two ways to spend extra computation: more tokens, or more passes over the hidden state.

Saunshi et al. make the link formal. They prove that a looped model, with a slightly larger block and one placeholder token per step, can simulate T steps of chain of thought with T loops, and call the intermediate states “latent thoughts”. Each approach has its own trade-offs:

Chain of thought Looped transformer
What carries over between steps One new token, appended to the context A full vector at every position
Work per step Sequential, one token at a time Parallel across the sequence
Readable reasoning Yes, it is text, though the text may not reflect what the model computed No, it is vectors
Training signal for the steps Can imitate written reasoning Usually discovered by the model

Coconut sits between the two. It keeps the token-by-token loop of chain of thought, but feeds the last hidden state back as the next input instead of a token.

Latent loops are efficient for the same reason they are opaque. There is no transcript to inspect, so understanding what a looped model did requires interpretability tools rather than reading.

The family tree

Looped transformers go back to the Universal Transformer in 2018, which built on earlier work on adaptive computation in recurrent networks. The main papers, oldest first:

Year Work What it added
2016 Adaptive Computation Time Learned halting, for recurrent networks
2018 Universal Transformer One transformer block recurrent in depth, with optional per-token halting
2019 ALBERT Weight sharing across BERT’s layers, mainly to save parameters
2019 Deep Equilibrium Models The infinite-loop limit, solving for the fixed point directly
2021 PonderNet Halting as a probability distribution over steps, with unbiased gradients
2023 Looped Transformers as Programmable Computers Proof by construction that a looped transformer can run programs
2023 Sparse Universal Transformer Mixture-of-experts layers and per-token halting; less than half the compute of a comparable Universal Transformer on translation
2023 Better at Learning Learning Algorithms Input injection for looped transformers and a training recipe; iterative solvers with under 10% of the parameters
2024 MoEUT Mixture-of-experts layers in a shared-layer transformer, competitive on language modelling
2024 Looped Transformers for Length Generalization Passes tied to input length; generalization to longer inputs
2024 Relaxed Recursive Transformers Pretrained language models converted to loops, with a low-rank update per pass
2025 Huginn A 3.5B-parameter language model with a looped middle block
2025 Reasoning with Latent Thoughts Many reasoning problems need depth, not parameters; link to chain of thought
2025 Hierarchical Reasoning Model Two recurrent modules, deep supervision and learned halting on puzzles
2025 Mixture-of-Recursions Per-token loop depth and selective caching, up to 1.7B parameters
2025 Tiny Recursive Model A 7M-parameter looped model competitive on ARC-AGI puzzles
2025 Ouro Looped language models pre-trained on 7.7T tokens, with a learned early exit
2026 Mechanistic analysis What looped language models converge to
2026 Parcae A looped language model constrained to stay stable, and scaling laws for looping
2026 Fully Looped Transformer How to keep long loops stable

The Tiny Recursive Model

TRM is one of the more recent looped models. It keeps two things in its state instead of one, a current answer and a scratchpad.

A scratchpad loop inside an answer loop, shown with n = 3 (the paper uses 6).

In the inner loop, the network revises its scratchpad several times, looking at the question and its current answer. It then uses the scratchpad to rewrite the answer, and starts over. The same two-layer network does both jobs.

The paper reports 45% on ARC-AGI-1 and 8% on ARC-AGI-2 with 7M parameters. However, TRM is trained only on grid puzzles, not as a general language model, and a follow-up analysis argues that its ARC-AGI-1 score comes from a mix of efficiency, task-specific conditioning and heavy test-time compute, rather than from deep internal reasoning.

Looped language models

The results above are on algorithmic tasks and puzzles. Three recent models test the idea on general language modelling.

  • Huginn puts a looped block of four layers between two ordinary layers at each end. It has 3.5B parameters and was trained on 800B tokens. Its scores on reasoning benchmarks improve as passes are added at test time, up to a compute load the authors equate to a 50B-parameter transformer. They describe it as a proof of concept.
  • Ouro comes in 1.4B and 2.6B sizes, trained on 7.7T tokens with four passes and a learned early exit. The authors report that these match standard transformers of 4B and 8B parameters on most benchmarks. Their controlled experiments suggest that looping does not let the weights store more facts, but improves how the model combines the facts it has.
  • Parcae scales to 1.3B parameters. With parameters and data held equal, it scores above a standard transformer, and its 770M model is comparable to a 1.3B transformer on one benchmark suite. The gain from extra passes at test time saturates.

Looping saves weights, but it does not shrink the KV cache when generating text. To avoid recomputing earlier tokens, a transformer stores their attention keys and values for every layer, which is what the KV cache holds. A looped model needs a separate cache for every pass, so Ouro’s four passes take as much cache as a standard transformer four times as deep. There are several ways to reduce this. Ouro keeps only the cache of the last pass once generation starts, with little loss on the authors’ benchmarks. Huginn keeps a fixed number of caches and overwrites the oldest. Mixture-of-Recursions lets each token leave the loop at its own depth, and stores a token only at the depths it reaches.

In PyTorch

The ideas above fit in a short PyTorch module. Compared with a standard transformer, the main difference is that the for loop reuses self.block on every pass instead of stepping through a list of distinct layers. The others are the input injection line, h = h + P, and normalizing the state after every pass.

import torch
import torch.nn as nn

class LoopedTransformer(nn.Module):
    def __init__(self, vocab, d=128, heads=4, k=1):
        super().__init__()
        self.embed = nn.Embedding(vocab, d)
        # k distinct layers form "the block"
        # (1 or 2 in small models, more in looped language models)
        self.block = nn.ModuleList(
            nn.TransformerEncoderLayer(d, heads, 4 * d,
                                       batch_first=True, norm_first=True)
            for _ in range(k))
        self.norm = nn.LayerNorm(d)
        self.head = nn.Linear(d, vocab)

    def forward(self, tokens, T):
        P = self.embed(tokens)        # (batch, seq, d) -- the problem
        h = torch.zeros_like(P)       # the working solution
        for _ in range(T):            # same weights on every pass
            h = h + P                 # input injection
            for layer in self.block:
                h = layer(h)
            h = self.norm(h)          # keep the state's scale fixed across passes
        return self.head(h)

model = LoopedTransformer(vocab=16)
x = torch.randint(0, 16, (8, 20))
shallow = model(x, T=6)               # 6 passes
deep    = model(x, T=30)              # 30 passes, zero new parameters

In the last two lines, the same weights run as a 6-pass or a 30-pass network. A real implementation would also add position information, a causal mask for generation, and one of the training schemes from earlier.

Trade-offs

Looping gives parameter efficiency and adjustable depth, at the cost of harder training and no reduction in compute.

Gains Costs
Far fewer parameters for the same depth No compute savings at a fixed number of passes
Number of passes chosen at inference Training memory and stability problems at high pass counts
A bias toward iterative solutions that can generalize to longer inputs Less capacity to memorize, since fewer weights hold fewer facts
Reasoning in the hidden state, without extra tokens No readable trace of the reasoning

The strongest results so far are on algorithmic tasks and puzzles, where the iterative structure is obvious. For general language modelling the picture is more mixed. Saunshi et al. find that looped models hold up on reasoning-style tasks but lag on memorization, which agrees with the Ouro experiments above. One response is to combine looping with mixture-of-experts layers, which hold many more weights but run only a few of them for each token. The Sparse Universal Transformer and MoEUT take this route, and the MoEUT authors report slightly better results than standard transformers on language modelling.

Further reading

  1. Universal Transformers for the original idea, and a per-token version of ACT halting.
  2. Looped Transformers for Length Generalization for a clear demonstration of length generalization with loops.
  3. Less is More: Recursive Reasoning with Tiny Networks for a recent, small looped model, with readable pseudocode.