attribution-patching
Gradient-based approximation to activation patching for scalable circuit analysis. Use when activation patching is too slow or when analyzing many components simultaneously.
npx skills add majiayu000/claude-skill-registry --skill attribution-patching-ndif-team-skills-2 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Attribution Patching Attribution patching uses gradients to approximate activation patching results in a single backward pass, making it practical to analyze thousands of components simultaneously. ## Core Idea Instead of running separate forward passes for each component: 1. Run clean and corrupted forward passes 2. Compute gradients of the metric w.r.t. corrupted activations 3. Multiply gradients by (clean - corrupted) activation differences This linear approximation works when clean and corrupted runs are similar. ## Mathematical Formula ``` attribution(component) = grad_corrupted(metric) * (clean_activation - corrupted_activation) ``` ## Setup ```python from nnsight import LanguageModel import torch model = LanguageModel("openai-community/gpt2", device_map="auto", dispatch=True) clean_prompt = "After John and Mary went to the store, Mary gave a bottle of milk to" corrupted_prompt = "After John and Mary went to the store, John gave a bottle of milk to" correct_token = model.tokenizer(" John")["input_ids"][0] incorrect_token = model.tokenizer(" Mary")["input_ids"][0] def logit_diff(logits): return logits[0, -1, correct_token] - logits[0, -1, incorrect_token] ``` ## Basic Attrib
- Core Idea
- Mathematical Formula
- Setup
- Basic Attribution Patching
- Per-Position Attribution
- Attention Head Attribution
- Efficient Batched Version
- Comparison with Activation Patching
- Validation
- When to Use
What does the attribution-patching skill do?
Gradient-based approximation to activation patching for scalable circuit analysis. Use when activation patching is too slow or when analyzing many components simultaneously.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill attribution-patching-ndif-team-skills-2 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
