bugger.
LLM ARCHITECTURE / PRACTICAL GUIDE

Looped transformers: a practical guide

A looped transformer repeatedly applies a shared block to hidden states before producing an output. The loop adds computation without adding a new set of block parameters at every depth. It is a research family with several designs, not a guarantee that more iterations always improve an answer.

What is recurrent depth?

A model reuses a block across depth while its hidden state evolves.

  • Embed the input and initialize the hidden state.
  • Apply the same block for a fixed or adaptive number of iterations.
  • Read out logits and compare quality against the computation spent.

1. The core idea: reuse depth

01 / RECURRENT DEPTH
INPUTh₀
SHARED BLOCKFθ
STATEh₁
SAME WEIGHTSFθ
STATEh₂
SAME WEIGHTSFθ
OUTPUTh₃
Redrawn from the recurrent refinement in Universal Transformers, Figure 1. The states change; θ is shared across visits.

A conventional transformer applies a sequence of different learned layers: layer 1 has its own weights, then layer 2 has another set, and so on. A looped transformer applies the same learned block multiple times. Its parameters stay fixed within the forward pass, but the hidden representation changes at every visit.

Think of the hidden state as a working representation of every token, not a sentence the model has written down. A second pass can use the representation produced by the first pass. Attention still mixes information across permitted positions; in a causal language model, the future-token mask must hold at every iteration.

The diagram below redraws the core idea in Universal Transformers, where representations are refined across recurrent steps. Sharing parameters across depth is the defining idea; the exact block, initialization and stopping rule vary between papers.

Trace a shared residual update. Loop a shared depth block · Python · ~30 min

2. Follow one forward pass

Let x be a sequence of n tokens and let each hidden state have shape n × d. A common abstraction is h₀ = embed(x), followed by hₜ₊₁ = Fθ(hₜ, x, t). Here θ denotes one shared set of weights; t is the loop index, not a token position. Input injection and an explicit step signal are optional design choices.

For example, a four-layer shared block run three times executes twelve layer applications, but stores only four layers of core weights. A prelude and output layers add their own parameters and operations. Reusing the block does not mean that h₁, h₂ and h₃ are identical: each receives a different state.

In an autoregressive model, the final state is projected to vocabulary logits. A decoding rule chooses the next token, appends it to the context, and the process continues. This is a conceptual forward pass; production implementations can cache intermediate keys and values, with bookkeeping that depends on the architecture and depth.

Python · schematic example
h = embed(tokens)
for step in range(num_loops):
    h = shared_block(h, causal_mask)  # same weights each time
logits = output_head(h)

3. A research example: Huginn

02 / HUGINN ARCHITECTURE
INPUTTokens
PRELUDEEncode
RECURRENT COREUpdate state ↻same block × r
CODADecode
OUTPUTProbabilities
Adapted from Geiping et al., Figure 2. The prelude output is injected into each core iteration; the recurrent state is initialized separately.

Geiping and colleagues study a decoder-only recurrent-depth language model with three parts: a prelude processes the input, a recurrent core updates a latent state repeatedly, and a coda produces next-token probabilities. The prelude representation is supplied to the core on every iteration; the paper initializes the recurrent state separately. This is one architecture, not a requirement for every looped transformer.

Their 3.5-billion-parameter proof of concept samples recurrent iteration counts during training and evaluates different test-time budgets. The authors report improvements on several benchmarks as computation increases, with different tasks benefiting from different amounts. The curves are empirical results for their model and settings, not a promise of monotonic improvement for every example or architecture.

4. How the loop learns

Training unrolls the recurrent core into a computation graph: the same parameters appear at each step, and gradient contributions from those uses accumulate into one update. A language-model objective can still be ordinary next-token cross-entropy; explicit labels for intermediate thoughts are not required.

Long unrolls can be expensive to train because intermediate activations are needed for backpropagation. Checkpointing trades recomputation for memory; truncated backpropagation limits how far gradients flow and changes the training signal. Huginn samples the number of iterations and uses truncated backpropagation, rather than fully backpropagating through every step.

Training across a range of depths may help a model handle variable test-time budgets, but extrapolating far beyond the training distribution can fail. Stability, initialization, normalization and how the input is reinjected all matter.

5. Fixed loops, adaptive loops and cost

The simplest policy runs a fixed number of iterations for every token. Adaptive computation chooses when to stop based on a signal such as a learned halting probability or a change in predictions, subject to a maximum budget. Universal Transformers explore adaptive halting per position; a small change in a hidden state or confident prediction does not prove the answer is correct.

Extra iterations reuse parameters but execute the block again. For a fixed sequence length, core work grows roughly with the number of loops; latency, activation memory and KV-cache behavior depend on the implementation. During training, activation memory can grow with the unrolled depth. Per-token early stopping also requires careful batching and cache handling, so fewer theoretical operations need not translate directly into lower wall-clock latency.

Depth recurrence is distinct from autoregressive generation across tokens and from recurrent state carried across sequence positions. Latent iterations do not automatically produce readable reasoning traces; a model can also generate a verbal chain of thought, but that is a separate way to spend inference compute.

Implement per-token halting bookkeeping. Stop depth updates per token · Python · ~30 min

6. Evaluate the tradeoff

Compare with a non-shared baseline at matched parameter count and separately at matched training and inference compute. Keep data, tokenization, evaluation prompts and decoding settings comparable. Sweep loop counts, including the training range and carefully chosen out-of-range values.

Report quality alongside measured FLOPs, latency, throughput and peak memory. Look at per-example changes as well as averages: additional iterations can help some inputs, do nothing for others, or hurt. A model with fewer stored weights is not necessarily cheaper or faster to serve.

  • Check causal masking at every loop and verify that the core weights are shared.
  • Plot loss and task accuracy against measured compute and latency.
  • Record the training depth distribution, stopping policy, hardware and cache strategy.

Follow the implementation roadmap. Contribution milestones

Frequently asked questions

Is a looped transformer an RNN?
It is recurrent across network depth: a shared transformation repeatedly updates hidden states. That differs from a traditional RNN whose state advances across sequence positions. Architectures can combine the two ideas.
Does more looping always improve reasoning?
No. Results depend on the model, task, training and iteration budget. Additional steps can plateau or degrade performance, and convergence or confidence alone does not establish correctness.
Does weight sharing make inference free?
No. Shared weights reduce the number of distinct parameters, but each extra application consumes compute and can increase latency and memory requirements.

Further reading

Start with primary reports and documentation. Community discussions are discovery leads, not evidence on their own.

PUT THE METHOD TO WORK

Practice on a focused challenge.

Explore LLM architecture challenges
BUILD A REGULAR PRACTICE

Start free. Keep following the evidence.

Explore the current challenge collection, or see what is planned for future practice packs.