Discovering Interpretable Algorithms by Decompiling Transformers to RASP

Xinting Huang, Aleksandra Bakalova, Satwik Bhattamishra, William Merrill, Michael Hahn

Introduction: From Black Boxes to Readable Code

While Transformers demonstrate incredible capabilities, understanding how they solve specific algorithmic tasks remains a significant challenge. A popular theoretical framework known as RASP (Restricted Access Sequence Processing) suggests that Transformer computations can be conceptualized as discrete programs. However, while it is established that Transformers can represent RASP programs, proving that trained models actually implement them has remained an open question.

Existing interpretability methods, such as "circuit discovery," successfully identify active model components but typically yield complex, length-specific graphs rather than universal algorithms. This paper tackles the inverse problem: given a trained Transformer, can we extract a compact, symbolic program that explains its behavior across any input length? By developing a novel "decompilation" pipeline, the researchers demonstrate that models capable of generalizing to longer sequences do, in fact, implement simple, discrete algorithms internally.

The Decompilation Pipeline

The authors introduce a systematic method to translate a GPT-2 style Transformer into a new dialect called D-RASP (Decompiled RASP). This pipeline operates in three primary stages:

  1. Faithful Reparameterization: Operating under a "Linear Layer Norm Assumption" (which treats layer normalization as a linear operation), the authors mathematically map any Transformer to a D-RASP program. Initially, this program is exponentially large and complex, as it accounts for every possible computational path through the model's residual stream.
  2. Causal Pruning: To isolate the true algorithmic signal from the noise, the pipeline applies causal interventions. It systematically prunes edges and variables in the program that do not significantly alter the model's output. This pruning is executed in multiple stages—from components to paths to attention products—ensuring the computation remains tractable.
  3. Primitive Matching: Finally, the surviving "neural" components (such as MLPs and attention matrices) are mapped to a library of human-interpretable primitives. For instance, an attention matrix might be replaced with a symbolic rule like k == q - 1 (attend to the previous token), while an MLP might be swapped for a discrete hard-max function.

Experimental Setup

The decompilation method was validated across two primary suites of tasks:

  • Algorithmic Tasks: Including operations like Sort (sorting a list of integers), Reverse Copy, Counting, and Most Frequent (identifying the majority element).
  • Formal Languages: 17 distinct finite-state languages, featuring Tomita Grammars and Dyck Languages (which require matching parentheses at varying nesting depths).

Crucially, the models were trained on short sequences (length $\le 50$) and evaluated on their ability to length-generalize to much longer sequences (up to 150 tokens).

Key Findings and Insights

Generalization is Algorithmic

The most striking insight from the study is the strong correlation between length generalization and "decompilability." Models that successfully generalized to longer sequences were almost universally those that could be pruned into short, clean RASP programs. Conversely, models that failed to generalize remained mathematically "entangled" and messy.

Extreme Compression and Faithfulness

The pipeline successfully decompiled 8 out of 11 algorithmic tasks and 9 out of 14 formal language tasks. In one remarkable instance (the Most Frequent task), a 4-layer Transformer was initially translated into a program containing over 16 million lines. The causal pruning process condensed this massive output into a human-readable 3-line program, all while maintaining a 99% match accuracy with the original model. Overall, the extracted programs typically achieved a match accuracy of $\ge 90\%$, proving that the symbolic code faithfully replicates the black-box neural network's predictions.

Recovering Known Mechanisms

For the Unique Copy task, the decompilation pipeline automatically recovered the "induction head"—a well-documented mechanism in Large Language Model (LLM) research where a model searches for previous occurrences of the current token to predict the subsequent token.

Programs vs. Circuits

Unlike traditional interpretability methods that provide a fixed "map" of a specific input length, this decompilation method yields universal "driving rules." Because the output is a symbolic program, it is inherently independent of the input length, offering a more robust understanding of model mechanics.

Limitations and Future Directions

While this work represents a breakthrough for small-scale models, scaling the pipeline to modern LLMs presents several challenges:

  • Model Size: The initial "unfolded" program grows exponentially with the number of layers. Applying this technique to a 70-billion parameter model remains a massive engineering hurdle, despite the multi-stage pruning tricks.
  • Linearization Assumption: The method relies heavily on the Linear Layer Norm Assumption (LLNA). While valid for the algorithmic models studied, it may not hold across all architectures or training regimes.
  • Splittable MLPs: The pipeline assumes MLPs can be decomposed into single-input operations. If a model learns highly entangled representations where multiple inputs interact in complex, nonlinear ways, decompilation may fail.

Despite these hurdles, the authors propose a promising path forward: while an entire LLM might be too complex to represent as a single RASP program, this decompilation method could be used to extract interpretable "sub-programs" for specific, localized skills—such as mathematical reasoning or coding—hidden within larger networks.

Summary updated

BibTeX
@inproceedings{huang2026discovering,
  author = {Xinting Huang and Aleksandra Bakalova and Satwik Bhattamishra and William Merrill and Michael Hahn},
  title = {{Discovering Interpretable Algorithms by Decompiling Transformers to RASP}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=QnWjcTk14G},
}
Figure