attribution-patching

Runs edge attribution patching experiments to discover circuits in transformer models.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Identifying which attention heads and edges inside a transformer actually drive a behavior is slow and manual; this Skill automates attribution patching and circuit pruning so researchers can isolate the components responsible for tasks like indirect object identification. ## Core Features & Use Cases - Edge Attribution Patching: Computes attribution scores across layers and heads, then iteratively prunes low-importance edges with configurable thresholds. - IOI Dataset Generation: Builds Indirect Object Identification prompts with template, name, and noun variation, plus flipped control prompts for causal intervention analysis. - Multi-Task Support: Ships configurations for IOI, greater-than comparison, and docstring generation tasks, with results saved as JSON summaries. - Use Case: A mechanistic interpretability researcher studying GPT-2's IOI circuit generates paired original and flipped prompts, runs attribution patching, and obtains a pruned circuit with a performance score. ## Quick Start Ask the agent to run the attribution patching experiment on the IOI task with gpt2-small and report the pruned heads and final circuit score.

Frequently Asked Questions about attribution-patching

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

FAQPage Schema
How do I run attribution patching on a transformer model?

Attribution patching computes gradient-based attribution scores for each edge, then prunes edges below a threshold iteratively. The run_attribution_patching.py script demonstrates this with a PatchingConfig specifying task, model name, threshold, and absolute-value handling.

What is the IOI task in mechanistic interpretability?

IOI (Indirect Object Identification) tests whether a model identifies the correct indirect object in sentences like 'Mary and John went to the store, John gave a drink to'. The IOIDataset class generates templated prompts and flipped variants for causal intervention analysis.

Which tasks does edge attribution patching support?

The framework supports three benchmark tasks: IOI for indirect object identification, greaterthan for numeric comparison, and docstring for code documentation generation. Each task has its own dataset preparation and prompt format.

Does attribution patching require a GPU?

The configuration defaults to CUDA when available and falls back to CPU otherwise. Real attribution patching with TransformerLens models benefits significantly from a GPU due to the gradient computations across many prompts.

What are the limitations of threshold-based circuit pruning?

Fixed thresholds may prune edges that are individually weak but collectively important, and results are sensitive to the threshold and absolute-value settings. Pareto analysis of sparsity versus accuracy helps select defensible operating points.