pyvene-interventions

Perform causal interventions on PyTorch models using pyvene's declarative intervention framework.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pyvene, torch, transformers, and includes references (resource) components.

What problem does it solve? Running causal intervention experiments on neural networks—such as activation patching, causal tracing, and interchange intervention training—typically requires ad-hoc hook code that is hard to reproduce and share. This Skill provides structured guidance for using pyvene's declarative, config-based framework to define, run, train, and share interventions on any PyTorch model. ## Core Features & Use Cases - Causal Tracing and Activation Patching: Localize where factual associations or circuit components live by corrupting inputs and restoring activations at specific layers and positions. - Trainable Interventions (DAS/IIT): Learn low-rank rotation subspaces with RotatedSpaceIntervention to discover causal structure in model representations. - Model Steering and Sharing: Apply interventions during generation (e.g., Honest LLaMA) and save or load intervention configs via HuggingFace for reproducibility. - Use Case: To find which attention layers mediate indirect object identification in GPT-2, patch attention outputs layer-by-layer from a clean run into a corrupted run and measure the logit difference recovery. ## Quick Start Ask the AI to set up a pyvene activation patching experiment on GPT-2 that swaps block outputs between a clean and corrupted prompt at a chosen layer.

Frequently Asked Questions about pyvene-interventions

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

FAQPage Schema
How do I run activation patching with pyvene?▼

Activation patching in pyvene uses an IntervenableConfig with a RepresentationConfig specifying the layer, component such as block_output, and VanillaIntervention type. Wrap the model in IntervenableModel, then call it with base and sources inputs to swap activations between runs.

What is the difference between pyvene, TransformerLens, and nnsight?▼

pyvene offers declarative dict-based configs, trainable interventions, and HuggingFace sharing for any PyTorch model. TransformerLens suits exploratory activation analysis on transformers, while nnsight provides lower-level control and remote execution on massive models via NDIF.

Does pyvene support models other than transformers?▼

pyvene works with any PyTorch model, not just transformers. It has been tested on GPT-2, LLaMA, Pythia, Mistral, OPT, BLIP for vision-language tasks, ESM protein models, and Mamba state space models.

How do I intervene at specific token positions in pyvene?▼

Set unit to pos and max_number_of_units in the RepresentationConfig, then pass unit_locations in the form {"sources->base": ([[[position]]], [[[position]]])} to the IntervenableModel call. This restricts the intervention to the specified token positions only.

Why does my pyvene intervention fail with a component name error?▼

pyvene requires exact component names such as mlp_output or attention_output; shorthand names like mlp are invalid. Check the supported component list including block_input, block_output, mlp_activation, and query_output when writing the RepresentationConfig.

Can I train interventions with pyvene using DAS?▼

Yes, Distributed Alignment Search uses trainable interventions like LowRankRotatedSpaceIntervention with a specified low_rank_dimension. Retrieve parameters via get_trainable_parameters, optimize with a standard PyTorch optimizer, and the learned rotation reveals the causal subspace.