# Looped Transformers Explained: How One Reused Layer Can Match a 12-Layer Model

> Source: <https://dev.to/jamilxt/looped-transformers-explained-how-one-reused-layer-can-match-a-12-layer-model-21a>
> Published: 2026-11-23 14:34:16+00:00

**Recommendation:** When looping a shared transformer layer, re-inject the original prompt at every iteration and train with truncated backpropagation over the last T steps to keep memory down and outputs stable.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

Thinking Machines' [Inkling 2 Mini](https://thinkingmachines.ai/news/inkling-2-mini/) is a production model that runs its middle layers three times per token. That idea has a research history. One of the clearest papers in it is ["Looped Transformers are Better at Learning Learning Algorithms"](https://arxiv.org/abs/2311.12424) by Liu Yang, Kangwook Lee, Robert D. Nowak and Dimitris Papailiopoulos (University of Wisconsin, Madison). It was accepted at ICLR 2024.

The headline result: a transformer with **one layer**, run in a loop, matched a standard **12-layer** GPT-2 style transformer on several in-context learning tasks. The looped model had about 0.79M parameters. The standard one had about 9.48M.

I have not run the paper's code. Everything below comes from the paper itself (arXiv v3, March 2024), and the numbers are the authors' results. The goal is to explain the idea in plain terms and be clear about what the experiments do and do not show.

Start with a simple setup from earlier work by [Garg et al. (2022)](https://arxiv.org/abs/2208.01066). You give a transformer a prompt made of example pairs, like this:

```
x1, f(x1), x2, f(x2), ..., xk, f(xk), x_test
```

The function `f` is random and different for every prompt. The model never sees it directly. It has to look at the examples and predict `f(x_test)`. This is in-context learning in its purest form: no fine-tuning, just "figure out the pattern from the prompt."

Garg et al. showed that a normal transformer trained from scratch can do this well for linear functions, often close to the textbook answer (ordinary least squares).

But here is the catch. Classic machine learning solves these problems with **iterative** algorithms. Gradient descent takes the same small step again and again until the answer settles. A standard transformer has no loop. It has a fixed stack of different layers, and each input goes through them once.

So the authors asked: if you build the loop into the transformer, does it learn these algorithms more efficiently?

The paper gives a clear example with linear regression.

The exact answer, least squares, needs a matrix inverse. Earlier work found that transformers find matrix inversion hard to learn. It needs more layers and heads.

Gradient descent avoids the inverse. Each step only needs matrix multiplication, which transformers handle well. The trade-off is that you must repeat the step many times.

That maps neatly onto a loop. If one layer can learn "one step of improvement", running it many times could do the rest. And because the same weights are reused on every pass, you pay for one layer of parameters, not twelve.

The model is a GPT-2 decoder with 1 layer, 8 attention heads and an embedding size of 256. The baseline is the same design with 12 layers.

Each loop looks like this:

```
Y0 = zeros
Y1 = M(Y0 + P)
Y2 = M(Y1 + P)
...
Yt = M(Y(t-1) + P)
```

`M` is the one shared layer. `P` is the original prompt. `Yt` is the model's state after `t` passes.

Notice that `P` is added back in at **every** step. The paper calls this **input injection**, and it turned out to be essential.

Older weight-sharing models (like ALBERT and Universal Transformers) feed the input in once and then just keep applying the layer to its own output. The problem: as the loop runs longer, the original input fades away and the output drifts.

The authors tested both versions. Without input injection, the model got worse as soon as it ran past the number of loops it was trained on. With input injection, it stayed stable.

The plain version: each pass gets to look at the original question again, not only at its own previous guess.

Training a loop raises two questions. How many loops do you run during training? And at which loop steps do you check the answer?

The paper uses two numbers:

Only checking the last T steps saves memory. It borrows the idea of truncated backpropagation through time from recurrent network training.

Both numbers involve trade-offs, according to the paper:

For linear regression the authors settled on b = 20 and T = 15. They also increased b gradually during training. They found this scheduling made little difference on most tasks, but it helped a bit on decision trees.

The goal of all this tuning is a **fixed point**. The answer should improve with each loop, then settle and stay there no matter how many extra loops you run. In the paper's Figure 2, a model trained with 30 loop iterations kept a stable answer well beyond 30 at inference time.

The main tests use inputs with 20 dimensions. The authors compare the looped model (1 layer) against the standard transformer (12 layers) and classic solvers.

**Linear regression.** The looped transformer matched the 12-layer transformer and came close to least squares, with about 1/12 of the parameters.

**Fewer training examples needed.** The authors trained both models on fixed datasets of different sizes. The looped model learned the task from fewer distinct prompts than the standard one. They attribute this to its smaller parameter count, and the result held for problem dimensions 5, 10 and 20.

**Harder function classes.** They also tested sparse linear functions (only 3 of 20 weights non-zero), depth-4 decision trees and 2-layer ReLU neural networks. The looped model matched the standard transformer on all of them.

**Sparse linear regression is the standout.** Here the looped model did better than the standard transformer, and with fewer than 10 examples in the prompt it even beat Lasso, the classic tool for sparse problems. The authors are careful about this claim. They mean the trend with few examples, not final precision. With 40 examples, the reported errors were:

So the looped model beat the standard transformer, but the classic solvers still reached more precise final answers when given enough data.

**Real tabular data.** In an appendix, they trained both models on 9 OpenML datasets and tested on a 10th unseen one, rotating through 10 datasets. The looped model was clearly better on 5, roughly tied on 4, and worse on 1. Example: on dataset 847 (wind), test accuracy was 0.757 for the looped model and 0.668 for the standard one.

One finding is easy to miss. You might expect a 1-layer model looped 8 times to equal an 8-layer model. It does not.

The paper reports that a 1-layer looped model needed roughly 20 iterations to match an 8-layer transformer. In general, the looped model needs more passes than the standard model has layers.

The authors looked inside both models using **probing**: training a small network to read specific quantities out of each layer's output. They probed for two things related to the regression answer. The standard transformer represented them best around layer 10, then moved on to other information. The looped model kept improving its representation of them with every pass.

That is a different way of computing. The standard model uses each layer for a different job. The looped model keeps refining the same estimate, which looks much more like an iterative algorithm.

The limitations section is the most useful part for anyone excited about looping.

**It learns a shortcut for its training data, not a general algorithm.** Real gradient descent works on any input. The looped transformer only behaves like a solver on data similar to what it was trained on. The authors say this directly: it "fails to identify an actual algorithm that generalizes to any input distribution."

**It prefers simple answers, which cuts both ways.** The looped model shows a bias toward simpler solutions. That helped with skewed inputs, with noisy regression, and with sparse problems. But when the test inputs were scaled up (by 3 in the main figure), the looped model did worse than the standard transformer.

**There is an error floor.** Even at its fixed point, the answer is not as precise as a classic solver.

**The tasks are small and synthetic.** Linear functions, small decision trees and small neural networks with 20 input dimensions. The OpenML results are a step toward real data, but nothing here tests language modeling or reasoning at scale.

**Tuning matters.** The right b and T values changed by task: b = 20 and T = 10 for sparse linear functions, b = 70 and T = 15 for decision trees, and b = 12 and T = 5 for 2-layer ReLU networks. The authors suggest these values could serve as a measure of how hard a task is for a transformer. Oddly, the neural network task needed fewer loops than plain linear regression, and they say the reason is still unclear.

In 2023 this was a small-scale research result. In late 2026, labs ship looped models that people run on laptops. The paper explains, in a clean setting, the core bargain those models are making:

If you want to go deeper, the code is open on [GitHub](https://github.com/Leiay/looped_transformer). The related paper ["Looped Transformers as Programmable Computers"](https://arxiv.org/abs/2301.13196), which shares two of the authors, covers the theory side.

The paper makes one clear point. If the algorithm you want a model to learn is iterative, give the model a loop. A single layer, looped with the prompt fed back in on each pass, matched a 12-layer transformer on these tasks and learned from fewer examples.

It also shows the limit. The loop learned to act like a solver for the data it was trained on, not a solver that works everywhere.

When you choose a model for your next project, do you care more about the number of parameters, or about how much computation it can do per token?
