Activation patching: causal experiments inside a network
Swap one internal activation from a clean run into a corrupted run and measure how much behavior comes back. Learn the recovery score, the design choices that dominate it, and why restoring a behavior doesn't prove you found the mechanism.
What runs in CodeSplash
- EXP014Activation patching and causal tracing Explained here
You will be able to
- Compute a patching effect and its normalized recovery
- Explain how the corruption, the patch location and the metric shape the result
- Distinguish sufficiency, necessity and mediation, and why single-component rankings miss interactions
From correlation to intervention
ReadAttributions and attention describe a model from its gradients or weights. Mechanistic interpretability runs experiments instead: change something inside the network and watch the output. Activation patchingActivation patchingCopies an internal activation from one run into another and measures how much of the output's difference it restores. (also called causal tracing) is the basic experiment.
Run the model twice: on a clean input that produces the behavior (the right answer to a fact question) and on a corrupted one that doesn't (the subject's name scrambled). Then rerun the corrupted input, but replace one internal activation, at a chosen layer, position or head, with its value from the clean run, and let the rest of the network compute forward.
Reference · EXP014 · Explained hereActivation patching and causal tracingProbe model computations by replacing selected activations in a corrupted or contrasting run with activations from a reference run and measuring a target behavior.The recovery score
ReadWith a behavior score (say the logit of the right answer),
means the patched component alone restores the clean behavior; means it restores nothing. Report the raw change beside : a recovery of one half of a tiny gap means little.
By hand: an interaction
ReadThe reference's toy has two hidden units and the score . The clean activations are , the corrupted ones . Patching only with its clean value raises the score by 1.93, a recovery of 0.55.
Why not all of it? The score multiplies by , and is still corrupted. The two units interact: patching each alone and adding the recoveries wouldn't give the effect of patching both. Single-component rankings miss exactly this.
Patch each hidden unit of a hand-wired network in both directions, then add a backup unit.
DExplorable · Activation patching: which units carry the answer?
Swap one hidden unit's activation between a clean and a corrupted run. How much of the answer moves with it, and what can that miss?
Patch h1 alone, clean into corrupted. How much of the logit gap comes back?
The clean and corrupted inputs differ only in x₁ (think: the subject of a prompt).
The corrupted run's x₁; everything else is shared.
The same in both runs, so units that read only x₂ shouldn't matter.
Patch
Clean into corrupted asks whether a unit is enough to restore the answer; corrupted into clean asks whether it is needed.
h₃ copies h₁ and the output takes whichever is larger, so either one alone carries the signal.
h₁
restores 100%
destroys 100%
h₂
restores 0%
destroys 0%
h₃
restores 0%
destroys 0%
h₄
restores 0%
destroys 0%
Each unit is shaded by the share of the clean–corrupted logit gap its patch moves in the chosen direction. "Restores" is the clean value patched into the corrupted run; "destroys" is the corrupted value patched into the clean run.
Commit your prediction above to see the result
Make your prediction to see the result.
Predict: a big recovery
PredictPredict first
Patching one layer's activation at the subject's position restores 90% of the right answer's logit. Have you found the layer that does the task?
Reveal
No. You've shown that this activation is sufficient, under this corruption, to carry the information. Redundant paths may do the same; patching elsewhere might also restore it; and a different corruption might give another picture. Necessity needs the reverse experiment: corrupt the component in a clean run.
Design choices that dominate
Read- The corruption. Noise added to embeddings, a swapped name and a random token test different things; corruptions can create internal states the model never sees.
- Direction. Clean-into-corrupt tests sufficiency; corrupt-into-clean tests necessity. Mediation through a path needs patching edges, not whole states.
- The metric. A logit difference, a probability or a loss can rank components differently.
- Controls. Check that patching also leaves unrelated outputs alone, and try combinations of components.
Patching activations isn't editing weights: a patch that restores a fact says nothing about whether a weight edit would change it reliably.
Where it stands in CodeSplash
ReadCheck your understanding
CheckpointCheck yourself
The clean score is 5 and the corrupted score is 1. Patching one component into the corrupted run gives a score of 2. What is the normalized recovery ?
Show the answer
Answer: 0.25
: the component restores a quarter of the gap.
Check yourself
Patching unit A alone recovers 40% and unit B alone 30%. Will patching both recover 70%?
Show the answer
Answer: b
Nonlinear interactions make single-component effects non-additive. Test combinations before ranking components.
Check yourself
Two studies patch the same model and disagree on which layer stores a fact. One corrupted the input with Gaussian noise on embeddings, the other by swapping the subject's name. What's the likely reason?
Show the answer
Answer: b
Report the corruption, direction, location and metric; conclusions depend on all four.
Recap
Recap- Patching copies a clean activation into a corrupted run; recovery is the share of the gap restored.
- Report raw changes, the corruption, the direction and the metric.
- Interactions make single-component effects non-additive.
- Restoring a behavior shows a sufficient pathway, not the unique mechanism; explained here.
Concepts in this lesson