Discovering Interpretable Algorithms by Decompiling Transformers to RASP
Xinting Huang, Aleksandra Bakalova, Satwik Bhattamishra, William Merrill, Michael Hahn
TL;DR
This work tackles mechanistic interpretability of Transformers by proposing a decompilation pipeline that reconstructs human-interpretable RASP-like programs from trained models. The core idea is to reparameterize Transformers as Decompiled RASP (D-RASP) programs under a linear layer norm assumption and then prune the resulting program to a minimal, causal substructure that faithfully reproduces the model’s behavior. Empirical results on small GPT-2 style models trained on algorithmic and formal-language tasks show that length-generalizing models often implement compact, readable RASP programs (e.g., histogram-based majority, induction-head copying, Dyck language counting), while non-length-generalizing models resist such simplification. This provides direct evidence that, at least in controlled settings, Transformers encode simple, interpretable algorithms that can be automatically extracted, supporting the length-generalization conjecture and offering a pathway toward systematic interpretability of neural computation.
Abstract
Recent work has shown that the computations of Transformers can be simulated in the RASP family of programming languages. These findings have enabled improved understanding of the expressive capacity and generalization abilities of Transformers. In particular, Transformers have been suggested to length-generalize exactly on problems that have simple RASP programs. However, it remains open whether trained models actually implement simple interpretable programs. In this paper, we present a general method to extract such programs from trained Transformers. The idea is to faithfully re-parameterize a Transformer as a RASP program and then apply causal interventions to discover a small sufficient sub-program. In experiments on small Transformers trained on algorithmic and formal language tasks, we show that our method often recovers simple and interpretable RASP programs from length-generalizing transformers. Our results provide the most direct evidence so far that Transformers internally implement simple RASP programs.
