12505011/agent-workspace/transformer-lens
Claude Code and agent skill by 12505011/agent-workspace
- community
Checking that the SKILL.md file is still in the repository.
Provides guidance for mechanistic interpretability research using TransformerLens to inspect and manipulate transformer internals via HookPoints and activation caching. Use when reverse-engineering model algorithms, studying attention patterns, or performing activation patching experiments.
Install
npx vskill@latest install 12505011/agent-workspace/transformer-lensSKILL.md
The same SKILL.md was published earlier as openlair/dr-claw/transformer-lens.
TransformerLens: Mechanistic Interpretability for Transformers
TransformerLens is the de facto standard library for mechanistic interpretability research on GPT-style language models. Created by Neel Nanda and maintained by Bryce Meyer, it provides clean interfaces to inspect and manipulate model internals via HookPoints on every activation.
GitHub: TransformerLensOrg/TransformerLens (2,900+ stars)
When to Use TransformerLens
Use TransformerLens when you need to:
- Reverse-engineer algorithms learned during training
- Perform activation patching / causal tracing experiments
- Study attention patterns and information flow
- Analyze circuits (e.g., induction heads, IOI circuit)
- Cache and inspect intermediate activations
- Apply direct logit attribution
Consider alternatives when:
- You need to work with non-transformer architectures → Use nnsight or pyvene
- You want to train/analyze Sparse Autoencoders → Use SAELens
- You need remote execution on massive models → Use nnsight with NDIF
- You want higher-level causal intervention abstractions → Use pyvene
Installation
For development version:
Core Concepts
HookedTransformer
The main class that wraps transformer models with HookPoints on every activation:
Supported Models (50+)
| Family | Models | |
|---|---|---|
| GPT-2 | gpt2, gpt2-medium, gpt2-large, gpt2-xl | |
| LLaMA | llama-7b, llama-13b, llama-2-7b, llama-2-13b | |
| EleutherAI | pythia-70m to pythia-12b, gpt-neo, gpt-j-6b | |
| Mistral | mistral-7b, mixtral-8x7b | |
| Others | phi, qwen, opt, gemma |
Activation Caching
Run the model and cache all intermediate activations:
ActivationCache Keys
| Key Pattern | Shape | Description | |
|---|---|---|---|
resid_pre, layer | [batch, pos, d_model] | Residual before attention | |
resid_mid, layer | [batch, pos, d_model] | Residual after attention | |
resid_post, layer | [batch, pos, d_model] | Residual after MLP | |
attn_out, layer | [batch, pos, d_model] | Attention output | |
mlp_out, layer | [batch, pos, d_model] | MLP output | |
pattern, layer | [batch, head, q_pos, k_pos] | Attention pattern (post-softmax) | |
q, layer | [batch, pos, head, d_head] | Query vectors | |
k, layer | [batch, pos, head, d_head] | Key vectors | |
v, layer | [batch, pos, head, d_head] | Value vectors |
Workflow 1: Activation Patching (Causal Tracing)
Identify which activations causally affect model output by patching clean activations into corrupted runs.
Step-by-Step
Checklist
- [ ] Define clean and corrupted inputs that differ minimally
- [ ] Choose metric that captures behavior difference
- [ ] Cache clean activations
- [ ] Systematically patch each (layer, position) combination
- [ ] Visualize results as heatmap
- [ ] Identify causal hotspots
Workflow 2: Circuit Analysis (Indirect Object Identification)
Replicate the IOI circuit discovery from "Interpretability in the Wild".
Step-by-Step
Checklist
- [ ] Set up task with clear IO/S tokens
- [ ] Compute baseline logit difference
- [ ] Decompose by attention head contributions
- [ ] Identify key circuit components (name movers, S-inhibition, induction)
- [ ] Validate with ablation experiments
Workflow 3: Induction Head Detection
Find induction heads that implement [A][B]...[A] → [B] pattern.
Common Issues & Solutions
Issue: Hooks persist after debugging
Issue: Tokenization gotchas
Issue: LayerNorm ignored in analysis
Issue: Memory explosion with large models
Key Classes Reference
| Class | Purpose | |
|---|---|---|
HookedTransformer | Main model wrapper with hooks | |
ActivationCache | Dictionary-like cache of activations | |
HookedTransformerConfig | Model configuration | |
FactoredMatrix | Efficient factored matrix operations |
Integration with SAELens
TransformerLens integrates with SAELens for Sparse Autoencoder analysis:
Reference Documentation
For detailed API documentation, tutorials, and advanced usage, see the references/ folder:
| File | Contents | |
|---|---|---|
| references/README.md | Overview and quick start guide | |
| references/api.md | Complete API reference for HookedTransformer, ActivationCache, HookPoints | |
| references/tutorials.md | Step-by-step tutorials for activation patching, circuit analysis, logit lens |
External Resources
Tutorials
- Main Demo Notebook
- Activation Patching Demo
- ARENA Mech Interp Course - 200+ hours of tutorials
Papers
- A Mathematical Framework for Transformer Circuits
- In-context Learning and Induction Heads
- Interpretability in the Wild (IOI)
Official Documentation
Version Notes
- v2.0: Removed HookedSAE (moved to SAELens)
- v3.0 (alpha): TransformerBridge for loading any nn.Module
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingAI-Research-SKILLs-main/04-mechanistic-interpretability/transformer-lens/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/12505011/agent-workspace/transformer-lens)