Phase C · mechanistic interpretability

Attribution / edge patching

Nanda 2023; Syed et al. 2023

← back to the method catalogue

What it does?

Attribution patching is a fast, gradient-based approximation to activation patching. Exact patching requires a separate re-run for every internal value tested, which is expensive on a large network. Attribution patching instead uses a first-order, linear estimate: it multiplies the gradient at each site by the change that patching would apply, to predict the patch's effect in a single backward pass. This lets researchers screen thousands of sites at once, at industrial scale, and only re-run the exact patch on the promising ones. We apply it to the VCS by forming the gradient-linear estimate of each site's patch effect and comparing it to the exact effect the oracle measures. The comparison is unusually clean here because we have the exact answer for every site. The linear surrogate keeps the edges precise: it is usually right about which dependencies exist, because a real edge tends to have a non-zero gradient. What it gets wrong is the size of an edge, since the true relationship is not linear, so its numerical agreement with the exact patch is only partial. Attribution patching is therefore a good cheap screen with a measurable error, and the VCS lets us quantify exactly how much accuracy the approximation trades away for its speed.

Attribution / edge patching result

Each point is one intervention site: its exact causal effect from the oracle (x) against the method's recovered/approximate effect (y). Points on the dashed diagonal mean the method recovered the true effect. corr_approx_vs_exact = 0.876 — this example only (pong, state gameplay(seed=0,prefix=90)+15); the audit aggregate is below.

How it's scored

The score is the Pearson correlation between the gradient-approximate patch effect and the exact patch effect from the oracle. The grading is always against the intervention oracle. Attribution patching forms a first-order, linear estimate of each site's patch effect in a single backward pass, so we can compare that estimate directly to the exact effect the oracle measures at the same site. Faithfulness for this method is that correlation, and it is good but not perfect, because the true relationship is not linear. The linear surrogate keeps the edges precise: it is usually right about which dependencies exist, since a real edge tends to have a non-zero gradient, so edge precision and recall stay high. What it gets wrong is the size of an edge, which is why the numerical agreement with the exact patch is only partial. There is no sprite-position collapse framed as such here, because the method is scored on internal patch effects rather than on a rendered position; but its gradient origin is exactly why it approximates rather than matches. The grading is always against the oracle. The audit box reports the measured triad, so the correlation is an average across the scored games, quantifying how much accuracy the fast approximation trades away for its speed.

The score is measured against the §1 intervention oracle — never against another interpretability method. F (faithful) is always vs the oracle; see the execution stack. How each of F / S / M is actually computed for this method (and whether it matches the paper) is in the box just below; the numbers are in the In the audit box under it.

How F, S, M are computed here

The exact formula this method uses for each score, read from its runner, and whether it matches the paper's §3 (F ∧ S ∧ M triad) definition. From the committed audit fsm_math_phaseC.json.

AxisFormula (as computed) What it measuresMatches §3?
F
faithfulness
\(F = \rho_{\mathrm{Pearson}}\!\left(\hat{\Delta y}(u),\ \Delta y(u)\right)\)Pearson correlation between the first-order attribution-patching approximation of each patch effect and the exact re-run patch effect.✓ matches attribution_patching.jl (F = clamp(r.corr,0,1)); metric_name corr_approx_vs_exact. This is the paper's Phase-C patching F = causal-effect-agreement correlation vs Delta_y(u). Record: extra.triad.F (attribution_patching_pong.json F=0.876; battery mean F=0.456, n=42).
how it's measured — call stack:
  1. F = clamp Pearson(approx Δ, exact patch Δ), into the triad — attribution_patching.jl:580
  2. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242
S
sufficiency
\(S = \dfrac{\#\{\,u_{\mathrm{held}}:\ |\hat{y}-y|\le\varepsilon\,\}}{|\mathrm{held\text{-}out}|}\in[0,1]\)Same shared held-out predictive sufficiency estimator as activation_patching.✓ matches common/triad_sm.jl sufficiency_score via triad_extra_dict (attribution_patching.jl). Paper-conform. Record: extra.triad.S (pong S=0.973; battery mean S=0.769, n=42).
how it's measured — call stack:
  1. sufficiency_score: fit Δy=a·attr+b on a calib half, predict held-out within ε — triad_sm.jl:111
  2. assemble the triad via triad_extra_dict — attribution_patching.jl:580
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242
M
minimality
\(M = |U^{\star}| / |\hat{U}| \in (0,1]\quad U^{\star}=\{u:\Delta y(u)>0\},\ \hat{U}=\{u:|\mathrm{attr}(u)|>\tau\}\)True minimal cause set over method-named (above-threshold) set.✓ matches common/triad_sm.jl minimality_score. Paper-conform. Record: extra.triad.M (pong |U*|=6/|U_hat|=5, M=1.0; battery mean M=0.995, n=42).
how it's measured — call stack:
  1. minimality_score: |U*| oracle movers / |U_hat| named cells — triad_sm.jl:57
  2. assemble the triad via triad_extra_dict — attribution_patching.jl:580
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242

✓ matches = the same quantity as §3; ◐ partial = the same kind of estimator but a differing detail; ✗ does not match = a different quantity (see the note). Definitions: F = agreement with the oracle's true causal effects Δy(u); S = held-out predictive score in [−1, 1]; M = |U*|/|Û| (true-minimal-set size / named-set size).

In the audit

This is the method's entry in the actual cross-method audit — scored on the paper's correctness triad, each axis a mean over all 42 scored games (42 committed §R records), not the single example shown above. Tradition: gradient. The example figure (Pong) is one of those records.

0.456F — faithfulness vs oracle (mean over 42 games, ±0.113 CI95)
0.769S — sufficiency: held-out predictive (n/a where the paper does not define this axis)
0.995M — minimality: true-minimal-set / named-set (n/a otherwise)
42committed records aggregated
0.00human-plausibility proxy

F faithfulness (scored vs the oracle for every method) · S sufficiency (held-out predictive score in [−1, 1]; a negative value means the explanation predicts held-out interventions worse than the unperturbed baseline; reported for the predictive methods across all three phases where the calibration/held-out split is defined) · M minimality (true-minimal-set / named-set; where the method names a cause set) — n/a otherwise, per the paper's F ∧ S ∧ M triad.

Source: leaderboard.json · the whole leaderboard is on the methods page and the Paper 2 audit.

Results per game

This method's faithfulness on each of the 42 scored games (all-regime F; this method has no content-vs-position split (see the note below)). Click a header to sort. Every number is read from site_data.json (methods.attribution_patching.per_game).

content-F and position-F are n/a for this method. The content-vs-position split applies only to pixel-attribution methods — those that produce an attribution map over the framebuffer, whose score can be read separately on the smooth content outputs and the discrete position outputs (where the naive gradient is provably zero). This method does not attribute to a pixel output; it is graded by its own fidelity metric (corr_approx_vs_exact), reported as the F column, so there is no content or position regime to separate.

GameF (all)content-Fposition-FSMNote
Yars' Revenge1.000n/an/a0.9831.000recovers the true causes
Kung-Fu Master1.000n/an/a0.9761.000recovers the true causes
Berzerk1.000n/an/a0.9581.000recovers the true causes
Centipede1.000n/an/a0.9761.000recovers the true causes
Kangaroo0.999n/an/a0.9271.000recovers the true causes
Carnival0.998n/an/a0.9511.000recovers the true causes
Tennis0.986n/an/a0.9271.000recovers the true causes
Hero0.960n/an/a0.9621.000recovers the true causes
Breakout0.936n/an/a0.9521.000recovers the true causes
Venture0.909n/an/a0.0001.000recovers the true causes
Pong0.876n/an/a0.9731.000recovers the true causes
Pitfall0.790n/an/a0.9181.000
Video Pinball0.769n/an/a0.9091.000
Riverraid0.654n/an/a0.9601.000
Ms. Pac-Man0.645n/an/a0.9431.000
Montezuma's Revenge0.567n/an/a0.9571.000
Atlantis0.493n/an/a0.9521.000
Bank Heist0.463n/an/a0.0421.000
Private Eye0.444n/an/a0.9541.000
Road Runner0.434n/an/a0.0120.778
Assault0.408n/an/a0.9781.000
Pacman0.371n/an/a0.0541.000
Space Invaders0.360n/an/a0.9621.000
Ice Hockey0.310n/an/a0.8911.000
Air Raid0.263n/an/a0.9671.000
Chopper Command0.257n/an/a0.9781.000
Gopher0.232n/an/a0.9781.000
Freeway0.198n/an/a0.8911.000
Fishing Derby0.183n/an/a0.9521.000
Seaquest0.178n/an/a0.9521.000
Jamesbond0.174n/an/a0.9171.000
Phoenix0.131n/an/a0.9091.000
Krull0.082n/an/a0.9651.000
Double Dunk0.059n/an/a0.0361.000
Frostbite0.031n/an/a0.9431.000no true-cause signal
Q*bert0.006n/an/a0.0001.000no true-cause signal
Alien0.000n/an/a0.8931.000no true-cause signal
Beam Rider0.000n/an/a0.0001.000no true-cause signal
Bowling0.000n/an/a0.9451.000no true-cause signal
Boxing0.000n/an/a0.9411.000no true-cause signal
Demon Attack0.000n/an/a0.9131.000no true-cause signal
Name This Game0.000n/an/a0.0001.000no true-cause signal

Call stack — how it runs on jutari / jaxtari

The path from this method's runner (run_game) into the bit-exact VCS substrate, and the computation it involves. Every step links to the exact source on main. From callstack_phaseC.json.

Applied on the substrate

  1. Boot the real ROM with the xitari-parity reset (60 NOOP + 4 RESET) — env_reset!(env; boot_noop_steps = 60, boot_reset_steps = 4) jutari
  2. Deterministically step the emulator one action per env-frame — env_step!(env::StellaEnvironment, action::Integer) jutari
  3. Assemble the shared gameplay-state testbed via build_attr_shared_state (also builds the sampler-aware position read through soft_ram_peek) — build_shared_testbed(game; ... run_intervention = run_intervention, soft_ram_peek = soft_ram_peek, ...) via build_attr_shared_state runner
  4. Freeze byte-exact RAM + screen out of the env at a frame — snapshot(env::StellaEnvironment, frame::Integer) jutari

The computation

  1. THE gradient step (linear/gradient surrogate): local slope (partial y / partial a)|_clean via a central finite difference of the true patch at a+eps and a-eps — site_gradient(...) -> snap_hi = run_patch(...hi); snap_lo = run_patch(...lo); (read(snap_hi)-read(snap_lo))/denom runner gradient surrogate over the true patch run_patch (activation_patching.jl:282)
  2. Attribution approx = grad*(a'-a) compared cell-by-cell against the exact full re-run patch (ex_snap = run_patch) in _run_game_body — ex_snap = run_patch(clean_ckpt, tail, p.kind, p.site, p.value) runner ex_snap @ :352; linear-probe positive control @ linear_probe :481
  3. Sampler-aware position gradient (redesign Problem 2): differentiable screen-position read of the RAM tape through the bilinear sampler; nonzero partial/partial ram[pidx] via the one-hot soft RAM read — _st_sampler_position_read(ram, geom, cell; soft_ram_peek) -> soft_ram_peek(ram, pidx) runner soft_ram_peek definition @ jutari/src/diff/SoftStep.jl:108

Scored against the exact intervention oracle Δy(u): run_intervention(checkpoint, actions, target_frame, horizon, cause).

On jaxtari (JAX / GPU): the same differentiable path has a bit-exact JAX sibling (Theorem 1, forward-exact) for batched GPU runs — jaxtari/jaxtari/diff/soft_step.py (soft_ram_peek @ line 102) — the JAX SOFT-STE gradient path, forward-bit-exact to the HARD jutari map. attribution_patching is the ONLY Phase-C method with a gradient step; its sampler-aware position gradient routes through soft_ram_peek (jutari/src/diff/SoftStep.jl:108), whose JAX sibling is this file.

Implementation
tools/xai_study/phaseC_mechanistic/attribution_patching.jl
Reference
Nanda 2023; Syed et al. 2023
Record
attribution_patching_pong.json
All records
phaseC_mechanistic/out

The figure is generated from the committed record by docs/gen_method_figures.py; the game frame and each RAM cell's screen footprint are produced by render_scenes.jl / cell_footprints.jl.