[Paper Review] Tracr: Compiled Transformers as a Laboratory for Interpretability
Tracr compiles human-readable RASP programs into standard decoder-only transformer models with known, interpretable structure, enabling controlled experiments in interpretability. By generating models with ground-truth computational mechanisms, Tracr allows researchers to study phenomena like superposition and validate interpretability methods such as gradient-based attribution and causal tracing.
We show how to "compile" human-readable programs into standard decoder-only transformer models. Our compiler, Tracr, generates models with known structure. This structure can be used to design experiments. For example, we use it to study "superposition" in transformers that execute multi-step algorithms. Additionally, the known structure of Tracr-compiled models can serve as ground-truth for evaluating interpretability methods. Commonly, because the "programs" learned by transformers are unknown it is unclear whether an interpretation succeeded. We demonstrate our approach by implementing and examining programs including computing token frequencies, sorting, and parenthesis checking. We provide an open-source implementation of Tracr at https://github.com/google-deepmind/tracr.
Motivation & Objective
- To address the lack of ground-truth explanations in interpretability research by creating transformer models with known, human-readable computational mechanisms.
- To provide a reproducible and structured environment for testing interpretability tools, where the true computation is known in advance.
- To enable controlled investigation of neural network phenomena such as superposition in models executing multi-step algorithms.
- To serve as a didactic and experimental platform for understanding transformer mechanics through compiled, traceable models.
- To support evaluation of interpretability methods like classifier probes, gradient attribution, and causal tracing using models with known behavior.
Proposed method
- Tracr compiles RASP (a domain-specific language for transformer computations) into standard decoder-only transformer architectures with known structural components.
- The compiler generates models where each layer's function—such as computing indicators, selecting tokens, or aggregating values—maps directly to high-level program operations.
- The residual stream is used as a central memory mechanism, with attention and MLP layers explicitly designed to implement specific computational steps (e.g., selection, aggregation).
- The method leverages the transformer circuits perspective, parameterizing attention via query-key and value-output matrices to enable modular, interpretable design.
- Models are trained via gradient descent, and their internal representations are analyzed to verify correct implementation of algorithms like frequency counting, sorting, and parenthesis checking.
- Superposition is studied by compressing trained models, observing how features are pruned or represented in low-dimensional subspaces.
Experimental results
Research questions
- RQ1Can transformer models compiled from RASP programs be used to create ground-truth benchmarks for evaluating interpretability methods?
- RQ2How do compressed transformer models represent features in superposition, and do they drop unimportant features as predicted by theory?
- RQ3To what extent can interpretability tools like gradient-based attribution or causal tracing correctly recover the known computational structure of Tracr-generated models?
- RQ4Can multi-step algorithms such as sorting or parenthesis checking be reliably compiled into transformers with interpretable attention and MLP patterns?
- RQ5What are the limitations of implementing complex logical operations (e.g., OR, AND) in attention-based selectors when using rank-1 predicates?
Key findings
- Tracr successfully compiles RASP programs into transformer models that correctly implement algorithms such as token frequency counting, sorting, and parenthesis checking with known internal mechanisms.
- The compiled models exhibit clear, interpretable attention and MLP patterns: for example, one attention head computes selection and another performs aggregation, matching the intended program logic.
- When compressed via gradient descent, Tracr models drop unnecessary features and represent less important features in superposition, confirming predictions from Elhage et al. (2022b).
- The models enable validation of interpretability tools—e.g., gradient-based attribution and causal tracing—by providing a known ground-truth mechanism to compare against.
- Boolean operators like OR in selectors can be implemented only under specific conditions (e.g., shared s-ops), and the general case is limited by rank-1 predicate constraints.
- The approach demonstrates that complex algorithms can be compiled into transformers with predictable, modular components, supporting both research and pedagogical use.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.