Attribution patching replaces thousands of separate activation-patching forward passes with a single first-order Taylor expansion computed from two forward passes and one backward pass, delivering roughly a 30,000x speedup when screening every head and token position on a 100-token GPT-2 XL prompt. Introduced by Neel Nanda (building on work with Anthropic’s circuits team), the method trades exact counterfactual interventions for an O(1)-pass exploratory heuristic that scores heads, Q/K/V inputs, attention patterns, and component-to-component paths at once.

  • Constant-pass screening: Exhaustive per-head, per-position patching on GPT-2 XL (1,600 model width, 48 layers, 64-dim heads, 100 tokens) requires 120,000 forward passes, whereas attribution patching caches every site in 2 forward passes plus 1 backward pass (~4x a single forward pass).
  • One formula across all sites: Scoring any activation reduces to ((clean_act - corrupted_act) * corrupted_grad_act).sum(), with negligible post-cache arithmetic (O(P * M * N) elementwise ops).
  • Additive decomposition: Linearity lets one AttributionCache split into per-position slices, individual heads, or pairwise edges (direct attribution path patching) without re-running the model.
  • Sharp boundary on granularity: On GPT-2 Small Indirect Object Identification (IOI), the linear fit breaks on full residual streams and MLP0 (an extended embedding over 50,000 tokens), yet accurately tracks attention head outputs, Q/K/V vectors, and attention patterns.
Three-pass workflow and why GPT-2 XL scales to 30,000x fewer forward passes
Pass 1: Clean forward

Run X_clean once and cache every target activation tensor clean_act (head outputs, Q/K/V, MLP neurons, patterns).

Pass 2: Corrupted forward

Run X_corrupt once, caching corrupted_act and computing the patching metric (e.g. logit difference).

Pass 3: Corrupted backward

Backpropagate the metric once (~2 forward passes) to get corrupted_grad_act, then sum elementwise products.

GPT-2 XL compute for all heads x positions (100 tokens, lower is faster; log scale)
Activation patching
120,000 passes
Attribution patching
~4 passes

Source: Nanda (2023), What Is Attribution Patching & Why Care.

How It Works

Standard activation patching fixes a clean and corrupted prompt pair (X_clean, X_corrupt) and swaps one internal activation at a time to see which component flips the output metric. Because every tested location needs its own patched forward pass, scanning N layers with M / 64 heads across P token positions costs O(M * N * P) forward passes.

Attribution patching treats each patch as a small perturbation delta_a = clean_act - corrupted_act around the corrupted baseline and approximates the metric change linearly: delta_a . grad_a(metric). One clean forward pass caches clean_act, one corrupted forward pass caches corrupted_act, and one backward pass from the patching metric (roughly 2x the FLOPs of a forward pass) caches the activation gradient at every node simultaneously.

Because partial derivatives are linear, attributions add cleanly across both tensor elements and summed residual-stream terms. Summing per-position scores recovers the full-sequence score for a head; summing heads recovers the attention layer. Extending this trick across pairs of residual-stream outputs and downstream inputs (clean_early_out - corrupted_early_out dotted with corrupted_late_in_grad) approximates path patching across all head pairs in one matrix multiply. Dropping the corrupted prompt altogether gives attention attribution (clean_pattern * clean_pattern_grad), a zero-ablation proxy that highlights which source-to-destination attention links drive the metric on a single prompt.

Key Findings

Evaluating the approximation on GPT-2 Small’s Indirect Object Identification (IOI) circuit ("When John and Mary went to the store, John gave the bag to" vs swapped "Mary"), Nanda notes that raw single-pair prompts carry strong unigram priors (" John" starts roughly +1 logit above " Mary" out of a total logit difference near 3), so averaging symmetric clean/corrupted flips cancels token-frequency bias.

Across IOI components, granularity determines whether the linear approximation holds:

  • Coarse blocks fail: Patching the full residual stream or MLP0 disagrees sharply with true activation patching. MLP0 effectively extends discrete token embeddings across GPT-2’s 50,000-token vocabulary, violating local continuity, while full residual-stream patches collide with LayerNorm normalization. Because LayerNorm projects vectors onto a hypersphere of radius sqrt(d_model), its gradient along the residual direction v is zero; large patches aligned with v vanish unless practitioners freeze normalization factors (hook_scale) via stop-gradients.
  • Heads and sub-vectors hold up: Attribution patching closely matches true activation patching for later layer outputs, individual attention head outputs, Q/K/V inputs, and attention patterns, recovering key IOI induction (L5H5), S-Inhibition (L8H6), and Name Mover (L9H9) pathways.
  • Backup heads stand out strongly: When a Name Mover is ablated, downstream backup heads nonlinearly shift their attention patterns to compensate (the Hydra effect). Even if net compensation cancels out along the full path, the steep local gradient flags redundant heads on the exploratory shortlist.
Where first-order attribution patching holds vs where it breaks
Reliable: small patches

Head outputs, Q/K/V vectors, attention patterns (locally linear scaling of values), and late-layer activations near the logits.

Unreliable: big or early

Full residual stream (LayerNorm kills parallel gradients), token embeddings, and MLP0 acting as an extended discrete lookup.

Blind spots: AND & flat tails

Multi-feature AND gates (holding context fixed hides interaction terms) and saturated softmax/GELU regions with near-zero local slope.

Source: Nanda (2023), Experiments & Does This Make Any Sense?.

Caveats & Builder Takeaway

Nanda explicitly positions this write-up as an incomplete exploratory project tested primarily on GPT-2 Small IOI rather than a systematic multi-model benchmark (a gap later closed and corrected by AtP*). By design, first-order attribution cannot detect multi-feature AND interactions where two upstream signals must both flip simultaneously, and it drops false negatives whenever a clean or corrupted activation sits on a saturated softmax or GELU plateau. Furthermore, patching clean/corrupted prompt pairs only isolates components that vary between those two distributions, missing shared grammar or formatting circuits.

For engineers debugging models today, treat attribution patching as a 4-pass shortlist generator rather than proof of causality: run it at head, Q/K/V, or neuron granularity with logit difference, avoid full residual-stream attribution unless LayerNorm scales are frozen, and verify every shortlisted component with direct activation patching or causal scrubbing.