SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.07809 · NAACL · 2024

pyvene: A Library for Understanding and Improving PyTorch Models via Interventions

Christopher Manning, Jing Huang, Noah Goodman, Christopher Potts, Atticus Geiger, Zhengxuan Wu, Zheng Wang, Aryaman Arora

arXiv · PDF · Open in the Atlas

Code that ran

6 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 1 failure of our instrument; 4 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2403.07809.json · badge: /api/ran/2403.07809.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
frankaging/pyvene community (classifier label)
classifier basis not recorded on the link
6 ran · 4 no recorded run
FunctionStatusWhere it lives
broadcast_tensor_v1 Ran
ran on a synthesized input
frankaging/pyvene/pyvene/models/intervention_utils.py
code served (permissive licence) · get_code("595a06b9091701fd")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function takes:
# - x: a tensor with some shape, where the last dimension is preserved
# - target_shape: a tuple/list representing the desired output shape
# 
# The function requires that target_shape[-1] == x.shape[-1]
# It reshapes x to have leading dimensions of 1, then expands to target_shape

# Create a small input tensor with last dimension = 4
x = torch.randn(4)  # shape: (4,)

# Create a target_shape that has the same last dimension
# Let's use (2, 3, 4) so we expand from (4,) to (2, 3, 4)
target_shape = (2, 3, 4)

ARGS = {
    'x': x,
    'target_shape': target_shape
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
embed_to_distrib Ran
ran on a synthesized input
frankaging/pyvene/pyvene/models/basic_utils.py
code served (permissive licence) · get_code("e6fa80bf2dce57f3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 10) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from torch import nn

torch.manual_seed(0)

# Create a minimal GPT2-like model
class MinimalGPT2Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.wte = nn.Embedding(num_embeddings=10, embedding_dim=4)
        self.config = type('Config', (), {
            'architectures': ['GPT2LMHeadModel']
        })()

model = MinimalGPT2Model()

# Create a small embedding tensor (batch=2, seq_len=3, embedding_dim=4)
embed = torch.randn(2, 3, 4)

ARGS = {
    'model': model,
    'embed': embed,
    'log': False,
    'logits': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 10) — shape (2, 3, 10) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_internal_model_type Ran
ran on a synthesized input
frankaging/pyvene/pyvene/models/modeling_utils.py
code served (permissive licence) · get_code("fd1cb0e0f7713047")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned type. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

model = SimpleModel()

ARGS = {
    "model": model
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type type — a type output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a type output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_type_from_string Ran
ran on a synthesized input
frankaging/pyvene/pyvene/models/basic_utils.py
code served (permissive licence) · get_code("9539ef9c23b94162")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned type. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import importlib
import torch

def get_type_from_string(type_str):
    """Help function to convert string to type"""
    type_str = type_str.replace("<class '", '').replace("'>", '')
    module_name, class_name = type_str.rsplit('.', 1)
    module = importlib.import_module(module_name)
    cls = getattr(module, class_name)
    return cls

# Test with a valid type string
# The function expects a string representation of a type
# For example: "<class 'torch.Tensor'>" or "torch.nn.Linear"

ARGS = {
    "type_str": "torch.nn.Linear"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type type — a type output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a type output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sigmoid_boundary Ran
ran; our contract draft was wrong, not the code
frankaging/pyvene/pyvene/models/basic_utils.py
code served (permissive licence) · get_code("39eceb45250b08ff")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create small tensor inputs
_input = torch.randn(2, 4)
boundary_x = torch.randn(2, 4)
boundary_y = torch.randn(2, 4)
temperature = torch.tensor(0.5)

ARGS = {
    "_input": _input,
    "boundary_x": boundary_x,
    "boundary_y": boundary_y,
    "temperature": temperature
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
split_heads Ran
ran on a synthesized input
frankaging/pyvene/pyvene/models/constants.py
code served (permissive licence) · get_code("a2d93b74f75430a8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 4, dtype family float, shape (2, 2, 4, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function expects:
# - tensor: a torch tensor with at least 2 dimensions
# - num_heads: an integer for number of attention heads
# - attn_head_size: an integer for attention head size
# 
# The function reshapes tensor.size()[:-1] + (num_heads, attn_head_size)
# and then permutes to (0, 2, 1, 3)
# So we need a tensor with shape (..., hidden_size) where hidden_size = num_heads * attn_head_size

# Setup parameters
num_heads = 2
attn_head_size = 3
hidden_size = num_heads * attn_head_size  # 6

# Create a tensor with shape (batch_size, seq_len, hidden_size)
# Using batch=2, seq_len=4, hidden_size=6
tensor = torch.randn(2, 4, hidden_size)

ARGS = {
    "tensor": tensor,
    "num_heads": num_heads,
    "attn_head_size": attn_head_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 2, 4, 3) — shape (2, 2, 4, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
broadcast_tensor_v2 Not yet run
unverified (harvested, no recorded run)
frankaging/pyvene/pyvene/models/intervention_utils.py
code served (permissive licence) · get_code("20eb71d8a67805e3")
How it ran

no invocation recorded.

create_backpack_gpt2 Not yet run
unverified (harvested, no recorded run)
frankaging/pyvene/pyvene/models/backpack_gpt2/modelings_intervenable_backpack_gpt2.py
code served (permissive licence) · get_code("66d7bf90ca55ef33")
How it ran

no invocation recorded.

is_gru Not yet run
unverified (harvested, no recorded run)
frankaging/pyvene/pyvene/models/modeling_utils.py
code served (permissive licence) · get_code("9eb295208e5af61d")
How it ran

no invocation recorded.

is_stateless Not yet run
unverified (harvested, no recorded run)
frankaging/pyvene/pyvene/models/modeling_utils.py
code served (permissive licence) · get_code("d8f71d28a49db6a2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
sigmoid_boundary 1 other paper
1 dated earlier
2305.08809 (2023-05)
Interpretability at Scale: Identifying Causal Mechanisms in Alpaca

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Interventions on model-internal states are fundamental operations in many areas of AI, including model editing, steering, robustness, and interpretability. To facilitate such research, we introduce pyvene, an open-source Python library that supports customizable interventions on a range of different PyTorch modules. pyvene supports complex intervention schemes with an intuitive configuration format, and its interventions can be static or include trainable parameters. We show how pyvene provides a unified and extensible framework for performing interventions on neural models and sharing the intervened upon models with others. We illustrate the power of the library via interpretability analyses using causal abstraction and knowledge localization. We publish our library through Python Package Index (PyPI) and provide code, documentation, and tutorials at https://github.com/stanfordnlp/pyvene.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2403.07809")
get_code_for_paper("2403.07809")
have("2403.07809")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2403.07809.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2403.07809.svg)](https://syntology.ai/paper/2403.07809)

Connect an agent — have() is free.