Standard Transformers suffer from a "fixed-depth" problem: they struggle to solve algorithmic problems that are longer than those seen during training because their computational budget is set in stone. To address this, researchers have introduced Looped Transformers, an architecture that reuses a single decoder block for an adaptive number of steps. This allows the model to "think longer" for harder problems, achieving near-perfect length generalization on various algorithmic tasks.
The Length Generalization Gap
If you train a standard Transformer to add two 5-digit numbers, it will likely fail when asked to add two 50-digit numbers. This phenomenon is known as the length generalization gap.
The core issue is that standard Transformers have a fixed number of layers (depth). For many algorithmic tasks—like multi-digit addition or parity checking—the number of computational steps required scales with the size of the input. A fixed-depth model essentially runs out of "thinking time" as the input grows. While techniques like Chain-of-Thought (CoT) or scratchpads help by adding "horizontal" compute (more tokens), they still rely on fixed-depth blocks and often fail to learn the underlying, recursive logic of the task.
The Looped Transformer Architecture
To overcome fixed-depth limitations, the authors propose a recurrent approach. Instead of a stack of different layers, the model consists of a single decoder block that is applied iteratively.
Key innovations of this approach include:
- $n$-RASP-L Framework: The authors formalize a class of problems that can be solved by looping a primitive Transformer operation (RASP-L) a number of times $T(n)$ that depends on the input length $n$.
- Step-Dependent Supervision: During training, the model isn't forced to predict the next token at every layer. Instead, it is supervised only at the final step $T(n)$. This encourages the model to learn meaningful intermediate representations.
- Input Injection: To prevent the model from "forgetting" the original problem during long loops, the original input embeddings are re-injected (added) into the hidden state at every iteration.
- No Positional Embeddings (NoPE): To ensure the model learns the logic rather than memorizing positions, standard positional encodings are omitted. The model relies entirely on the Transformer's inherent ability to handle relative positions.
- Adaptive Inference: At test time, the model can stop based on an "Oracle" (knowing the required steps) or "Maximum Confidence" (stopping when the output probability is highest or loss is lowest).
Evaluating Iterative Algorithmic Tasks
The researchers evaluated their model on six synthetic algorithmic tasks where the solution is inherently iterative: Parity, Copy, Addition, Binary Sum, Multiplication, and Unique Set. The models were typically trained on short sequences (e.g., length 1–20) and tested on much longer ones (up to length 40 or more).
Key Insights and Results
The Looped Transformer outperformed vanilla Transformers and several strong baselines (like Transformers with "pause tokens") across the board.
- Looping as an "Internal Scratchpad": Looping allows the model to perform sequential computation without needing to output explicit Chain-of-Thought tokens. It proves to be a highly compute-efficient way to handle recursion.
- The "Aha!" of Convergence: For tasks like Addition and Copy, the model naturally "converges." Even if it runs for more steps than necessary, the output remains stable and correct, suggesting it has learned a robust algorithm rather than a brittle heuristic.
- Input Injection is Vital: Without re-injecting the original input at each step, performance on complex tasks dropped significantly. The model needs a constant "anchor" to the original data to maintain accuracy over many iterations.
- Near-Perfect Generalization: While standard Next-Token Prediction (NTP) models failed immediately beyond the training length on tasks like Parity, the Looped Transformer maintained ~100% accuracy on sequences twice as long as those seen in training. In the Copy task, the Looped model stayed near 100% accuracy up to length 34, whereas NTP models crashed after the training limit of 20.
- Confidence-Based Stopping: The "Maximum Confidence" rule proved highly effective. The model's internal loss reached its minimum exactly when the correct answer was formed, providing a reliable way to decide when to stop "thinking" without knowing the answer in advance.
Limitations and Future Work
While highly effective for algorithmic reasoning, the approach has limitations. The current $n$-RASP-L definition only covers tasks solvable by a single loop, whereas many real-world problems require sequential loops. Additionally, training through many loops can be computationally expensive due to backpropagation through time, and the current method requires knowing the ground-truth number of steps $T(n)$ during training. Finally, while perfect for strict algorithms, it remains to be seen how this architecture handles the messy, non-algorithmic nature of general natural language reasoning.
Summary updated