intermediate-outputs

Analyze transformer circuits using RelP relevance patching and LRP rules with TransformerLens.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill intermediate-outputs-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: intermediate-outputs
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/gradient-detection/intermediate-outputs
Command: npx skills add https://github.com/zjunlp/Mechanist --skill intermediate-outputs-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, numpy, transformer_lens, matplotlib, and includes scripts (resource) and references (resource) components.

What problem does it solve? Understanding which internal components of a language model drive specific predictions requires tedious manual instrumentation of attention heads, MLP layers, and residual streams. This Skill provides ready-to-run scripts for circuit discovery using RelP (Relevance Patching) and Layer-wise Relevance Propagation, so researchers can compute component relevance scores without writing boilerplate hooking code. ## Core Features & Use Cases - RelP-Based Circuit Analysis: Load HookedTransformer models with configurable LRP rules (LN-rule, Identity-rule, Half-rule, 0-rule, AH-rule) and compute relevance scores for attention, MLP, and residual stream components. - IOI Task Benchmarking: Run Indirect Object Identification analysis to identify name mover heads, rank attention heads by indirect-object attention, and compare RelP against standard attribution patching via logit differences. - LRP Rule Comparison: Evaluate multiple LRP rule configurations on the same input to see how propagation choices change component relevance rankings. - Use Case: A mechanistic interpretability researcher wants to know which attention heads in GPT-2 small copy name information in IOI sentences. They run the IOI analysis script to get ranked head scores and a RelP-vs-attribution comparison in one pass. ## Quick Start Ask the agent to run the basic RelP analysis script on GPT-2 small to compute relevance scores for attention and MLP components on a sample sentence.

Frequently Asked Questions about intermediate-outputs

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

FAQPage Schema
How do I use RelP for circuit discovery in transformer models?

Load a HookedTransformer model, set model.cfg.use_lrp to True, and assign LRP rules such as LN-rule, Identity-rule, and Half-rule. Then call run_with_cache on your input text to capture activations and compute relevance scores per component.

How to analyze the IOI task with TransformerLens?

Create IOI examples with indirect object and subject tokens, run the model with cache, and compute logit differences between the two name tokens. You can then rank attention heads by their attention to the indirect object position to find name mover heads.

What is the difference between RelP and attribution patching?

RelP propagates relevance through the network using LRP rules, while attribution patching uses gradient-based approximations of component contributions. The scripts compare both methods by measuring logit differences on IOI examples with LRP enabled versus disabled.

Which LRP rules should I use for transformer analysis?

The default configuration uses LN-rule for layer normalization, Identity-rule for activation functions, and Half-rule for multiplicative gates. You can compare alternatives like 0-rule and AH-rule using the rule comparison function to see how rankings change.

Does RelP work with models other than GPT-2?

The scripts default to gpt2-small but accept any model name supported by HookedTransformer.from_pretrained, such as gpt2-medium or gpt2-large. The model must be loadable through the RelP-enhanced TransformerLens installation.

Why is my relevance score analysis not working with standard TransformerLens?

RelP requires the enhanced TransformerLens fork from the RelP repository, installed via pip install -e from the RelP/TransformerLens directory. Standard TransformerLens does not support the use_lrp configuration flag or LRP_rules settings.