Foundations to Frontier
Tests
F. NLP and Large Language Models › F15 Interpretability of LLMs

Activation patching and steering

Probes and attention maps show correlations; interventions show causes. Activation patching runs a model on a clean and a corrupted input. It then copies activations from one run into the other, one component at a time, to see which components carry the difference. Steering adds a direction to the activations, often the difference between mean activations on contrasting prompts, to change behaviour without retraining. This page covers causal tracing, noising and denoising, metrics, attribution patching, path patching, steering vectors and directional ablation, and how to check side effects. In the exercises you patch activations, compute the restored fraction and build a steering vector. You then intervene on a frozen two-layer network that reads a binary concept and a 4-way topic. No single block of 8 hidden units restored more than 33% of the concept, and the top 4 of 8 blocks restored 67%. A mean-difference steering vector flipped the concept on 94% of inputs while keeping topic accuracy at 0.995. Eight times stronger, it cut topic accuracy to 0.45. A random vector of the same size never flipped the concept.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Swapping parts to find what matters

To find which wire in a machine carries a signal, swap that wire’s signal from a working run into a broken run and see whether the machine starts working. Activation patching does this inside a network. Steering goes one step further: once you know the direction that means ‘formal tone’ or ‘refuse’, you can add a little of it to change the model’s behaviour, but adding too much breaks other things. The demo shows how the push size changes the behaviour.

Interpretability lab
Adding α = 0 times a feature direction changes the probability of the behaviour to 12%. Too large a push breaks fluency.
Why engineers care

Directional ablation can remove a model’s refusal behaviour, a reminder that safety features inside models can be fragile; the same tools can strengthen them.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Activation patching copies activations between…
  2. 2. A steering vector is often…
  3. 3. Too strong steering…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Causal tracing (ROME): corrupt the subject with noise, restore one hidden state at a time; factual recall localised to middle-layer MLPs at the last subject token (Meng et al., 2022).
  • Noising vs denoising: patch corrupted into clean (is it necessary?) or clean into corrupted (is it sufficient?); results can differ.
  • Metrics: logit difference or probability of the right answer; normalise as the fraction restored. Corruptions: resample other prompts rather than add Gaussian noise when possible (Zhang & Nanda, 2024).
  • Scaling: attribution patching uses gradients to estimate all patches at once; path patching isolates edges between components.
  • Steering: activation addition (ActAdd), contrastive activation addition (CAA), representation engineering, SAE-feature steering; directional ablation of a refusal direction (Arditi et al., 2024).
  • Checks: side effects on unrelated tasks, fluency (perplexity), dose-response curves, comparison with random directions of the same norm.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Causal tracing localised factual recall to…
  2. 2. Denoising tests whether a component is…
  3. 3. Refusal can be removed by…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Patching and steering in practice

Exercise 1.

  • Patching selected activations.
  • Restored fraction.
  • A mean-difference steering vector.

Practice.

  • TransformerLens hooks (run_with_hooks) or nnsight for patching; build clean/corrupted prompt pairs that differ in one fact.
  • Sweep layers × positions first, then heads; use attribution patching for large models and confirm the top hits with real patching.
  • Steering: collect activations on contrasting prompt pairs at one layer, take the mean difference, add α times it during generation; sweep α.
  • Always compare with random vectors, check unrelated benchmarks and perplexity.
  • Libraries: steering-vectors, repeng, SAELens for feature steering.
from transformer_lens import HookedTransformer
model = HookedTransformer.from_pretrained("gpt2-small")
_, pos = model.run_with_cache("I love this. It is wonderful"); _, neg = model.run_with_cache("I hate this. It is terrible")
L = 6; v = pos["resid_post", L][0].mean(0) - neg["resid_post", L][0].mean(0)
def steer(resid, hook, alpha=4.0): return resid + alpha * v
with model.hooks(fwd_hooks=[(f"blocks.{L}.hook_resid_post", steer)]):
    print(model.generate("The flight today was", max_new_tokens=20))
🐍 Exercise 1: patch and steer
Patch activations, compute the restored fraction and build a steering vector.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Patching in TransformerLens uses…
  2. 2. Prefer corruptions that…
  3. 3. Always compare a steering vector with…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Distributed representations. If a concept is spread across many units, patching any small subset restores only part of the effect; effects of disjoint subsets roughly add when the downstream computation is nearly linear, and fail to add when nonlinearities intervene.

Why mean differences steer. If activations of the two classes differ mainly along a direction v, adding α v moves a negative example’s activation towards the positive class mean. The readout of the concept changes approximately linearly in α until ReLUs saturate.

Side effects. The push also changes components that other readouts use: projections of v onto the topic readout, and nonlinear changes through later ReLUs. Larger α pushes activations off the training distribution, where unrelated behaviour degrades; a random vector of the same norm shows the generic damage of moving off-distribution.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Patching a small subset of a distributed concept restores…
  2. 2. Large steering pushes activations…
  3. 3. A random vector of equal norm measures…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Is a concept localised in a few units, and can a steering vector change it without damaging other behaviour?

History.

  • K. Meng et al., “Locating and editing factual associations in GPT” (ROME, 2022).
  • A. Turner et al., “Activation addition” (2023); N. Rimsky et al., “Steering Llama 2 via contrastive activation addition” (2024).
  • A. Arditi et al., “Refusal in language models is mediated by a single direction” (2024).

Exercise 2. A frozen two-layer ReLU network (32 → 64 → 64).

  • Inputs: a binary concept (±0.8 along a direction), a 4-way topic and noise.
  • Readouts: logistic heads read the concept and the topic from layer 2.
  • Patching: clean inputs have concept 1; corrupted inputs are the same inputs with the concept flipped. Copy blocks of 8 layer-1 units from clean to corrupted and measure the restored fraction of the concept logit.
  • Steering: add α times the mean layer-1 difference between concepts to concept-0 inputs; compare with a random vector of the same norm.
patching restored fraction
best single block 0.328
top 2 blocks 0.462
top 4 blocks (half the units) 0.672
sum of all 8 single-block effects 1.092
steering α concept flipped topic accuracy (unsteered 0.997)
0.5 0.258 0.995
1 0.935 0.995
2 1.0 0.963
4 1.0 0.701
8 1.0 0.449
random direction, any α 0.0 0.995 → 0.378
  • Distributed: no block carried the concept; effects roughly added up (1.09).
  • Steering worked at α ≈ 1 with almost no side effect; larger pushes damaged the topic, as did random vectors of equal size.
  • Seeds 1 and 2: top 4 blocks 0.765 and 0.692; α = 1 flipped 0.993 and 1.0 with topic accuracy 0.983 and 0.973; α = 8 topic accuracy 0.576 and 0.233.
  • Caveat: a small random network with linear readouts; in LLMs, steering effects depend on layer, prompt and token position.
🐍 Exercise 2 (research): is a concept localised in a few units, and can a steering vector change it without damaging other behaviour?
Patch blocks of hidden units between clean and corrupted inputs; steer with a mean-difference vector and a random vector at several strengths, measuring the target behaviour and an unrelated one.

Patching and steering in AI, robotics and aerospace

  • Model editing: locating and fixing wrong facts (for example outdated procedures) without retraining, with checks for side effects.
  • Behaviour control: steering assistants towards concise or cautious answers; robustness of safety behaviours tested by directional ablation.
  • Robot policies: patching between successful and failed episodes localises the component responsible for a failure.

References

  1. K. Meng, D. Bau, A. Andonian and Y. Belinkov (2022). “Locating and editing factual associations in GPT.” NeurIPS.
  2. F. Zhang and N. Nanda (2024). “Towards best practices of activation patching in language models.” ICLR.
  3. N. Rimsky et al. (2024). “Steering Llama 2 via contrastive activation addition.” ACL.
  4. A. Arditi et al. (2024). “Refusal in language models is mediated by a single direction.” NeurIPS.