NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Multi-head Transformers Provably Learn Symbolic Multi-step Reasoning via Gradient Descent

Tong Yang, Yu Huang, Yingbin Liang, Yuejie Chi

TL;DR

This paper provides the first theoretical proof that shallow, one-layer multi-head transformers can learn complex, multi-stage symbolic reasoning (like path-finding on trees) using gradient descent. It reveals a fascinating "mechanistic" look at how different attention heads coordinate: one head learns to navigate the graph while another acts as a "stage controller" to manage transitions between subtasks.

What Problem Does This Paper Address?

While Large Language Models (LLMs) excel at multi-step reasoning via Chain-of-Thought (CoT), we still don't fully understand how they learn these algorithmic procedures during training. Most theoretical work focuses on what transformers can represent (expressive power) rather than how they actually acquire these skills through gradient descent (optimization dynamics).

The authors tackle this gap using a canonical symbolic task: path-finding in trees. They look at two versions:

  1. Backward Reasoning: Finding a path from a leaf node (goal) to the root. This is relatively straightforward because every node has exactly one parent.
  2. Forward Reasoning: Finding a path from the root to a specific leaf node. This is much harder because a parent can have many children; the model must first "climb" to the root to identify the unique path and then reverse it.
Figure 1: An illustration of the path-finding reasoning task in a tree. Solving the forward task (finding the root-to-goal path) requires solving the backward task (finding the goal-to-root path) first.

The core question is: Can a simple, one-layer transformer be trained to solve these tasks, and if so, how do its attention heads learn to coordinate and switch between stages of reasoning?

Methods

The researchers analyze a one-layer multi-head transformer trained with standard autoregressive supervised learning and gradient descent. Their approach is two-fold:

  • Construction: They first prove that a specific configuration of weights exists that can solve these tasks using CoT. For backward reasoning, one head is enough. For forward reasoning, they show it requires at least two heads.
  • Optimization Analysis: They then prove that gradient descent, starting from zero initialization, will actually find these weights. They use a "multi-phase training dynamics" analysis to track how the model's internal attention matrices evolve over time.

For the forward reasoning task, the model is trained to output a "scratchpad" sequence: it first lists the path from goal-to-root (Stage 1) and then, upon hitting the root, reverses direction to output the root-to-goal path (Stage 2).

The multi-step reasoning process for the forward reasoning task, showing the transition between Stage 1 and Stage 2.

Datasets

The study uses randomly generated perfect binary trees for training.

  • Training: Trees of a fixed depth (e.g., depth 3 or 4) where nodes are assigned unique random IDs.
  • Testing/Generalization: To prove the model isn't just memorizing paths, they test it on unseen trees with different structures, varying depths, and different branching factors (e.g., nodes having 0 to 3 children).

Key Insights and Ideas

  • Head Specialization and Coordination: In the forward reasoning task, the heads "divide and conquer." One head becomes the Navigator, responsible for traversing edges. The other head becomes the Stage Controller, which monitors the sequence to detect when the root is reached and triggers the switch from backward to forward chaining.
  • CoT as a Depth Substitute: A major finding is that extending the reasoning length (using more CoT steps) allows a shallow model to solve problems that would otherwise require a much deeper architecture. The CoT acts as an external memory or "scratchpad" that the one-layer model can refer back to.
  • Autonomous Stage Transition: The model doesn't need an external signal to switch tasks. Through gradient descent, it learns to identify "turning points" (like reaching the root node) internally, demonstrating how hierarchical reasoning can emerge from simple training objectives.

Key Results

  • Provable Convergence: The authors provide rigorous theorems (Theorems 3 and 5) showing that the training loss converges to zero at a rate of $O(1/\epsilon)$ for backward reasoning and $O(1/\epsilon^{3/2})$ for forward reasoning.
  • Generalization: They prove (Theorems 4 and 6) that the trained model generalizes to unseen trees. This confirms the model learns the rule of tree traversal rather than memorizing specific training examples.
  • Experimental Validation: Numerical experiments match the theory perfectly. Loss curves for both tasks drop to zero, and tracking the internal weights shows them converging exactly to the " Navigator/Controller" configurations predicted by the math.
Training and test loss curves for the forward reasoning task, showing successful convergence and generalization.

Limitations and Future Work

  • Shallow Architecture: While the one-layer analysis is a breakthrough for theoretical clarity, real-world LLMs are much deeper. Future work could explore how these mechanisms distribute across many layers.
  • Synthetic Tasks: Path-finding on trees is a "clean" symbolic task. It remains to be seen how these specific mechanistic insights (like the stage controller head) translate to more ambiguous natural language reasoning.
  • Embedding Assumptions: The proofs rely on orthonormal or linearly independent node embeddings. Relaxing these assumptions to account for the high-dimensional, non-orthogonal embeddings found in practice is a logical next step.

Summary updated

BibTeX
@inproceedings{yang2025multi,
  author = {Tong Yang and Yu Huang and Yingbin Liang and Yuejie Chi},
  title = {{Multi-head Transformers Provably Learn Symbolic Multi-step Reasoning via Gradient Descent}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=qFC728XyeM},
}
Figure