Looped Transformers
A transformer architecture that applies one shared block repeatedly over many loop iterations instead of stacking many distinct layers.
Looped transformers reuse one shared transformer block many times in a row. Each loop iteration reads the current hidden states, runs the same attention and feed-forward weights again, and writes back updated states before the model makes a final prediction.
At a glance
Released
May 2024
Authors
Liu Yang, Kangwook Lee, Robert D. Nowak, et al.
Optimizes
- Parameter Efficiency
- Iterative Inference
- In Context Learning
What It Is
Looped transformers are a transformer architecture that creates depth by repeating one shared block instead of stacking many separate layers. The model embeds input tokens into hidden states, then applies the same transformer block—self-attention followed by a feed-forward path—over and over for a fixed loop count. Each pass refines the hidden states in place. After the last loop iteration, a prediction head reads the final states and produces the output.Why It Exists
A standard transformer grows its parameter count every time a new layer is added, because each layer keeps its own weights. Looped transformers ask whether depth can come from repeated computation on shared weights instead. That pattern can reduce parameter count while still giving the model many refinement steps. Researchers study looped transformers partly because repeated passes over the same block may help a model carry out iterative in-context learning behavior with fewer total parameters.How It Works
Input context tokens are embedded into hidden states that carry information across positions. A loop counter sets how many times the shared block runs. On each iteration, the block applies self-attention so tokens can exchange information, then applies a feed-forward network to refine each position. Residual connections carry the previous state forward so each loop updates rather than replaces the representation. After each pass, the updated hidden states feed back into the same shared block until the loop counter reaches its limit. When the loop count is exhausted, the final hidden states feed a prediction head. The same block weights are used on every iteration; only the hidden states change from pass to pass. In the ICLR 2024 study, training sets a maximum loop count and a truncated loss window over recent loop outputs, while inference can use a different loop count; their linear-regression experiments report that a model trained for one loop budget can still reach a stable fixed-point solution when unrolled for more loops at test time.Looped transformer compute flow
Input context token embeddingsShared transformer block (attention + feed-forward)Updated hidden states h^(ell)Final prediction headLoop count LSame block weights reused on every loop iterationInput context token embeddings to Shared transformer block (attention + feed-forward)Loop count L to Shared transformer block (attention + feed-forward)Shared transformer block (attention + feed-forward) to Updated hidden states h^(ell)Updated hidden states h^(ell) to Shared transformer block (attention + feed-forward)Updated hidden states h^(ell) to Final prediction headInput context token embeddings to Updated hidden states h^(ell)
Hidden state computation path
Loop iteration control
Residual connection
Loop count input
Shared-weight note
Math Or Compute Schema
A standard depth-L transformer uses L distinct blocks with separate parameters. A looped transformer applies one shared block L times to the evolving hidden state, then reads the final state with a prediction head. The formulas below contrast layer-specific depth against shared-block iteration and show how the final prediction is produced.- Hidden states after layer l.
- Layer index from 1 to L.
- Total number of distinct layers.
- Transformer block with layer-specific parameters.
- Hidden states after loop iteration ℓ.
- Loop iteration index from 1 to L.
- Loop count for repeated block application.
- Shared transformer block reused on every iteration.
- Model prediction after the last loop iteration.
- Output projection that maps final hidden states to predictions.
- Hidden states after the final loop iteration.
Compared To Nearby Modules
A standard transformer stack assigns fresh weights to every layer, so depth and parameter count grow together and each layer runs once per forward pass. A looped transformer keeps one shared block and sets depth through a loop count L, so stored parameters stay tied to that block while compute depth comes from repeated passes. The same attention and feed-forward weights are reused on every iteration, which trades duplicated parameters for extra forward compute. Where a standard stack hands states to a new layer map at each step, a looped design can keep refining the same states with one shared map, which is the intuition behind fixed-point or convergence-style behavior when more loops are unrolled at test time. The shared block still contains ordinary attention and feed-forward submodules; the architectural difference is parameter sharing, iteration count, compute reuse, and iterative refinement rather than a replacement for those building blocks.| Comparison dimension | Standard transformer stack | Looped transformer | Shared transformer block |
|---|---|---|---|
| How depth is created | L distinct layers stacked in sequence, each with its own weights | One shared block applied L times in a loop over the same states | Single attention and feed-forward block used as the repeated unit |
| How parameters scale with depth | Parameter count grows with layer count because every layer stores separate matrices | Parameter count stays tied to one block while loop count adds compute depth | Weights are shared across loop iterations rather than duplicated per layer |
| What repeated passes do | Each layer transforms states once on the forward pass | Each loop iteration refines the same hidden states with reused weights | Self-attention and feed-forward run inside every loop pass |
| How loop or layer depth is chosen | Depth equals layer count; every layer runs once per forward pass | Loop count L sets how many times the shared block runs; the studied setup can train and test with different counts | Not applicable; describes the reusable unit inside each loop pass |
| Iterative refinement or fixed-point role | States pass through distinct layer maps without revisiting earlier weights | Repeated application of one block can refine states toward a stable fixed point when unrolled further at test time in the reported linear-regression experiments | Self-attention and feed-forward execute inside every loop iteration |