Skip to content

TorchLens for mechanistic interpretability

Mechanistic interpretability needs three things from a model's activations: an exact address for every site (a head's query, a block's residual stream, one MLP neuron), the ability to edit that site and measure the effect on the output, and enough speed to sweep the edit over many sites and prompts. TorchLens records every operation of a forward pass with a stable label, lets you patch, ablate or steer any of them with the same call whether you run once or through generation, and hands the result to the SAE, probing and steering libraries you already use.

The lists below are in the order most people want them: see one site, edit it, then scale up. Every link is to a file in this repository.

Start here

Patching, ablation and steering

Circuits, attribution and lenses

Sparse autoencoders

Probes and representations

Replications on GPT-2

  • Paper replications: scripts that state one published claim, measure it and print a verdict against a rule fixed before the first run: induction heads (Olsson et al. 2022), the IOI name movers (Wang et al. 2022) and causal tracing (Meng et al. 2022).
  • The same three lines on any architecture: the trace, draw and edit calls on six architecture families.

Experiments at scale

Connectors and migration