NeurIPS 2026QuestionsPapersAreasAboutMarkdown

Transformers Provably Learn Graph Search: Training Dynamics and the Exponential Power of Depth

Xutao Ma, Somayeh Sojoudi

NeurIPS page · Open on the map

Category: Interpretability & Model Adaptation › Transformer Models · Type: theory · Keywords: transformer depth, graph search, expressivity, theoretical analysis, learning dynamics

Areas: LLM Reasoning › Reasoning Mechanisms › Looped Reasoning; Model Architectures & Sequence Modeling › Language Model Architectures › Algorithmic Transformers

Summary

The paper proves that transformer depth is necessary and sufficient for efficient graph search, showing exponential gains with depth and demonstrating that two-layer transformers can learn DFS via gradient flow.

Explained to a 5-year-old

Computers called transformers can solve puzzles that need many steps. The paper shows that adding more layers makes them solve these puzzles much faster. It proves that a simple one-layer model needs a lot of memory, but two layers are enough. It also shows that even deeper models can look far ahead, like seeing many steps at once. Finally, it shows that these models can actually learn to solve the puzzles on their own.

Explained to a 5-year-old, longer

A transformer is a kind of computer program that can think step by step. The researchers looked at how well these programs can find a path through a maze made of connected nodes. They discovered that a very thin program (one layer) needs a huge amount of memory to do this, almost as big as the whole maze squared. A slightly thicker program (two layers) can do the same job with far less memory, almost like the size of the maze times its logarithm. When they made the program even thicker (more layers), it could see many steps ahead at once, giving it an exponential boost in speed. They also showed that with the right training data, the two-layer program can actually learn to solve new mazes it has never seen before. This gives us a clear picture of why depth matters in these models and how they can acquire complex reasoning abilities.

For a technical reader

The work analyzes how many layers a transformer needs to solve graph-search problems efficiently. It proves lower-bound requirements for shallow models and shows that adding a second layer reduces the needed size from quadratic to near-linear. Deeper models are shown to provide an exponential increase in look-ahead capability. Finally, the paper demonstrates that, with appropriate data, gradient descent can actually cause a two-layer transformer to learn the DFS algorithm and generalize to new graphs.

Problem

How do transformers acquire reasoning capabilities and how efficiently can they perform multi-step reasoning? Specifically, what architectural requirements are needed for transformers to solve path-finding over directed graphs?

Method

The authors conduct a theoretical analysis of transformer expressivity, proving size requirements for DFS implementation and deriving exponential gains with depth, and complement this with a gradient-flow learning analysis on curated graph data.

Results

The results show that one-layer transformers need quadratic size, while two-layer transformers achieve near-linear size, and deeper models provide an exponential look-ahead horizon; additionally, two-layer transformers provably learn DFS and generalize to unseen graphs.

Contributions

The paper provides theoretical proofs of depth's necessity and sufficiency for graph search, demonstrates exponential efficiency gains with depth, and establishes provable learning dynamics for DFS in transformers.

Research questions this paper is counted under

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction