transformer-lens-interpretability

Inspect and manipulate transformer internals using HookPoints and activation caching.

5|2|Updated Aug 10, 2026
One-click install
npx skills add https://github.com/MedTiLab/Auto-meta-analysis --skill transformer-lens-interpretability-medtilab
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: transformer-lens-interpretability
Source: https://github.com/MedTiLab/Auto-meta-analysis/tree/main/skills/mechanistic-interpretability/transformer-lens
Command: npx skills add https://github.com/MedTiLab/Auto-meta-analysis --skill transformer-lens-interpretability-medtilab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires transformer-lens, torch, and includes references (resource) components.

What problem does it solve? Reverse-engineering what a language model computes internally requires intercepting and modifying activations at every layer, which standard model APIs do not expose. This Skill provides workflows for activation patching, circuit analysis, and logit attribution using TransformerLens HookPoints. ## Core Features & Use Cases - Activation Caching: Run models with run_with_cache to capture residual streams, attention patterns, and MLP outputs at every layer. - Activation Patching: Perform causal tracing experiments by patching clean activations into corrupted runs to identify which components drive specific outputs. - Circuit Analysis: Decompose model behavior into attention head contributions, detect induction heads, and replicate experiments like the IOI circuit. - Use Case: You want to know which attention heads cause GPT-2 to predict "Paris" after "The Eiffel Tower is in the city of". Use direct logit attribution to rank head contributions, then ablate the top heads to validate the circuit. ## Quick Start Load gpt2-small with TransformerLens and show me which attention heads contribute most to predicting the next token in my prompt.

Frequently Asked Questions about transformer-lens-interpretability

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I perform activation patching with TransformerLens?▼

Activation patching runs the model on a clean prompt with run_with_cache, then patches those activations into a corrupted run via run_with_hooks. Measure the effect with a metric like logit difference and iterate over layers and positions to build a heatmap of causal hotspots.

What models does TransformerLens support?▼

TransformerLens supports over 50 models including GPT-2, LLaMA, LLaMA-2, Mistral, Mixtral, Pythia, GPT-Neo, GPT-J, OPT, Gemma, Phi, and Qwen. Gated models like LLaMA require setting an HF_TOKEN environment variable before loading.

TransformerLens vs nnsight vs pyvene for interpretability?▼

TransformerLens is the standard for GPT-style transformer circuit analysis with HookPoints on every activation. Use nnsight for remote execution on massive models or non-transformer architectures, and pyvene for higher-level causal intervention abstractions.

Why do my TransformerLens hooks persist between runs?▼

Hooks persist because old hooks remain active after run_with_hooks calls during debugging. Call model.reset_hooks() before each new hooked run to clear previously registered hooks and avoid stale modifications.

How do I reduce memory usage when caching activations?▼

Use the names_filter parameter in run_with_cache to cache only needed activations, such as resid_post or pattern. You can also pass device="cpu" to store the cache in CPU memory instead of GPU memory.

Can TransformerLens work with Sparse Autoencoders?▼

Yes, TransformerLens integrates with SAELens for Sparse Autoencoder analysis. Load an SAE with SAE.from_pretrained, cache activations from a hook point like blocks.8.hook_resid_pre, and encode them with sae.encode.