Mechanism and Emergence of Stacked Attention Heads in Multi-Layer Transformers

Tiberiu Musat
2/12/2026

No confident code implementation found for this paper.

Abstract

In this paper, I introduce the retrieval problem, a simple yet common reasoning task that can be solved only by transformers with a minimum number of layers, which grows logarithmically with the input size. I empirically show that large language models can solve the task under different prompting formulations without any fine-tuning. To understand how transformers solve the retrieval problem, I train several transformers on a minimal formulation. Successful learning occurs only under the presence of an implicit curriculum. I uncover the learned mechanisms by studying the attention maps in the trained transformers. I also study the training process, uncovering that attention heads always emerge in a specific sequence guided by the implicit curriculum.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Cite this paper

@article{musat2026mechanism,
  title  = {Mechanism and Emergence of Stacked Attention Heads in Multi-Layer Transformers},
  author = {Tiberiu Musat},
  year   = {2026},
  eprint = {2411.12118},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2411.12118},
  journal = {ICLR 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2411.12118.svg)](https://codeofpaper.com/paper/2411.12118)

Discussion