Transformers Provably Learn Graph Search: Training Dynamics and the Exponential Power of Depth
Abstract
Large Language Models (LLMs) have achieved remarkable progress on complex reasoning tasks, yet the mechanisms by which they acquire reasoning capabilities and the efficiency of their reasoning remain poorly understood. In this paper, we investigate the path-finding problem over directed graphs, a symbolic abstraction of multi-step reasoning. We first characterize the architectural requirements for this task, proving that one-layer transformers require size on dense graphs to implement the key DFS child-selection primitive. While a two-layer transformer implements full DFS with size. Thus, a second layer is necessary and sufficient for near-linear DFS reasoning. We then extend this expressivity analysis to deeper models: for every , a -layer transformer implements a bounded-reachability DFS policy with look-ahead horizon , establishing an exponential increase in reachability horizon with depth. Finally, going beyond expressivity, given appropriately curated training data, we show that two-layer transformers can provably learn to execute DFS via gradient flow and generalize to unseen graphs. Together, our results provide a mechanistic account of how transformers implement graph search, how depth expands bounded look-ahead, and how such reasoning algorithms can emerge through training.
Create a lesson
Related papers
Joint Quantization and Dynamic Partitioning for Context-Aware Edge Vision Transformers
Shared title terminology · Zhu Jiaqi, Jain Prakriti, Katare Dewant et al.
BioEmu2: Scalable Emulation of Biomolecular Dynamics
Shared title terminology · Michael Gastegger, Adam E. Foster, José Jiménez-Luna et al.
Functional Depth Is Learned: Isolating the Computation That Layers Produce Only Together
Shared title terminology · JaeSeong Kim, KyungTae Lim
The Dual-Tier Sentiment Framework: Scalable Multimodal UX Attribution in Web Search
Shared title terminology · Yi Ding, Gaurav Kumar, Rui Min et al.
Auditable Financial Knowledge Graphs: Schema-Driven Construction and Intrinsic Quality Evaluation
Shared title terminology · Samarth Sarin, Lovepreet Singh, Dhagash Mehta
Average-Depth Variable Execution via Request-Local Token Routing
Shared title terminology · Pengjie Zheng, Mengwei Xie, Huan Yang et al.