Activation patching is a causal intervention technique in which the internal activations of a neural network, recorded on one input, are copied into the forward pass on a different input to measure how much a specific component changes the output. In Explainable AI, and especially in mechanistic interpretability, it is the standard way to move from correlation to causation: instead of asking which neurons light up, it asks which components are necessary or sufficient for a behavior.
The method is also called causal tracing when it scans many layers and token positions, and path patching when it restricts the intervention to specific connections between components. It underlies much of the published work on circuit analysis in transformer language models, including studies of factual recall and indirect object identification.
How activation patching isolates causal components
Activation patching compares two carefully matched inputs. The clean prompt produces the behavior of interest, for example “The Eiffel Tower is in” followed by “Paris”. The corrupted prompt differs only in the critical information, for example a different landmark, so the model predicts another city.
The procedure has three runs. The model first processes the clean prompt and caches every activation. It then processes the corrupted prompt to obtain a baseline. Finally it processes one prompt again while replacing a single activation with the cached value from the other run, such as the output of one attention head at one token position.
The effect is measured with a behavioral metric, most often the logit difference between the correct and incorrect answers. The result is usually normalized so that 0 means no recovery and 1 means full recovery of the clean behavior. Repeating the patch for every layer, position and head yields a heat map that locates the components carrying the relevant information.
The approach formalizes ideas from causal mediation analysis, where an intermediate variable is held at a counterfactual value to estimate its indirect effect. In the closely related framework of interchange interventions, the same operation is used to test whether a network implements a hypothesized high-level algorithm, which links patching to causal abstraction as a theory of model explanation.
Variants of the technique
Variants differ in the direction of the patch and in how narrowly the intervention is targeted. The table below lists the forms practitioners meet most often.
| Variant | What is patched | Question it answers |
|---|---|---|
| Denoising patch | Clean activation into the corrupted run | Is this component sufficient to restore the behavior |
| Noising patch | Corrupted activation into the clean run | Is this component necessary for the behavior |
| Causal tracing | Hidden states across layers and positions | Where is the information stored |
| Path patching | One edge between two components | Which connection carries the signal |
| Attribution patching | Linear gradient estimate of every patch | Which components to test first at scale |
| Subspace patching | A direction inside an activation | Is a specific feature responsible |
Attribution patching deserves special mention because it replaces thousands of forward passes with one forward and one backward pass. It approximates each patch with a first-order Taylor expansion, which is fast but can be unreliable where activations change sharply, such as in attention patterns or around layer normalization.
How activation patching differs from other attribution methods
Activation patching is interventional rather than observational. Gradient-based attribution, probing and attention visualization describe what a model represents or which inputs matter, but they do not prove that the model actually uses that information.
| Method | Type of evidence | Main limitation |
|---|---|---|
| Activation patching | Causal effect of internal components | Depends on the choice of corrupted input |
| Probing classifier | Information is linearly decodable | Decodable does not mean used |
| Logit lens | Intermediate predictions per layer | Assumes a shared output basis |
| Gradient × input | Local sensitivity to input features | Noisy and saturates easily |
| Ablation | Effect of removing a component | Removal can push activations off distribution |
| Attention visualization | Where attention weights point | Weights are not explanations |
Patching is closest to ablation, but it replaces an activation with a realistic value from another input instead of zero or a mean. This keeps the network closer to its training distribution and makes the measured effect easier to interpret.
Designing a reliable patching experiment
A trustworthy patching result depends mostly on experimental design choices made before any code runs. The decision table below summarizes the choices that most affect conclusions.
| Choice | Recommended practice | Reason |
|---|---|---|
| Corrupted input | Minimal pairs with matched token length | Positions stay aligned between runs |
| Corruption method | Token substitution over Gaussian noise | Noise creates unnatural activations |
| Metric | Logit difference, normalized | Linear and sensitive to partial effects |
| Dataset size | Dozens to hundreds of prompt pairs | Single prompts give anecdotal results |
| Granularity | Layers first, then heads and positions | Narrows the search efficiently |
Libraries such as TransformerLens, nnsight and pyvene expose hooks that cache and overwrite activations, which makes these experiments practical on open-weight models. They do not, however, choose a meaningful contrast between prompts; that remains the analyst’s responsibility.
Pitfalls and interpretability illusions
Activation patching gives strong but narrow evidence: it shows what matters for one metric on one distribution of prompts. Several known effects can mislead an analyst who reads a heat map at face value.
- Self-repair, sometimes called the hydra effect, lets later components compensate when one is patched, so a necessary mechanism can look unimportant.
- Backup circuits activate only when the primary path is disrupted, which hides redundancy.
- Subspace illusions appear when patching a direction changes the output through a dormant pathway rather than the feature the analyst intended.
- Metric sensitivity means probability-based metrics can hide effects that logit differences reveal, and the reverse.
- Out-of-distribution activations from noise-based corruption can produce effects that never occur on real inputs.
Good practice is to report both noising and denoising results, test the circuit on held-out prompts, and confirm faithfulness by checking that the identified components alone reproduce most of the behavior.
In plain words
Activation patching is like swapping parts between two working engines. One engine runs well. The other has a small difference. You move one part at a time from the good engine into the other one. If the second engine suddenly runs well, that part matters.
In a language model, the parts are internal signals. Researchers swap them between two similar sentences. This shows which parts of the model really cause an answer, not just which parts happen to be active.
A real-world example
An interpretability team wants to know how a 12-layer open-weight language model recalls the capital of a country. They build 200 prompt pairs such as “The capital of France is” and “The capital of Japan is”, with the corrupted prompt always using a different country of the same token length.
They first patch the residual stream at every layer and position. The heat map shows that restoring the last token of the country name in layers 4 to 7 recovers about 80 percent of the logit difference, while later layers matter mainly at the final position. Path patching then reveals two attention heads in layers 9 and 10 that move the country information to the final token.
The outcome is a compact, testable circuit hypothesis. When the team keeps only these components and mean-ablates the rest, the model still answers correctly on most held-out prompts, which supports the claim that the circuit is faithful.