A Mechanistic Analysis of a Transformer Trained on a Symbolic Multi-Step Reasoning Task

Jannik Brinkmann, Abhay Sheshadri, Victor Levoso, Paul Swoboda, Christian Bartelt

Introduction

While Transformer-based models have demonstrated remarkable performance on complex reasoning benchmarks, a fundamental question remains: are these models truly performing multi-step reasoning, or are they merely utilizing sophisticated pattern matching and memorization? Most evaluations of large language models (LLMs) are behavioral, focusing on the relationship between inputs and outputs. This approach, however, treats the model as a "black box," leaving the underlying computational processes opaque.

This research adopts the lens of mechanistic interpretability to bridge the gap between performance and understanding. By training a small Transformer on a controlled, symbolic pathfinding task, the authors aim to identify the specific internal circuits and algorithms the model employs to solve multi-step problems. This approach allows for the observation of the model's internal "gears" without the confounding variables of natural language and common-sense heuristics.

Methodology and Task Design

The study utilizes a 6-layer, 1.2-million parameter decoder-only Transformer. To ensure the model must learn structural logic rather than linguistic shortcuts, it was trained on a Synthetic Symbolic Reasoning Dataset. This dataset consists of randomly generated binary trees with 16 nodes. The model is presented with a shuffled list of edges (e.g., 2 → 1, 3 → 2), a designated "Goal Node," and a "Root Node." Its task is to output the correct path from the root to the goal. The training set comprised 150,000 trees, with 15,000 unseen trees reserved for testing.

To analyze the model's internal state, the researchers employed several state-of-the-art interpretability techniques:

  • Linear Probes: Classifiers trained to detect if specific structural information (e.g., parent-child relationships) is encoded in hidden states.
  • Activation Patching & Causal Scrubbing: Interventions that isolate specific activations to determine their causal role in the model's output.
  • Tuned Lens: A method to "preview" intermediate layer computations by mapping the residual stream to the output vocabulary.
  • Circuit Analysis: An investigation of Query-Key (QK) and Output-Value (OV) circuits to understand how information is moved between tokens.

Mechanistic Insights: The Backward Chaining Algorithm

The analysis revealed that the model does not reason forward from the root. Instead, it implements a backward chaining algorithm. Starting from the goal node, the model "climbs" the tree toward the root. Each layer of the Transformer effectively computes one step upward in the hierarchy.

Deduction Heads

The researchers identified specialized attention heads, termed "deduction heads," which are central to this process. These heads search the context for an edge where the current node is the "target" and then copy the corresponding "source" node into the current state. This allows the model to iteratively reconstruct the path in reverse.

Parallelization via Register Tokens

A significant finding of this study is the model's use of "register tokens." Because a Transformer's sequential reasoning capacity is limited by its depth (number of layers), it must find ways to handle paths longer than its layer count. The model repurposes tokens that carry no semantic meaning—such as commas or brackets—as a parallel working memory. It computes different sub-paths in parallel across these tokens and merges the information at the final layer. This "parallelization motif" allows a 6-layer model to solve reasoning chains that would otherwise exceed its depth.

Heuristic Fallback

In instances where the path complexity exceeds the capacity of its logical circuits, the model exhibits a "one-step lookahead" heuristic. It identifies which child nodes are not leaves to make an educated guess, showing that the model can transition between rigorous logic and probabilistic heuristics when pushed to its limits.

Key Results and Validation

The model achieved an impressive 99.7% accuracy on unseen trees, indicating the acquisition of a generalizable algorithm rather than memorization. The mechanistic theories were validated through causal scrubbing, where the researchers recovered nearly 100% of the model's performance by preserving only the activations associated with the hypothesized backward chaining circuit. Furthermore, linear probes reached an F1 score of 92.82% in identifying sub-paths stored in register tokens, providing strong evidence for the parallel working memory theory.

Discussion and Limitations

While this study provides a clear view of how a Transformer can implement symbolic reasoning, several limitations remain. The findings are based on a highly structured synthetic task; it is currently unknown if these same deduction heads or register token motifs emerge in large-scale models trained on natural language. Additionally, the analysis suggests that the model's choice of algorithm may be sensitive to the input format, such as the order of edges in the prompt. Future research will investigate whether larger models develop more complex recursive motifs or simply scale the parallelization strategies identified here.

Summary updated

BibTeX
@inproceedings{brinkmann2024mechanistic,
  author = {Jannik Brinkmann and Abhay Sheshadri and Victor Levoso and Paul Swoboda and Christian Bartelt},
  title = {{A Mechanistic Analysis of a Transformer Trained on a Symbolic Multi-Step Reasoning Task}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.242},
}
Figure