Automated causal intervention framework for mechanistic interpretability experiments.
Install from the repository root:
pip install -e "."
# Optional: notebook + table deps for examples
pip install -e ".[demo]"causal_patcher.viz plots logit(clean answer) − logit(corrupt answer) on the patched corrupt run. With the default RdBu_r scale (centered at zero):
| Color | Meaning |
|---|---|
| Red / warm | Recovery — the patch increased that score; the run looks more like the clean-answer side of the comparison. |
| Blue / cool | Suppression — the patch decreased the score; the readout moved toward the corrupt answer or away from the clean one. |
| Near white | little effect. |
A longer guide (layer × position vs. layer × head, baselines, caveats) is in docs/heatmap.md.
plot_layer_position_patching labels each column with decoded subwords from the corrupt prompt by default. For custom grids, pass x_tick_labels=viz.position_tick_labels(runner, "corrupt") to plot_heatmap, or which="clean" to align the axis with the clean sequence.
- Notebook:
notebooks/demo_factual_recall.ipynb— factual recall (Eiffel/Paris vs Colosseum/Rome) ongpt2-smallwithresid_preandattn_head_zsweeps. - Heatmap reading: see
docs/heatmap.md.