Skip to main content


A Library for Understanding and Improving PyTorch Models via Interventions

pyvene is an open-source Python library for intervening on the internal states of PyTorch models. Interventions are an important operation in many areas of AI, including model editing, steering, robustness, and interpretability.

pyvene has many features that make interventions easy:

  • Interventions are the basic primitive, specified as dicts and thus able to be saved locally and shared as serialisable objects through HuggingFace.
  • Interventions can be composed and customised: you can run them on multiple locations, on arbitrary sets of neurons (or other levels of granularity), in parallel or in sequence, on decoding steps of generative language models, etc.
  • Interventions work out-of-the-box on any PyTorch model! No need to define new model classes from scratch and easy interventions are possible all kinds of architectures (RNNs, ResNets, CNNs, Mamba).

pyvene is under active development and constantly being improved 🫡

[!IMPORTANT] Read the pyvene docs at https://stanfordnlp.github.io/pyvene/!

Installation

To install the latest stable version of pyvene:

pip install pyvene

Alternatively, to install a bleeding-edge version, you can clone the repo and install:

git clone git@github.com:stanfordnlp/pyvene.git
cd pyvene
pip install -e .

When you want to update, you can just run git pull in the cloned directory.

We suggest importing the library as:

import pyvene as pv

Citation

If you use this repository, please consider to cite our library paper:

@inproceedings{wu-etal-2024-pyvene,
    title = "pyvene: A Library for Understanding and Improving {P}y{T}orch Models via Interventions",
    author = "Wu, Zhengxuan and Geiger, Atticus and Arora, Aryaman and Huang, Jing and Wang, Zheng and Goodman, Noah and Manning, Christopher and Potts, Christopher",
    editor = "Chang, Kai-Wei and Lee, Annie and Rajani, Nazneen",
    booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 3: System Demonstrations)",
    month = jun,
    year = "2024",
    address = "Mexico City, Mexico",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.naacl-demo.16",
    pages = "158--165",
}

Star History

Star History Chart

Metadata

Release files for pyvene 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyvene 0.1.8
File Size Uploaded
pyvene-0.1.8.tar.gz 54.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyvene 0.1.8
File Interpreter ABI Platform
pyvene-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 128.9 kB

Release files / pyvene-0.1.8.tar.gz

Download URL pyvene-0.1.8.tar.gz
Size 54.3 kB
Tags Source
SHA-256 checksum
How to use checksums
de15ba3888b01a1eca367b162f06a8d4e8f12342bb0eb4b702c8c6027520603e
BLAKE2b-256 checksum
How to use checksums
635b00e9a0ab489e27df2bca460a72fc6cb30f28463e24d0057fc02d7b8fbbd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.22

Release files / pyvene-0.1.8-py3-none-any.whl

Download URL pyvene-0.1.8-py3-none-any.whl
Size 74.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c16727944230d29e95a5cdbe541fe6d983298ccbc98f5c47bf451ddd88a66db8
BLAKE2b-256 checksum
How to use checksums
3c063a3beaac1633a11951999bb77ba654c05684cc335b9abd1ceda91131071c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.22

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page