Causal Methods: Patching & Circuit Discovery
Ablation, activation patching, attribution patching — and the IOI circuit as the worked example.
- → Choose the right intervention (ablate/patch/path-patch) for a question
- → Explain the IOI circuit's name movers and S-inhibition heads
- → Replicate an activation-patching experiment in TransformerLens
Looking is not enough
Everything so far has been observational. Logit lens shows you what a layer predicts. A probe shows you that a direction encodes a property. An SAE shows you a feature fires on a concept. None of that establishes that the model uses any of it.
This is not pedantry. You can train a probe to 95% accuracy on a direction the model provably never reads — the information is there, sitting in the residual stream, and nothing downstream touches it. Interpretability's central epistemic discipline is the habit of asking, about every claim: is this correlational or causal?
The variations differ in what you replace the activation with, and the choice is not innocent.
Activation patching: two directions, two questions
Activation patching is resample ablation with the resampling distribution chosen surgically. You build a clean prompt and a corrupted one that differ in exactly the property you are studying, run both, splice one activation from one run into the other, and measure the output.
Because the two prompts differ in one controlled way, the difference in outcome is attributable to that difference. This is a randomized controlled trial with a population of one, run inside a neural network.
The metric matters as much as the intervention. Logit difference is the field's default because it is linear in the residual stream — softmax normalization cancels, so a component's contribution adds up the way your intuition wants it to. Probability and accuracy are non-linear and will hide effects at the ceiling.
Heimersheim & Nanda's guide is blunt about the failure mode: patching a component and seeing no damage does not prove the component is unused. Models self-repair. Knock out the heads that do a job and other heads that were sitting idle will step in — you will see this happen for real in the IOI circuit, where ablating all three name mover heads costs only about 5% of the logit difference because backup heads take over.
The worked example: indirect object identification
Every field needs one problem that everybody has solved. In mechanistic interpretability it is IOI, from Wang, Variengien, Conmy, Shlegeris & Steinhardt (2022).
The task: complete “When John and Mary went to the store, John gave a drink to ___”. The answer is Mary — theindirect object, the name that appears once. GPT-2 small gets this right, with a mean logit difference of 3.56 over 100,000 examples and the right answer preferred 99.3% of the time. It is a real linguistic behavior, small enough to fully reverse-engineer.
Here is the algorithm a person would use:
- Identify all previous names in the sentence (Mary, John, John).
- Remove the names that are duplicated (John).
- Output the remaining name.
The remarkable finding is that GPT-2 small implements almost exactly this, in 26 attention heads across 7 classes — about 1.1% of the model's (head, token position) pairs. Three classes map onto the three steps: duplicate-token heads detect the repeat, S-inhibition heads suppress it, name mover heads copy what is left.
Two of the seven classes do not fit the story and are the most interesting part of the paper. Negative name mover heads (10.7, 11.10) write against the correct answer, apparently hedging to limit loss when the model is wrong. Backup name mover heads do nothing at all — until you ablate the name movers, at which point they take over the job.
How was it found? Backwards, from the logits. Path patch every head to the logits: three heads dominate — the name movers. Path patch every head to the name movers' queries: four heads appear — the S-inhibition heads. Path patch to the S-inhibition heads' values: the duplicate-token and induction heads appear. Each step narrows the target and each step uses path patching rather than plain patching, because the question at each step is about a specific route.
What “the circuit explains 87% of performance” means
Wang et al. did something unusual: they tried to falsify their own result, with three explicit criteria. Learning to apply them is the most transferable thing in this module.
Causal scrubbing (Chan et al., Redwood Research, 2022) pushes the idea to its logical end. You state your hypothesis as a mapping from your idealized computational graph onto the model's graph. The hypothesis licenses a set of resamplings: if you claim head 5.5 only carries “is this token duplicated”, then swapping its activation for one from any other prompt with the same duplication structure must not change the output. Scrub every activation your hypothesis says is interchangeable, and see how much performance survives.
Feel it: patch a component, read the circuit
First, run the experiment: pick a token position and a component, and see how much of the behavior one patch moves. Then read the answer key — the circuit those patches add up to.
The end of the road. These heads sit at the END position, attend to earlier names, and copy whatever they attend to straight into the logits — their copy score is above 95%. Patching them alone recovers most of the logit difference, which is why the circuit was discovered by starting at the logits and walking backwards.
Denoising runs the corrupted prompt and splices in one clean activation. A large number means this component is sufficient, on its own, to restore the behavior.
26 attention heads in 7 classes — about 1.1% of the (head, token position) pairs in GPT-2 small. Click any class to see what it does and how it was identified.
- Active at
- END
- Attends to
- previous names in the sentence — and, thanks to S-inhibition, the IO name specifically
- Writes to
- the logits, directly
Step 3: output the remaining name. They attend to a name and copy it. That is the entire mechanism — no cleverness beyond “attend to the right name.”
Copy score above 95%: feed a name through the head's OV circuit and the top output logit is that name. Patching them at END recovers most of the logit difference, which is how the circuit was found.
Things to try: (1) Select attention, layer 9 and switch between END and S2 — the same component is decisive at one position and inert at the other. Components matter at positions, and any analysis that averages over positions throws that away. (2) With END selected, compare layer 9 in denoise versus noise: patching the name movers in recovers far more than knocking them out destroys. That gap is self-repair by backup heads, and it is exactly why sufficiency and necessity need separate experiments. (3) Find the one component with a negative effect (attention, layer 11, at END) and note that any ranking by absolute effect size would have filed it with the name movers instead of against them. (4) In the circuit map, step to “2 · Inhibit it” and follow the dashed arrow: the S-inhibition heads write into queries, not values — they change where attention looks, not what it carries.
Problem set
The IOI replication is the field's rite of passage and the reason this module is 240 minutes. Do the pencil problems first; they will save you hours of confused debugging.
Clean prompt: “When John and Mary went to the store, John gave a drink to” → Mary. Here are three candidate corruptions:
- When John and Mary went to the store, Chris gave a drink to
- When John and Mary went to the store, Mary gave a drink to
- When John and Mary went to the park, John gave a drink to
For each: what does patching with it isolate, and what confound does it introduce? Which would you use to find the name mover heads, and which to find the duplicate-token heads?
You patch attention layer 9 at the END position and find: denoising recovers 58% of the logit difference; noising destroys only 34% of it.
(a) Explain why these numbers are not required to match. (b) Give the specific mechanism in GPT-2 small that produces this gap. (c) A colleague concludes “layer 9 attention is only 34% necessary, so it is not the main mechanism.” What is wrong with that inference, and what experiment settles it?
Attribution patching estimates the effect of replacing activation with as
(a) State the assumption this makes. (b) You attribution-patch every head in GPT-2 small on IOI and then verify with real patching. Where should you expect the approximation to be worst, and in which direction will it err? (c) Given that, what is the right way to use attribution patching in a discovery pipeline?
The rite of passage. In TransformerLens with GPT-2 small, build an IOI dataset of at least 100 prompts over several templates and both name orders, then:
- Establish the baseline logit difference between IO and S. You should land near 3.5.
- Patch each head's output at each token position (clean → corrupted with a third name) and produce the heatmap. Heads 9.9, 9.6, 10.0 should dominate at END.
- Path patch each head into the queries of those three heads. You should recover 7.3, 7.9, 8.6, 8.10.
- Plot the attention patterns of the name movers before and after patching the S-inhibition heads, and confirm attention moves off IO onto S1.
Success check: your heatmap reproduces Figure 3 of Wang et al. qualitatively, and your S-inhibition set matches theirs exactly.
Using the same setup, implement attribution patching: cache activations on both clean and corrupted runs, take gradients of the logit difference with respect to the clean activations, and score every (head, position) with .
Success check: produce a scatter plot of attribution score against true patching effect over all (head, position) pairs, report the correlation, and identify by name every point where the approximation is badly wrong.
State the IOI hypothesis precisely enough to scrub. For each of these three claims, write down the resampling it licenses — the set of alternative inputs whose activation you could swap in without, on your hypothesis, changing the output:
- Duplicate-token head 3.0 at S2 carries only “this token is duplicated, and the earlier copy was at position ”.
- S-inhibition head 8.6 at END carries only the token identity and position of S.
- Name mover head 9.9 at END copies whatever name it attends to.
Then say which claim you expect to survive scrubbing least well, and why.
Check yourself
Go deeper
Read the methods guide before the paper. It will save you from the three mistakes everyone makes on their first patching experiment.