Understanding Transformer Reasoning Capabilities via Graph Algorithms
Clayton Sanford, Bahare Fatemi, Ethan Hall, Anton Tsitsulin, Mehran Kazemi, Jonathan Halcrow, Bryan Perozzi, Vahab Mirrokni
TL;DR
This work analyzes transformer reasoning on graph problems under realistic parameter regimes, introducing a representational hierarchy that links task hardness to depth, width, and pause tokens and connects transformers to MPC. It proves that logarithmic-depth transformers can efficiently solve parallelizable tasks, while retrieval tasks admit highly compact single-layer solutions; shortest-path-like problems demand broader scaling. Empirically, GraphQA experiments show transformers can outperform GNNs on global graph reasoning, and trained transformers beat prompt-based LLMs, highlighting the practical potential of parameter-efficient algorithmic reasoning. The study clarifies when transformers excel at global versus local graph reasoning and sets the stage for further scaling analyses and extensions beyond graph tasks.
Abstract
Which transformer scaling regimes are able to perfectly solve different classes of algorithmic problems? While tremendous empirical advances have been attained by transformer-based neural networks, a theoretical understanding of their algorithmic reasoning capabilities in realistic parameter regimes is lacking. We investigate this question in terms of the network's depth, width, and number of extra tokens for algorithm execution. Our novel representational hierarchy separates 9 algorithmic reasoning problems into classes solvable by transformers in different realistic parameter scaling regimes. We prove that logarithmic depth is necessary and sufficient for tasks like graph connectivity, while single-layer transformers with small embedding dimensions can solve contextual retrieval tasks. We also support our theoretical analysis with ample empirical evidence using the GraphQA benchmark. These results show that transformers excel at many graph reasoning tasks, even outperforming specialized graph neural networks.
