Mechanistic Interpretability Techniques in Circuit Tracing (Anthropic 2025)
In the blog post “Circuit Tracing: Revealing Computational Graphs in Language Models”, Anthropic’s interpretability team introduces a methodology for dissecting model internals using an interpretable “replacement model” and attribution graphs. Below we summarize the key concepts and methods from that work, including their mathematical formulation and role in mechanistic interpretability:
Transcoders and Sparse Feature Representations
Transcoders are a class of learned interventions designed to resolve superposition by finding an alternate basis of features for a model’s activations. A transcoder is trained to approximate the function of one or more model subcomponents (typically an MLP layer) using a wider but sparsely-activating layer. In practice, this means replacing the original densely active neurons with a larger set of “features” that each fire rarely (ideally on a single human-interpretable concept). Mathematically, if is the input activation (e.g. a residual stream vector) to an MLP and the MLP’s output, a transcoder introduces an encoder matrix and decoder matrix such that:
- Encoder: , where is a high-dimensional hidden feature vector and is a sparsifying nonlinearity (e.g. a thresholded ReLU). The dimension of is larger than , allowing an overcomplete representation.
- Decoder: , producing a reconstructed output. can be viewed as defining the meaning of each feature in the original activation space.
The transcoder is trained to minimize a reconstruction loss, typically mean squared error (MSE) between the actual model output and the reconstructed output . For example, one can minimize
summing over layers if multiple layers are being approximated. To achieve sparsity, an additional penalty is added to the loss, often based on the norm of the hidden features or a saturating proxy (like a hyperbolic tangent of activations). The total loss is with tuning sparsity. Intuitively, this encourages each feature in to be mostly zero, activating only for particular inputs. In Anthropic’s implementation, they use a custom activation called JumpReLU (a thresholded ReLU with a straight-through estimator) and a tanh-based sparsity penalty to achieve a good trade-off between reconstruction fidelity and feature sparsity. They also include a small “pre-activation” loss to prevent dead (never-active) features.
Because transcoders produce sparsely activating features, these features tend to correspond to more monosemantic concepts than standard neurons. In other words, each feature often responds to a specific human-understandable pattern. The blog notes that prior work used Sparse Autoencoders (SAEs) for a similar purpose, but their approach prefers transcoders for improved circuit interpretability. An SAE likewise learns an encoder-decoder pair to reconstruct activations with a sparsity constraint (often via regularization or a k-sparse objective), typically solving:
where is a dataset of activation vectors and is a possibly nonlinear sparsity-enforcing transform (e.g. identity with an penalty, or an explicit k-sparse function). SAEs can discover an alternative basis of directions in activation space that are invisible in the neuron basis (e.g. one SAE feature might be a combination of many neurons). Both SAEs and transcoders address polysemanticity by resolving the superposition of multiple concepts in one neuron into separate sparse features. However, transcoders in this work are engineered to integrate seamlessly into a replacement model, as described next.
Interpretability use-case: By training transcoders on a pre-trained transformer’s activations, researchers can decompose the model’s computations into human-interpretable feature units. Dunefsky et al. (2024) demonstrated that transcoders can approximate GPT-2’s MLP layers faithfully while yielding features as interpretable as SAE features. In practice, one can replace the model’s neurons with these sparse features to analyze circuits. For example, Anthropic trains transcoders on an 18-layer language model’s MLPs, then replaces those MLPs with the transcoder features, obtaining similar outputs ~50% of the time. This creates a “proxy” model that is easier to interpret, since its units (features) correspond to understandable patterns (e.g. “feature that activates on the word digital”) rather than opaque linear combinations of neurons.
Cross-Layer Transcoder (CLT) and Replacement Model
A key innovation in the blog is using a Cross-Layer Transcoder (CLT). Instead of training an independent transcoder per layer, they train a single set of features that operate across multiple layers. In a CLT, each feature is associated with a specific source layer but can influence later layers. Concretely, if the original transformer has layers, the CLT defines features at each original layer . Each such feature reads from that layer’s residual stream and writes to the residual stream of all subsequent layers. Anthropic’s replacement model then substitutes the original MLP at layer with the contributions of all CLT features from layers . In formula form:
- Let be the residual stream at layer . The feature activations at layer are . This produces a sparse vector of feature activations for that layer.
- The contribution of features from a source layer to a later layer is linear: (the reconstructed MLP output at layer ) sums over all active features from earlier layers: Here is the decoder matrix mapping features from layer into the residual update at layer . In effect, a feature born at layer contributes additively to the residual streams of every subsequent layer .
Because each feature’s effect bridges over the nonlinearities of intermediate MLPs, the direct interactions between features become approximately linear. This is crucial for interpretability: if feature influences feature down the line, one can treat it (for a fixed input) as a linear dependence rather than a complicated nonlinear coupling. The replacement model constructed from the CLT thus behaves like a feedforward linear model (for fixed attention) composed of these features. Formally, Anthropic freezes other nonlinear components (the attention patterns and layer norm scaling) so that for a given input prompt, the pre-activation of any feature is an affine function of earlier feature activations. As they note, this setup is analogous to treating the network as a linearized computational graph around that input. The CLT’s outputs match the original model’s MLP outputs with reasonable accuracy (around 50% exact match on next-token output). While not perfect, this alignment means the same features that the CLT uses often correspond to actual mechanisms in the original model.
Interpretability use-case: The CLT-enabled replacement model serves as a stand-in for the original network when analyzing specific behaviors. Researchers can forward a chosen prompt through the replacement model and obtain all feature activations and their pairwise influences, which are far more interpretable than raw neuron activations. Because each feature spans multiple layers, entire multi-step computations (circuits) can sometimes be captured by a single feature’s chain of effects. The blog emphasizes that cross-layer features “greatly simplify” the circuits by reducing redundant re-encoding of the same concept in each layer. In other words, a concept first detected in layer 3 might be carried through as one persistent feature, instead of being rediscovered by separate neurons in layers 4, 5, etc. This simplification helps isolate direct feature–feature interactions, which can then be analyzed via attribution graphs.
Attribution Graphs (Per-Prompt Computational Graphs)
At the heart of Circuit Tracing is the construction of an attribution graph for a given prompt. An attribution graph is a directed acyclic graph in which nodes represent activations (of features, input tokens, or output logits) and edges represent the quantitative influence of one node on another in the replacement model’s computation. In essence, it is a causal circuit diagram of how the model computed its output for that specific input.
Nodes: The graphs include several node types:
- Primary input nodes: token embedding vectors for each position in the prompt.
- Intermediate feature nodes: active CLT features at particular layer and position (each feature at each position is a separate node if it fires).
- Error nodes: any portion of the original model’s MLP output that the CLT failed to reconstruct. (These account for approximation error by the replacement model.)
- Output nodes: the logits for the target output token(s) of interest. (Typically, they consider the top few most likely next-token logits, to focus on the relevant outputs.)
Edges: An edge between two nodes indicates that source node directly contributes to activating target node . Since the replacement model is largely linear w.r.t. feature activations, the edge weights are defined by a linear attribution:
- Let be the activation of source feature and be the effective weight connecting to in the replacement model. Then the edge attribution is . This represents how much of ‘s activation is coming from . In other words, each feature’s activation is explained as the sum of incoming edges from its predecessors.
Anthropic computes in a principled way using the model’s Jacobians. Intuitively, is the partial derivative of ‘s pre-activation with respect to ‘s activation, holding all nonlinearities fixed (no gradients propagate through other features). Formally, they use stop-gradient on the nonlinear parts and accumulate the linear paths. If is a feature at layer and a feature at layer , then:
where index the sequence position of those feature activations, and is a “stop-gradient Jacobian” that propagates linearly through the residual stream (attention outputs and skip connections) from layer to layer . In simpler terms, sums up all linear paths from feature to feature through the transformer’s residual connections (including any attention outputs along the way). Multiplying by then gives the actual contribution to ‘s value. Similarly, edges from an input token embedding to a feature use .
The result of this computation is a potentially huge graph of feature interactions for the given prompt. In practice, each prompt can activate hundreds of features per position, and edges number in the thousands or millions. To make the graph interpretable, the authors apply pruning: they algorithmically remove nodes and edges that contribute negligibly to the final output probability. They focus on the subgraph that carries the majority of attribution to the correct output token. This pruned attribution graph is the primary object of study in the paper.
Interpretability use-case: Attribution graphs provide a mechanistic explanation for why the model produced a certain output for a given input. By tracing paths from input tokens through features to the output, researchers can identify specific circuits. For example, in one case study the attribution graph revealed an “acronym-writing” circuit, involving features that detect letters in parentheses and features that cause the model to output those letters as an acronym expansion. Each edge tells which feature influences which other feature, and with what sign and magnitude. This is much more fine-grained than traditional attribution methods (like integrated gradients) because it distinguishes individual intermediate components. The approach is similar in spirit to Dunefsky et al. (2023), who also construct per-prompt feature graphs using transcoders.
By examining attribution graphs, one can hypothesize the roles of features in the circuit. The blog describes a process of manually labeling each feature node with a human-understandable description. For instance, they find an early-layer feature that activates on the token “digital” and label it “digital (input trigger)”, or a late-layer feature that directly increases the probability of the token “dag” and label it “say ‘dag’” (an output-driving feature). These labels then help interpret chains of edges: e.g. a “(first letter of acronym)” feature connects to a “say ‘D’” feature, suggesting a subcircuit for generating acronyms. Such feature visualizations and labeling are crucial to make sense of the raw graph. The authors generate feature visualizations by looking at examples of text that strongly activate a feature and the direct logit effects of that feature (which tokens it promotes or suppresses). This is analogous to classic feature visualization in vision models (where one might optimize an input to maximize a neuron), but here done by either finding dataset examples or examining the _unembedding weights that a feature feeds into. (In prior work, Anthropic indeed used optimization-based visualization for sparse features, although the blog implies they relied more on dataset-based interpretations in this study.)
Finally, once an attribution graph is built and annotated for a prompt, researchers can formulate claims like “Feature A (say, a ‘basketball’ feature) activated by the prompt causes Feature B (a ‘Michael Jordan -> basketball’ association feature) to activate, which in turn raises the logit for ‘basketball’.” These hypotheses can then be validated with causal interventions, as described next.
Causal Interventions and Validation (Activation Patching)
To ensure the attribution graph reflects actual mechanisms used by the original model, the authors perform perturbation experiments. This involves directly modifying feature activations and checking if downstream activations and outputs change as predicted by the graph. In mechanistic interpretability, this technique is often called activation patching (or interchange interventions). Activation patching means taking two inputs – a source prompt that elicits a certain behavior and a destination prompt that does not – and then transplanting some internal activations from the source run into the destination run. If doing so causes the destination’s output to switch to the source’s behavior, it implies those activations carried the causal information for that behavior.
In the context of Circuit Tracing, they intervene on one or more CLT features. For example, suppose the attribution graph suggests feature at layer 5 strongly influences an output. To test this, they can artificially boost or suppress ‘s activation and see if the final output changes accordingly. Because CLT features propagate to multiple layers, Anthropic introduces a refined method called constrained patching. The idea is to modify a feature’s decoded contribution within a specific range of layers so as to isolate its effect. If feature writes to layers 6,7,…,, one can choose a range (say layers 6–10) and replace the feature’s contributions in that range with an amplified or zeroed version, then run the model from layer 10 onwards. By not recomputing earlier or later parts, this prevents complicated feedback loops or double-counting of the feature’s influence. Essentially, patching a path means we only allow the intervention to affect a targeted route in the computation graph, rather than everything downstream indiscriminately. (This concept of path patching generalizes standard activation patching by confining the effect to a chosen “path” or subset of connections.)
Mathematically, one simple form of feature patching is: replace the activation with (for some multiplier or to ablate) and propagate its effects to the next layer(s) while holding other components constant. If is some scalar output metric (e.g. the logit difference between the originally predicted token and an alternative), we can measure caused by this intervention. The attribution graph predicts approximately by the summed contributions along edges from . Successful validation means that in the real model matches the sign and relative magnitude expected from the graph’s edge weights. The blog reports that across many prompts, these interventions were qualitatively consistent with the attribution graphs, bolstering confidence that the replacement model’s identified circuits are real mechanisms used by the original model.
In broader literature, activation patching (also known as causal tracing in some contexts) has been used to locate where specific information is encoded in a network. For example, Meng et al. (2022) used a causal tracing procedure to find which MLP layer in GPT stored a factual association: they ran a corrupted prompt (with a fact changed) and patched in the correct fact’s hidden representation at various layers to see where it fixes the output. This method identified certain middle layers as key-value memory for factual knowledge. In general, activation patching gives strong causal evidence: if replacing component ‘s activation causes a specific change in output, then was sufficient to carry the information for that change. Iterating this over many components yields a map of important pieces of the model for a task.
Interpretability use-case: In Circuit Tracing, interventions serve to verify circuits. For instance, if the attribution graph claims that a “six-related” feature causes an addition output, researchers can intervene to knock out that feature and see if the addition answer is disrupted. If yes, it confirms the feature was necessary for that part of the computation. If not, it may indicate either redundancy (another feature can fill in) or that the replacement model’s graph wasn’t fully faithful. This leads to a notion of mechanistic faithfulness: how reliably does the replacement model’s circuit reflect the true model? They measure this by the alignment of intervention effects with graph predictions. In quantitative terms, one could compute a causal score per edge or subgraph, e.g. the correlation between predicted effect (edge weight) and actual effect (change in activation or logit when source is perturbed). A high correspondence means the graph is mechanistically faithful, not just correlational. This rigorous validation step is crucial in mechanistic interpretability to avoid mistaking an explanatory story for the model’s actual workings.
Other Mechanistic Interpretability Techniques and Concepts
Beyond the specific methods highlighted in the Circuit Tracing blog, there is a rich toolbox of mechanistic interpretability techniques. We now survey major techniques not explicitly covered in the blog, each with its theoretical underpinnings and use-cases in analyzing transformer models (like GPT-3, LLaMA, etc.). We focus on the methodology and how each helps us understand model internals, including pointers to original papers or key references.
Sparse Autoencoders (SAEs) for Feature Extraction
Sparse Autoencoders are an unsupervised learning approach to identify interpretable features in neural activations. As discussed, an SAE is a type of autoencoder neural network trained to reconstruct input vectors while keeping the hidden representation sparse. For a given activation vector (for example, a residual stream slice or layer’s neuron activations), an SAE with code dimension ( is common) produces
- Encoding: , with often being elementwise nonlinearity like ReLU or identity (if using regularization separately).
- Decoding: , aiming for .
The loss function typically is:
where is a sparsity-inducing penalty on each code activation (such as , or a KL divergence to enforce being zero most of the time). By adjusting , one controls the trade-off between reconstruction fidelity and sparsity of . A common choice is (L1 penalty) or forcing the distribution of to have a low average activation (close to some small ). There are also k-sparse autoencoders that explicitly constrain to have at most nonzero entries per input.
The result is that each hidden dimension (feature) captures a recurring pattern in the inputs, and because of sparsity, each pattern is used in relatively few contexts – ideally corresponding to a semantic concept. Cunningham et al. (2023) applied SAEs to GPT-2 and found that “sparse autoencoders produce interpretable features that are effectively invisible in the neuron basis”. These features were monosemantic to a greater degree, meaning a single feature might detect “the presence of a specific name” or “the end of a sentence,” whereas any single neuron was entangled (polysemantic). The learned features can be examined by looking at which dataset examples strongly activate them or by projecting them into token space (via or ). In transformers, SAEs have been applied to various activation tensors:
- MLP layer outputs (to find features hidden in superposition among neurons).
- Attention patterns or outputs (to find sparse factors explaining attention heads’ behaviors).
- Residual stream vectors (combining both attention and MLP contributions at a position).
Use-case: SAEs are used for discovering hidden features without supervision. In a model like LLaMA, one could take all residual stream activations at a certain layer (across many text inputs) and train an SAE to find basis features. The resulting features might correspond to grammar constructs, topics, factual attributes, etc. Researchers then interpret and validate these features. For example, the SAE might find a feature that activates on sentences about geographical locations; we can verify this by checking the top activated examples or by seeing that this feature, when ablated, causes the model to lose some geographic knowledge. In the IOI (Indirect Object Identification) task from Wang et al. (2022), SAEs helped pinpoint specific features that carry the necessary information to resolve pronoun reference. Generally, SAEs address the problem of neurons being a non-orthogonal basis for the network’s internal representations – by switching to a sparsified overcomplete basis, interpretability improves.
Transcoders (Per-Layer or Weights-Based Circuit Analysis)
We already introduced transcoders as used in Circuit Tracing, but they deserve mention as a general technique. The original formulation by Dunefsky, Chlenski, and Nanda (2024) is weights-based rather than per-prompt. A per-layer transcoder is trained similarly to an SAE but with the specific goal of linearizing the action of an MLP layer. For one transformer layer’s MLP (viewed as including the GeLU and output projection), a transcoder constructs an approximating function using a wide sparse layer: , with some nonlinearity. Training to minimize over a distribution of (drawn from actual model activations) yields a faithful approximation. The important twist is that is chosen to encourage binary-like sparse activations (e.g. a steep sigmoidal or threshold function, such as JumpReLU). This way, each transcoder “neuron” either fires (essentially taking on responsibility for part of the MLP’s output on that input) or stays inactive. In the ideal limit, a transcoder unit might either exactly imitate one original neuron (if the original neuron was monosemantic) or split an original neuron’s behavior into two units (if that neuron was polysemantic).
Dunefsky et al. further showed that by analyzing the weights of a transcoder, one can perform circuit analysis in weight space. Since each transcoder feature has an encoder vector in the input space and a decoder vector in the output space, the outer product roughly represents a rank-1 component of the MLP’s overall weight matrix. The collection of all active features on some input provides a decomposition of the MLP’s transformation into a sum of sparse, interpretable pieces. If feature is active for input , it means the pattern was recognized, contributing to the output. Thus, one can interpret as detecting a concept and as the effect of that concept on the next-layer residual. By tracing connections between features of successive layers, a feature-level circuit can be assembled that mirrors the network’s computation.
In practice, transcoders have been applied to identify circuits like the greater-than circuit in GPT-2 (which determines when one number is larger than another). They found that the circuit cleanly factorized into input-dependent terms (specific comparisons) and input-independent terms (general thresholds), which is an insight that wasn’t obvious from neuron-centric analysis. Transcoders can be seen as bridging the gap between connection weight interpretation and activation interpretation: they yield pseudo-weight matrices ( terms) that are sparse and meaningful.
Use-case: For a model like LLaMA, one might train transcoders for the first few MLP layers to break down their behavior. Suppose layer 3 of LLaMA has a neuron that seems to entangle two concepts (“animal” vs “country”). A transcoder with sufficiently many units could split this into two features: one that triggers on animal-related contexts and one on country-related contexts, each then independently contributing to layer 4. By examining those features, we might discover that the model actually has a mechanism to handle these concepts separately, even though the original basis (neurons) obscured it. Furthermore, transcoders allow global circuit discovery: rather than analyzing a single input, one can analyze which features (and combination of features across layers) are responsible for a capability across many inputs. Dunefsky et al. define “feature circuits” as sets of features connected across layers that realize an algorithm.
Activation Patching (Causal Tracing in Activation Space)
Activation patching is an empirical technique to localize where in a network certain information is stored or computed. The core idea is to take two scenarios (inputs) that lead to different model outputs and then exchange intermediate activations between these runs to see which exchange causes the output difference to flip. This is effectively performing in-silico causal interventions on the computation.
For example, suppose we have two prompts for a language model: A = “The Eiffel Tower is located in Paris.” and B = “The Eiffel Tower is located in Rome.” Prompt A elicits the correct fact (“Paris”) and B an incorrect completion (“Rome”). To find where the model decides this fact, we run the model on both A and B and record all activations. Then, layer by layer (or component by component), we replace B’s activation with A’s activation and see if the output becomes “Paris.” If patching at layer is sufficient to switch the output, it means the information distinguishing Paris vs. Rome was present by layer . This method was described by Vig et al. (2020) in analyzing BERT as causal mediation analysis for attention heads, and later by Meng et al. (2022) in GPT knowledge tracing. Neel Nanda provides a clear description: “by patching in specific activations from the clean run to the corrupted run, we find which activations are sufficient to flip the model output… If a single activation is sufficient to change the entire model output, that’s strong evidence it matters!”
Mathematically, one can formalize activation patching as an intervention operator. Let be the hidden state at layer when processing input A.