What One Cannot, Two Can: Two-Layer Transformers Provably Represent Induction Heads on Any-Order Markov Chains

Chanakya Ekbote, Ashok Vardhan Makkuva, Marco Bondaschi, Nived Rajaraman, Michael Gastpar, Jason D. Lee, Paul Pu Liang

Introduction

In-context learning (ICL) is a defining capability of modern Large Language Models, allowing them to adapt to new tasks through prompt-based patterns without explicit parameter updates. Mechanistic interpretability research has identified "induction heads" as the primary circuit responsible for this behavior. These circuits identify patterns (e.g., seeing the sequence [A][B]) and, upon seeing [A] again, predict that [B] will follow.

Mathematically, this process is equivalent to learning a conditional $k$-gram model from a $k$-th order Markov chain. While previous theoretical frameworks suggested that at least three layers were necessary to represent these higher-order models, this paper demonstrates that a standard two-layer, single-head transformer is mathematically sufficient to represent any $k$-th order Markov process.

The Representational Challenge

The search for the minimal transformer architecture capable of ICL has been a central question in deep learning theory. Prior research established a clear hierarchy of complexity:

  1. One-layer transformers are fundamentally limited; they cannot represent higher-order induction efficiently without an exponentially large hidden dimension.
  2. Two-layer transformers were previously thought to be limited to simple 1st-order (bigram) sequences.
  3. Three-layer transformers were considered the baseline requirement for complex, $k$-th order sequences.

This paper challenges the third point, proving that the transition from 1st-order to $k$-th order complexity does not actually require an additional attention layer, provided the model utilizes its non-linear components effectively.

The "MLP Trick": Non-Linearities as Routers

The core innovation in this proof lies in the utilization of the Multi-Layer Perceptron (MLP) blocks. In traditional 3-layer constructions, attention layers are used to route information across the sequence. This paper demonstrates that the non-linearities within an MLP—specifically ReLU activations and LayerNorm—can be configured to act as "hard filters."

By using these non-linearities to isolate specific tokens within a context window, the MLP performs the routing work typically attributed to a third attention layer. This construction allows a 2-layer, 1-head transformer with an embedding dimension of $6S+3$ (where $S$ is the vocabulary size) to perfectly represent a conditional $k$-gram model. This finding reveals that MLPs are not merely feature transformers but can function as sophisticated information routers.

Learning Dynamics and Gradient Descent

Beyond theoretical existence, the authors investigate whether standard training procedures can actually discover these 2-layer solutions. They analyze the optimization process using a simplified 2-layer model and a two-stage training regime.

Their analysis provides a mathematical proof that gradient descent naturally converges to an optimal induction head solution for 1st-order Markov chains. This suggests that the compact 2-layer representation is not just a mathematical curiosity but a reachable point in the loss landscape during training.

Empirical Validation

To support their theoretical claims, the authors conducted experiments using synthetic random Markov sequences generated from Dirichlet priors. The results confirmed several key hypotheses:

  • Layer Sufficiency: 2-layer models trained on 2nd- and 3rd-order Markov data successfully learned induction patterns. The resulting attention maps closely mirrored the "ideal" patterns derived in the theoretical proofs.
  • 1-Layer Failure: 1-layer models consistently failed to learn these patterns, suffering from significantly higher cross-entropy loss (e.g., an excess loss of 0.131 compared to 0.100 for 2-layer models).
  • Architectural Equivalence: The research uncovered a depth-width tradeoff, showing that a depth-3, width-1 transformer is mathematically equivalent to a depth-2, width-2 architecture (two heads in the first layer, one in the second).

Conclusion

This work establishes that two layers represent the fundamental minimum depth for higher-order in-context learning. By proving that a 2-layer, single-head transformer can represent any $k$-th order Markov chain, the authors provide a tighter bound on transformer expressivity. The insight that MLP non-linearities can substitute for attention layers offers a new perspective on mechanistic interpretability and suggests pathways for designing more parameter-efficient architectures for sequence modeling.

Summary updated

BibTeX
@inproceedings{ekbote2025what,
  author = {Chanakya Ekbote and Ashok Vardhan Makkuva and Marco Bondaschi and Nived Rajaraman and Michael Gastpar and Jason D. Lee and Paul Pu Liang},
  title = {{What One Cannot, Two Can: Two-Layer Transformers Provably Represent Induction Heads on Any-Order Markov Chains}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=nYg6Qzm5xS},
}
Figure