Skip to content

Interpretability, attribution, and explanation audits · Interpretability, explanations, and model-mechanism analysis · EXP014 · Diagnostic

Activation patching and causal tracing

Probe model computations by replacing selected activations in a corrupted or contrasting run with activations from a reference run and measuring a target behavior.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Probe model computations by replacing selected activations in a corrupted or contrasting run with activations from a reference run and measuring a target behavior.

Question / hypotheses

Which internal activations restore or alter the selected behavior under this intervention protocol? The term causal refers to interventions in the computational model, not automatically causal claims about the world.

Architecture / computational structure

A clean/reference run caches activations. A corrupted or alternate input produces another trajectory. Hooks replace selected states at a specified layer, token, head or component; the remaining network runs forward. Interventions can target whole states or carefully defined edges/paths.

Assumptions

The patch location, clean/corrupt pair and evaluation score must be meaningful. Interventions can create off-distribution internal states. Sufficiency, necessity, mediation and restoration are different questions and require different experimental designs.

Formula / computational definition

Δpatch=s(xcorrupt;hS←hSclean)−s(xcorrupt),r=Δpatchs(xclean)−s(xcorrupt).\Delta_{\rm patch}=s(x_{\rm corrupt};h_S\leftarrow h_S^{\rm clean})-s(x_{\rm corrupt}),\qquad r=\frac{\Delta_{\rm patch}}{s(x_{\rm clean})-s(x_{\rm corrupt})}.

Parameters and notation

Predictor parameters are fixed. Choices include corruption type/strength, reference distribution, patched components S, position alignment, score or logit contrast, normalization and intervention sampling. The normalized recovery r is undefined or unstable when its denominator is near zero and can fall outside [0,1]. Here s is the selected scalar score, h_S the internal activation components in subset S, and clean and corrupt identify the two input runs. The left arrow means replacing those activations during the corrupted forward pass.

Fitting, fine-tuning, and adaptation

Repeat analysis after fine-tuning rather than transferring a circuit map blindly. Record the exact checkpoint and tokenization. Use matched reference pairs and negative-control patches; compare results across prompts or inputs instead of relying on one striking example.

How to use and calibrate

Report raw score changes alongside normalized recovery. Test patch direction, alternative corruptions, component combinations and unrelated outputs. An intervention that restores behavior may identify a useful pathway without proving that it is the unique mechanism.

Example application

Patch one hidden coordinate in a small nonlinear computation, then compare its restoration effect with a patch to another coordinate.

Interpretation / pitfalls

Watch out

Corruption design can dominate conclusions. Redundancy, nonlinear interactions and compensating pathways make single-component rankings incomplete. Editing weights and patching activations are separate experiments; successful patching alone does not establish a reliable knowledge-editing method.

Python and R code examples

Scope: Complete intervention on a supplied two-coordinate hidden state and fixed readout; no transformer hooks or factual-knowledge claim. Python: NumPy; R: base R.

Validation: Python executed successfully on the supplied fixture; R reviewed but unexecuted. Full implementations and supported operation details are provided in the linked primary/official sources.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Complete intervention on a supplied two-coordinate hidden state and fixed readout; no transformer hooks or factual-knowledge claim. Python: NumPy; R: base R. · needs numpy

import numpy as np
clean=np.array([2.,1.]);bad=np.array([-.5,.2])
score=lambda h:np.tanh(h[0])+h[0]*h[1]
patched=bad.copy();patched[0]=clean[0]
delta=score(patched)-score(bad);den=score(clean)-score(bad)
assert abs(den)>1e-12;print(delta,delta/den)
R

Component demo, not a trained model — Complete intervention on a supplied two-coordinate hidden state and fixed readout; no transformer hooks or factual-knowledge claim. Python: NumPy; R: base R.

clean<-c(2,1);bad<-c(-.5,.2);score<-function(h) tanh(h[1])+h[1]*h[2]
patched<-bad;patched[1]<-clean[1];delta<-score(patched)-score(bad);den<-score(clean)-score(bad)
stopifnot(abs(den)>1e-12);print(c(delta=delta,recovery=delta/den))

Sources

From the CodeSplash reference, entry EXP014.