Skip to main content

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

Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvene-0.1.7.tar.gz (58.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvene-0.1.7-py3-none-any.whl (72.7 kB view details)

Uploaded Python 3

File details

Details for the file pyvene-0.1.7.tar.gz.

File metadata

  • Download URL: pyvene-0.1.7.tar.gz
  • Upload date:
  • Size: 58.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyvene-0.1.7.tar.gz
Algorithm Hash digest
SHA256 33b0f9e6bfb346a23d9218edc98cdc58ea29afdd1bbcd9ac50948da12e2cee50
MD5 804da7796d137840326ff8b8828e5a49
BLAKE2b-256 df375f99be742a84f3cf8fa2b7fe2501540a4a5abfcb185d7726b4bce82135dd

See more details on using hashes here.

File details

Details for the file pyvene-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pyvene-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 72.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyvene-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 dac7e4e03da795918c0b80755b5dcc551050788aeee5ff3dd5780b8641ec7454
MD5 740120c52b31c662dbe01f208569e521
BLAKE2b-256 d29b6fed20f0a43f50eb9b2bb9c76f26fe7f5639653c36fd1ee6494416eea694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page