projects / proj-flag-004
Next task →
Projects/Specializations/Mechanistic interpretability pipeline with activation patching
Level 5 · research · ~45 h

Mechanistic interpretability pipeline with activation patching

Build an end-to-end causal interpretability pipeline on a small transformer: train a model on a synthetic factual task, locate the circuit for a fact via activation patching, and validate the circuit with ablation and restoration experiments.
Add to portfolio →

Problem statement

  • 01Build an end-to-end causal interpretability pipeline on a small transformer: train a model on a synthetic factual task, locate the circuit for a fact via activation patching, and validate the circuit with ablation and restoration experiments.

Real-world motivation

  • 01Correlational feature analysis cannot establish that a component causes a behavior; causal interventions are the standard for faithful explanations.

Learning objectives

  • 01Construct clean and counterfactual prompt pairs
  • 02Implement residual-stream and head-level patching
  • 03Validate a minimal sufficient circuit

Technical architecture

  • 01forward hooks for activation caching
  • 02counterfactual prompt pairs with matched structure
  • 03logit-difference effect metric

Mathematical foundations

  • 01$\mathrm{effect}(a)=p(answer|do(a=\text{clean}))-p(answer|\text{corrupted})$
  • 02normalization by the full restoration effect

Dataset and sources

  • 01synthetic subject-relation-object facts
  • 02WikiText-103 for pretraining a tiny model

Step-by-step tasks

  • 01Train a two-layer transformer on a synthetic factual task to >95% accuracy
  • 02Create clean and corrupted prompts that differ in one entity
  • 03Patch each layer and head, recording restoration effects
  • 04Run control patches with unrelated activations
  • 05Test whether the identified circuit is sufficient by freezing all other paths
  • 06Write a causal story with quantitative support

Implementation requirements

  • 01Use PyTorch forward hooks and cache tensors
  • 02Vectorize patching across sites
  • 03Store effects in a layer-by-head matrix

Testing requirements

  • 01Verify corrupted prompts reduce target probability
  • 02Check control patches produce near-zero effects
  • 03Confirm full restoration recovers the clean probability

Evaluation metrics

  • 01restored probability
  • 02effect localization score
  • 03control effect size
  • 04circuit sufficiency

Expected outputs

  • 01patching heatmap
  • 02circuit diagram
  • 03validation experiments
  • 04written causal analysis

Common failure modes

  • 01counterfactual prompts differ in more than the target entity
  • 02patching propagates through unrelated paths
  • 03effects dominated by output-layer bias

Stretch goals

  • 01add path patching
  • 02test feature-level patching with a sparse autoencoder

Research extensions

  • 01study circuit universality across random seeds
  • 02derive conditions under which patching effects are interpretable

GitHub submission requirements

  • 01Code for training and patching
  • 02Heatmaps and control experiments
  • 03Circuit diagram
  • 04Two-page causal analysis with caveats

Completion rubric

  • 01clean/corrupted pairs valid
  • 02patching implementation correct
  • 03controls included
  • 04sufficiency tested
  • 05claims calibrated to evidence

Submit when every rubric item is satisfied and your repository contains runnable code plus a reproduction command.