Towards Best Practices of Activation Patching in Language Models: Metrics and Methods
TL;DR. Activation patching runs a model on a clean prompt and a minimally different corrupted prompt, then copies one internal activation from one run into the other and measures how much of the output gap moves. Zhang and Nanda show that the answer depends heavily on two choices that papers rarely justify: how you corrupt (Gaussian noise vs token replacement) and which metric you read off (probability, logit difference, KL). Their recommendation is in-distribution token replacement plus logit difference.
Why it matters now. Patching is the basic causal tool of mechanistic interpretability: ROME’s causal tracing, the IOI circuit and every “this head computes relevance” result in neural IR are patching experiments. If you plan to reverse-engineer a reranker or an embedding model, as in Axiomatic causal interventions and Cross-encoders as semantic BM25, these choices decide whether your circuit is real. This page also covers two companion papers: Heimersheim and Nanda’s tutorial (2404.15255) and attribution patching at scale, AtP* (2403.00745).
Key idea
Section titled “Key idea”Three forward passes on prompts and that differ in one controlled way (e.g. “The Eiffel Tower is in” vs “The Colosseum is in”):
- Clean run: cache every activation .
- Corrupted run: record the output, e.g. the logit difference between the clean answer and the corrupted answer .
- Patched run: rerun on but overwrite one node (a head, an MLP output, or a residual position) with its clean value, and re-measure.
The normalised effect of node is
where is the corrupted run: 0 means “restores nothing”, 1 means “restores everything”. The paper also defines a probability metric and a KL metric .
Two corruption methods. Gaussian noise (GN), from ROME, adds to the subject-token embeddings with equal to 3 times the embedding standard deviation. Symmetric token replacement (STR) swaps the key tokens for similar real tokens. STR uses realistic counterfactual prompts and tends to reduce distribution shift relative to Gaussian corruption; it does not guarantee that patched hybrid states are in-distribution.
Two directions. Patching clean into corrupt (denoising) tests whether a component is sufficient. Patching corrupt into clean (noising) tests whether it is necessary. The tutorial’s example: for an AND of two components, only noising finds them; for an OR, only denoising does.
Attribution patching. Exact patching costs one forward pass per node. AtP replaces it with a first-order Taylor expansion around the clean run. As written below (the AtP* convention), it approximates noising: corrupt values patched into the clean run. To approximate the denoising patch drawn in the diagram’s patched row, use the gradient at the corrupted input and the clean-minus-corrupt activation difference instead.
One backward pass gives the gradient for every node at once, so two forward passes plus one backward pass score all nodes. AtP* reports this matters at scale: Chinchilla 70B has about 2.7·10⁹ neuron nodes on a 1024-token prompt.
Key results
Section titled “Key results”- Corruption changes the localization (§3). On factual recall in GPT-2 XL (PairedFacts, 145 prompt pairs), MLP patching at the last subject token shows a clear peak near layer 16 under GN that is barely visible under STR; across window sizes the GN peak is 2–5× higher. In IOI (500 prompts), GN also changes how Name Mover heads attend: they put 0.58 attention on the indirect object in clean runs, STR preserves this pattern, and under GN attention is split between IO and S1 (0.26 and 0.21).
- Metric changes the localization (§4). The ratio of total effect at the last subject token to the middle subject tokens is 4.33× under probability vs 1.22× under logit difference with STR (1.74× vs 0.77× with GN).
- Negative heads (§4). Negative Name Mover head 11.10 in IOI is detected under logit difference but missed under probability: its probability effect is −0.022 against a mean of 0.003 and SD of 0.015. It cannot go below −0.03, because the corrupted run already gives the indirect object probability 0.03.
- Recommendations (§6). Use STR with logit difference; try several corrupted-token choices, since corrupting different positions surfaces different heads (corrupting both S1 and IO is needed to find all three Name Mover heads). Experiments cover models up to 6B parameters.
- AtP* (2403.00745). On Pythia 410M–12B, AtP beats the alternatives they test for ranking nodes, but has false negatives from attention saturation and cancellation. The QK fix costs under two extra forward passes; GradDrop costs one extra backward pass per layer.
Limitations & open questions
Section titled “Limitations & open questions”- No corruption is neutral. STR needs a well-chosen counterfactual; for open-ended tasks (long documents, agent traces) a clean “same except one fact” pair is hard to build.
- Patching tells you where an effect flows, not what the component computes. A large effect can come from a component that just moves information.
- Negative and self-repairing components remain hard to interpret; the tutorial lists them as unsolved.
- Patching results are not the same as edit targets: Hase et al. (2301.04213) find that causal-tracing localization does not predict which layer is best to edit (see ROME).
Connections
Section titled “Connections”- ROME uses GN causal tracing to pick its edit layer, which is exactly the setting this paper revisits.
- Axiomatic causal interventions and MechIR apply patching to bi-encoders and cross-encoders with axiom-based perturbations.
- Activation addition uses the same activation differences, but to steer instead of to localize.
- TransformerLens and NNsight are the libraries most people use to run these experiments.
- Mor Geva’s job talk covers FFN layers as key–value memories, the object most patching studies of factual recall end up pointing at.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
A reranker head is patched from the clean run into the corrupted run. The logit difference is LD_clean = 3.0, LD_corrupt = −1.0 and LD_patched = 1.5. (a) Give the normalised patching effect. (b) An attribution-patching estimate for a scalar node with n_clean = 0.5, n_corrupt = 2.0 and ∂L/∂n = −0.8 at the clean input: what is Î, and what sign of effect does it predict for noising this node?
What a strong answer covers
- (a) (LD_pt − LD_corrupt)/(LD_clean − LD_corrupt) = (1.5 − (−1.0))/(3.0 − (−1.0)) = 2.5/4 = 0.625, so the head restores about 62% of the clean–corrupt gap.
- (b) Î = (n_corrupt − n_clean)·∂L/∂n = (2.0 − 0.5)·(−0.8) = −1.2: inserting the corrupted value is predicted to lower the metric by 1.2.
- The estimate is a first-order Taylor expansion around the clean activation, so it is exact only if L is linear in n along that segment; a move of 1.5 units is not small.
- Normalisation makes 0 mean "no restoration" and 1 mean "full restoration", so values above 1 or below 0 flag over-restoration or negative components rather than errors.
- Mechanism
Why can Gaussian-noise corruption of the subject embeddings make a component look important when symmetric token replacement does not? Explain using what the downstream layers see in each case.
What a strong answer covers
- Noise of 3σ on the embeddings produces inputs that never occur in training, so later components can behave in ways they never would on real text (off-distribution).
- STR swaps in a real, similar token (e.g. another landmark), so the corrupted run itself is a realistic counterfactual prompt and only the fact-specific information changes. This tends to reduce distribution shift relative to GN, though the patched hybrid states are still not guaranteed to be in-distribution.
- Under GN, restoring one MLP can look decisive because it pulls the stream back toward the data manifold, not because it carries the fact. The paper finds GN peaks 2–5× higher than STR for MLP patching at the last subject token.
- In IOI, GN also disrupts the Name Mover heads' attention pattern (attention to IO is 0.58 on clean prompts but is shared 0.26/0.21 between IO and S1 under GN), which is a side effect of the corruption, not of the circuit.
- What if…
The paper compares probability, logit difference and KL as patching metrics on factual recall. What did switching from probability to logit difference change, and why does probability systematically miss negative components?
What a strong answer covers
- Ratio of effect at the last subject token vs middle subject tokens: 4.33× under probability vs 1.22× under logit difference with STR (1.74× vs 0.77× with GN), so the "last subject token" story is partly a metric artefact.
- Probability is a sigmoid-like function of logits. When the corrupted run already gives the answer low probability, a component cannot lower it much further, so its negative effect is bounded (for Negative Name Mover head 11.10 in IOI, the corrupted P(IO) of 0.03 bounds the effect at ≥ −0.03, so its −0.022 stays inside 2 SD of the mean and the head is missed).
- Logit difference is linear in the residual stream contributions, so positive and negative heads show up with comparable scale.
- KL compares whole output distributions; it is general but less targeted and cannot say which direction a component pushes.
- Mechanism
Denoising (patch clean into corrupt) and noising (patch corrupt into clean) can give different maps. Using an AND-gate and an OR-gate circuit, explain which method finds which components and what each tests.
What a strong answer covers
- Denoising asks whether a component is sufficient to restore the behaviour; noising asks whether it is necessary to keep it.
- AND gate (output needs A and B): denoising A alone restores nothing because B is still corrupted, so it misses both; noising either A or B breaks the output, so noising finds both.
- OR gate (A or B suffices): noising one leaves the other working, so noising misses both; denoising either one restores the output, so denoising finds both.
- Practical rule from Heimersheim and Nanda: run both and report which; a circuit claim needs both sufficiency and necessity evidence.
- Critique
Attribution patching (AtP) ranks billions of nodes with two forward passes and one backward pass. Name the two failure modes AtP* fixes, why each produces false negatives, and an experiment that would falsify an AtP ranking for one head.
What a strong answer covers
- Attention saturation: if a softmax is saturated, its gradient is near zero even though a large change in a query or key would flip the attention pattern. The QK fix recomputes the softmax with the patched queries and keys, costing under two extra forward passes.
- Cancellation: a node's direct and indirect effects can cancel in the gradient while the real patch still has a large effect. GradDrop zeroes the gradient through each layer in turn and averages absolute estimates, at the cost of extra backward passes.
- Both errors come from the linear (first-order) approximation being evaluated only at the clean point.
- Falsification: take heads AtP ranks low but just below the cut-off and run real activation patching on them; a large true effect on any of them shows the ranking missed it. AtP* recommends verifying top candidates this way anyway.
- Design
You want to find which components of a 12-layer MS MARCO cross-encoder implement the term-frequency axiom. Design the patching experiment: corrupted inputs, metric, patching direction and the sanity checks you would report.
What a strong answer covers
- Corruption in the spirit of STR: pairs that differ only in one query-term occurrence (inject the term vs a filler token of the same length), so the inputs are realistic text (patched hybrid states can still be off-distribution).
- Metric: the relevance logit difference between the two documents, normalised by the clean–corrupt gap so that 0 means no restoration and 1 means full restoration; not a probability. Do not clip: effects can be negative or exceed 1, and near-zero baseline gaps need separate handling.
- Patch from the higher-scoring run into the lower one (denoising) per layer, position and head; then noise the top heads to test necessity.
- Sanity checks: vary the injected position and term IDF, check sign of effects, verify top heads with mean ablation, and confirm with path patching that effects flow into the scoring position.