Transformers Struggle to Learn to Search

Abulhair Saparov, S. Pawar, Shreyas Pimpalgaonkar, Nitish Joshi, Richard Yuanzhe Pang +4 more
2/12/2026

No official code found. Best implementation: asaparov/learning_to_search (10 stars, last commit 2025-10-22).

Abstract

Search is an ability foundational in many important tasks, and recent studies have shown that large language models (LLMs) struggle to perform search robustly. It is unknown whether this inability is due to a lack of data, insufficient model parameters, or fundamental limitations of the transformer architecture. In this work, we use the foundational graph connectivity problem as a testbed to generate effectively limitless high-coverage data to train small transformers and test whether they can learn to perform search. We find that, when given the right training distribution, the transformer is able to learn to search. We analyze the algorithm that the transformer has learned through a novel mechanistic interpretability technique that enables us to extract the computation graph from the trained model. We find that transformers perform search at every vertex in parallel: For each vertex in the input graph, transformers compute the set of vertices reachable from that vertex. Each layer then progressively expands these sets, allowing the model to search over a number of vertices exponential in $n_{\text{layers}}$. However, we find that as the input graph size increases, the transformer has greater difficulty in learning the task. This difficulty is not resolved even as the number of parameters is increased, suggesting that increasing model scale will not lead to robust search abilities. We also find that performing search in-context (i.e., chain-of-thought) does not resolve this inability to learn to search on larger graphs.

View on arXivView PDF

Code Implementations(1)

Train transformers on synthetic graph search problems to measure their scaling behavior and to do mechanistic analysis.

102C++, ShellNov 1, 202312 months ago

Similar Papers

Cite this paper

@article{saparov2026transformers,
  title  = {Transformers Struggle to Learn to Search},
  author = {Abulhair Saparov and S. Pawar and Shreyas Pimpalgaonkar and Nitish Joshi and Richard Yuanzhe Pang and Vishakh Padmakumar and Seyed Mehran Kazemi and Najoung Kim and He He},
  year   = {2026},
  eprint = {2412.04703},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2412.04703},
  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/2412.04703.svg)](https://codeofpaper.com/paper/2412.04703)

Discussion