6.3.9Interpretability & Explainability

Activation patching

2,266 words10 min readdifficulty · medium

Activation patching is a causal intervention technique in mechanistic interpretability that isolates the specific role of a component (neuron, attention head, layer) by replacing its activations from one input with those from another, then measuring the downstream effect on model behavior.

Figure — Activation patching

Core Intuition

Why Not Just Look at Attention Weights?

Attention weights show correlation, not causation. A head might attend to pronouns but not actually use that information. Patching tests: "If I remove this component's ability to see the clean input, does the model's behavior change?"

The Mechanism

Worked Examples

Common Mistakes

Variants & Extensions

1. Activation Addition (Opposite Direction)

Instead of replacing with clean activations, add a steering vector: apatched()=aoriginal()+αvsteera^{(\ell)}_{\text{patched}} = a^{(\ell)}_{\text{original}} + \alpha \cdot v_{\text{steer}}

Used for: Enhancing capabilities (e.g., "add more French-ness" to translation)

2. Path Patching

Don't patch the entire layer—patch only the path from component A → component B.

Why? Isolates direct vs. indirect effects. Maybe head 3.2 doesn't directly solve the task, but it feeds head 5.1 which does.

Technique: Replace residual stream contribution from A→B specifically, leave other paths intact.

3. Iterative Patching

Patch components in sequence, always keeping the best patches from previous steps. Builds a minimal circuit that explains behavior.

Connections

  • Mechanistic Interpretability: Activation patching is the primary tool for circuit discovery
  • Causal Scrubbing: Formalization that generalizes patching with ground-truth circuits
  • Ablation Studies: Removing components is "patching with zeros"—less informative than counterfactual patching
  • Logit Lens: Complements patching by showing what representations exist; patching shows why they matter
  • Causal Mediation Analysis: Statistical framework patching implements for neural networks

Active Recall

Recall Explain to a 12-year-old

Imagine your brain is solving a math problem, but one part gives you the wrong number. You want to figure out: "Which part of my brain messed up?"

Here's what you do: You solve the problem twice. First time, you get it wrong. Second time, someone whispers the correct number for just one step in your brain. If suddenly you get the whole problem right, you know: "Aha! That step was the one that mattered!"

That's activation patching. We take a robot brain (neural network) doing something wrong, and we secretly give it the "correct" information for one tiny part. If the robot suddenly works, we know that part was super important. It's like being a detective, but for robot thoughts!

#flashcards/ai-ml

What is activation patching? :: A causal intervention technique where you replace a component's activations from a corrupted run with those from a clean run, then measure if behavior is restored—proving that component was causally responsible for the correct behavior.

Why is patching better than just measuring activation magnitude? :: Activation magnitude shows correlation (what fires together), but patching shows causation (what's actually necessary). A neuron can activate strongly but be redundant or epiphenomenal.

Write the formula for causal effect and explain each term :: ΔC=L(f(xcorrupt))L(f(xcorruptpatch C))\Delta_C = \mathcal{L}(f(x_{\text{corrupt}})) - \mathcal{L}(f(x_{\text{corrupt}} | \text{patch } C)). It measures loss reduction when patching component C. Positive Δ means patching helped (lowered loss), larger values mean stronger causal role.

What's the difference between patching and ablation?
Ablation removes a component (sets to zero/mean), showing what happens without it. Patching replaces with a counterfactual activation, showing what happens with different information. Patching gives cleaner causal attribution.
You patch head 4.2 and behavior doesn't change. What does this mean?
Head 4.2 is not causally important for this specific behavior, even if it activates. It could be redundant, epiphenomenal, or working on a different task.
What is path patching?
Patching only the specific information flow from component A to component B, leaving other paths intact. Isolates direct causal effects from indirect ones.
How do you detect if two components are redundant vs. synergistic?
Calculate synergy = Δ(A∪B) - (ΔA + ΔB). Negative synergy means redundant (overlap), positive means synergistic (they cooperate), zero means independent.
Why must your metric match your research question?
Generic metrics (like overall cross-entropy) average over all behaviors. If you're studying toxicity detection, you need to measure the specific toxic token logit, not average loss across all tokens.

Concept Map

is a

isolates role of

provides

run with

replaces C in

measured by

quantifies

large positive means

shows correlation only, so use

Activation patching

Causal intervention

Clean input x_clean

Corrupted input x_corrupt

Target component C

Patched run

Causal effect delta_C

Loss vs clean answer

Attention weights

Clean activation

Causally important

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Activation patching ek detective jaisa technique hai jisme hum neural network ke specific parts ko test karte hain. Socho ki ek robot galat answer de raha hai—hum janna chahte hain ki "kaun sa part responsible hai is mistake ke liye?"

Basic idea simple hai: Hum dobaar model chalate hain. Pehli baar, sahi input dete hain aur model sahi output deta hai. Dusri baar, galat input dete hain aur model galat ho jata hai. Ab detective mode start: Hum galat run mein se ek specific layer ya attention head ke activations ko temporarily swap kar dete hain sahi run ke activations se. Agar suddenly model sahi answer dene lag jaye, matlab us component ne hi solve kiya tha original problem ko! Ye correlation nahi, causation hai—hum prove kar rahe hain ki ye part actually important hai, sirf coincidence nahi.

Ye technique bahut powerful hai kyunki traditional methods sirf dekhte the ki "kis neuron mein zyada activation hai" (high magnitude = important lagta hai). Lekin patching se pata chalta hai ki high activation ka matlab zaroori nahi ki wo component actually kuch kaam kar raha hai—shayad wo redundant hai ya sirf side-effect hai. Isliye interpretability research mein patching ab gold standard ban gaya hai circuits discover karne ke liye. Jab tum transformer models mein specific behaviors (jaise pronoun resolution ya factual recall) ko understand karna chahte ho, activation patching se tum exact mechanism ko isolate kar sakte ho—kaun sa head kis information ko process karta hai, kis layer pe computation hota hai, sab kuch systematically test ho sakta hai.

Go deeper — visual, from zero

Test yourself — Interpretability & Explainability

Connections