Iteration Head: A Mechanistic Study of Chain-of-Thought

Vivien Cabannes, Charles Arnal, Wassim Bouaziz, Alice Yang, Francois Charton, Julia Kempe

TL;DR

Researchers from FAIR (Meta AI) and NYU have identified a specific neural circuit they call the "iteration head" that enables transformers to perform Chain-of-Thought (CoT) reasoning. By studying simple iterative tasks, they show how transformers learn to use generated tokens as an external "tape" to overcome their inherent depth limitations, and demonstrate that these reasoning skills are highly transferable between different tasks.

What Problem Does This Paper Address?

Large Language Models (LLMs) show a dramatic jump in performance when asked to "think step-by-step," a technique known as Chain-of-Thought (CoT). While we know CoT works, we don't fully understand how the transformer architecture—which is essentially a stack of attention layers—actually implements these logical steps.

Theoretically, a transformer's ability to solve complex problems in a single forward pass (next-token prediction) is limited by its depth. This paper investigates how CoT allows the model to bypass these limits by treating the output sequence as a form of working memory, effectively emulating a Turing machine. The authors use mechanistic interpretability to peek under the hood and see exactly which attention heads are responsible for this behavior.

Methods

The authors designed a controlled experimental setup using "iterative algorithms." These are tasks where a final answer is reached by repeatedly applying a rule $F(s, x)$ to an internal state $s$ and an input sequence $x$.

Iterative schemes represent reasoning as a sequence of state updates.

To study this, they trained small, two-layer transformers on these tasks using two modes:

  1. Direct Prediction: Outputting the final answer immediately.
  2. Chain-of-Thought: Outputting every intermediate state before the final answer.

They then analyzed the attention maps and weights to identify the "Iteration Head"—a specific two-layer circuit that manages the retrieval of the correct input token for each reasoning step.

Datasets

The study relies on three synthetic datasets designed to be "hard" for standard transformers but "easy" for iterative reasoning:

  • Binary Copy: Simply repeating the input sequence.
  • Parity Problem: Computing the parity of a bitstring (a classic "hard" problem for shallow networks).
  • Polynomial Iteration: Evaluating a polynomial function $P(X, Y) = XY + 1$ over a finite field $\mathbb{F}_{11}$.

These datasets are structured as: [Problem] [Inputs] [End-of-Input] [Intermediate States] [End-of-Sequence].

Key Insights and Ideas

  • The "Iteration Head" Circuit: The researchers discovered a specific pattern in two-layer models. The first layer's attention head focuses on the "End-of-Input" (EoI) token to establish a reference point. The second layer then uses this reference to perform "positional subtraction," allowing it to point to the $t$-th input token when generating the $t$-th reasoning step.
  • CoT as a "Tape": CoT effectively turns the transformer into a recurrent system. As shown in Figure 4, the auto-regressive nature of the model allows it to feed its own previous reasoning steps back into the input, creating a loop that isn't possible in a single forward pass.
Figure 4: Chain-of-thought addresses this issue by explicitly representing the reasoning process in token space. The auto-regressive nature of LLMs (blue arrow) allows for the implementation of iterative algorithms, as long as the states are encoded in token space. A concrete implementation of such a mechanism, which we call iteration head, is described in Section 3. In practical applications of LLMs, one could imagine earlier layers summarizing the t-th input sentence (or some other coherent semantic information of varying token length) into xt, as well as summarizing the generated CoT sentences into some st−1, with later layers translating the state st into readable text.
  • Skill Transfer via Data Curation: One of the most striking findings is that a model pre-trained on polynomial iteration develops an iteration head that makes it nearly trivial to learn the parity problem later. This suggests that training on structured data (like code or math) builds "reasoning primitives" that the model can reuse for other tasks.
  • The Embedding Bottleneck: The emergence of these heads is sensitive to the embedding dimension ($d$). If $d$ is too small, the model struggles to "superpose" positional and token information, leading to a failure in forming the iteration head.

Key Results

  • CoT vs. No-CoT: For the polynomial task, two-layer models using CoT achieved near-perfect accuracy even as sequence length increased, whereas models without CoT failed completely as the task complexity outstripped their depth.
  • Transfer Learning: A model trained on the parity problem from scratch took ~1000 epochs to converge. However, a model pre-trained on polynomial iteration for just 200 epochs could be fine-tuned to solve parity in fewer than 20 additional epochs.
  • Mechanistic Validation: Through "attention patching" (manually zeroing out specific attention routes), the authors confirmed that the model's accuracy depends specifically on the heads focusing on the EoI token and the corresponding input tokens.
Figure 5: Implementation of an iteration head with a two-layer transformer. Contiguous box: superposition in high-dimensional space. Blue: information brought to working space thanks to residual connections. Red: information brought thanks to attention. Green: next-token prediction. The first layer MLP implements a subtraction t = (L + t) −(L + 1) + 1 for the second attention to be able to query pt from (pL+1, pL+t). The second layer MLP implements F to be able to predict st from (st−1, xt), with the “end-of-input” mark assimilated to the initial state s0 of Algorithm 1.

Limitations and Future Work

  • Statelessness: The authors note that transformers are fundamentally stateless. To reason, they must write their state into the token space. They argue this is a potential shortcoming of the GPT architecture compared to models that might maintain an internal latent state.
  • Synthetic to Real-World Gap: While the study provides a clear "smoking gun" for how CoT works in small models, identifying these exact circuits in massive LLMs with hundreds of heads remains a significant challenge.
  • Alternative Circuits: The paper notes that in very low-dimensional settings, models sometimes find "alternative" (and less efficient) circuits to solve these tasks, suggesting that the "iteration head" is a preferred but not exclusive solution.

Summary updated

Abstract

Chain-of-Thought (CoT) reasoning is known to improve Large Language Models both empirically and in terms of theoretical approximation power. However, our understanding of the inner workings and conditions of apparition of CoT capabilities remains limited. This paper helps fill this gap by demonstrating how CoT reasoning emerges in transformers in a controlled and interpretable setting. In particular, we observe the appearance of a specialized attention mechanism dedicated to iterative reasoning, which we coined "iteration heads". We track both the emergence and the precise working of these iteration heads down to the attention level, and measure the transferability of the CoT skills to which they give rise between tasks.
BibTeX
@inproceedings{cabannes2024iteration,
  author = {Vivien Cabannes and Charles Arnal and Wassim Bouaziz and Alice Yang and Francois Charton and Julia Kempe},
  title = {{Iteration Head: A Mechanistic Study of Chain-of-Thought}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=QBCxWpOt5w},
}
Figure