Use Activation Intervention to Interpret Causal Mechanism of Model
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyvene-0.1.6.tar.gz
.
File metadata
- Download URL: pyvene-0.1.6.tar.gz
- Upload date:
- Size: 57.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5a2d6bff45b895969d886e81f603359af3420454c720d368de085ccb1db4faf |
|
MD5 | f2bc8f0af6a672c0cf380bdbc5c2abbc |
|
BLAKE2b-256 | f864b9a9f9b07a310095a3a212873d8a677b49f945c77a9d143adacb89670882 |
File details
Details for the file pyvene-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: pyvene-0.1.6-py3-none-any.whl
- Upload date:
- Size: 70.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 241453dfeb330af79f42220af8dc61c6287a6f182455fb327848a6ff4a58c4b2 |
|
MD5 | b39bcd5f0d14b0b6b888136284380008 |
|
BLAKE2b-256 | 03e89e39affbe8c7143ebe9dad341f3ef27be36ef49350b71fa4c5ac6968f5a4 |