Skip to content

Commit 7af5600

Browse files
committed
Activation collection to support probe training; iit training; relative import path; more tutorials (#24,#26,#40)
1 parent 76aceaa commit 7af5600

33 files changed

+2279
-7688
lines changed

CONTRIBUTING.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Contributing Guidelines
2+
3+
*Pull requests, bug reports, and all other forms of contribution are welcomed and highly encouraged!* :octocat:
4+
5+
### :book: Pull Requests
6+
7+
#### Uninstall pyvene from python library
8+
It becomes tricky if you have `pyvene` installed while debugging with this codebase, since imports can be easily messed up. Please run,
9+
```bash
10+
pip uninstall pyvene
11+
```
12+
13+
#### Unit Test Run Is A Must before Creating PRs
14+
When adding new methods or APIs, unit tests are now enforced. To run existing tests, you can kick off the python unittest command in the discovery mode as,
15+
```bash
16+
cd pyvene
17+
python -m unittest discover -p '*TestCase.py'
18+
```
19+
When checking in new code, please also consider to add new tests in the same PR. Please include test results in the PR to make sure all the existing test cases are passing. Please see the `qa_runbook.ipynb` notebook about a set of conventions about how to add test cases. The code coverage for this repository is currently `low`, and we are adding more automated tests.
20+
21+
#### Format
22+
```
23+
**Descriptions**:
24+
25+
[Describe your PR Here]
26+
27+
28+
**Testing Done**:
29+
30+
[Provide logs, screen-shots, files that contain tests you have done]
31+
32+
```
33+
34+
Go to issues, and open with a title formatted as,
35+
```
36+
[Priority Tag] Short Title
37+
```
38+
For Priority Tag, you can use P0-P2, P0 is the highest priority, which means everyone should stop working and focus on this PR.
39+
40+
### :beetle: Bug Reports and Other Issues
41+
Go to issues, and open with a title formatted as,
42+
```
43+
[Bug Fix] Short Title
44+
```
45+
For external requests (i.e., you are not in our core dev team), please use,
46+
```
47+
[External] Short Title
48+
```
49+
50+
### :inbox_tray: Larger Feature Requests
51+
Please email us!

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@ Install with pip on stable releases,
1616
```bash
1717
pip install pyvene
1818
```
19+
1920
or with our dev repo directly,
2021
```bash
2122
pip install git+https://github.com/frankaging/pyvene.git
2223
```
2324

25+
or you can clone our repo,
26+
```bash
27+
git clone https://github.com/frankaging/pyvene.git
28+
```
29+
and import to your project as,
30+
```python
31+
from pyvene import pyvene
32+
_, tokenizer, gpt2 = pyvene.create_gpt2()
33+
```
34+
2435
## _Wrap_ , _Intervene_ and _Share_
2536
You can intervene with supported models as,
2637
```python
@@ -142,13 +153,10 @@ intervenable.train(
142153
where you need to pass in a trainable dataset, and your customized loss and metrics function. The trainable interventions can later be saved on to your disk. You can also use `intervenable.evaluate()` your interventions in terms of customized objectives.
143154

144155

145-
## Unit-tests
146-
When adding new methods or APIs, unit tests are now enforced. To run existing tests, you can kick off the python unittest command in the discovery mode as,
147-
```bash
148-
cd pyvene
149-
python -m unittest discover -p '*TestCase.py'
150-
```
151-
When checking in new code, please also consider to add new tests in the same PR. Please include test results in the PR to make sure all the existing test cases are passing. Please see the `qa_runbook.ipynb` notebook about a set of conventions about how to add test cases. The code coverage for this repository is currently `low`, and we are adding more automated tests.
156+
## Contributing to This Library
157+
Please see [our guidelines](CONTRIBUTING.md) about how to contribute to this repository.
158+
159+
*Pull requests, bug reports, and all other forms of contribution are welcomed and highly encouraged!* :octocat:
152160

153161

154162
## Related Works in Discovering Causal Mechanism of LLMs

icons/pyvene-icon-with-name.png

62.5 KB
Loading

icons/pyvene-icon.png

42.4 KB
Loading

pyvene/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .models.interventions import SigmoidMaskRotatedSpaceIntervention
2020
from .models.interventions import LowRankRotatedSpaceIntervention
2121
from .models.interventions import PCARotatedSpaceIntervention
22+
from .models.interventions import CollectIntervention
2223

2324

2425
# Utils

pyvene/models/blip/modelings_intervenable_blip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111

12-
from pyvene.models.constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
12+
from ..constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
1313

1414
"""blip base model"""
1515
blip_type_to_module_mapping = {

pyvene/models/configuration_intervenable_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from transformers import PreTrainedTokenizer, TensorType, is_torch_available
66
from transformers.configuration_utils import PretrainedConfig
77

8-
from pyvene.models.interventions import VanillaIntervention
8+
from .interventions import VanillaIntervention
99

1010

1111
IntervenableRepresentationConfig = namedtuple(

pyvene/models/gpt2/modelings_intervenable_gpt2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111

12-
from pyvene.models.constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
12+
from ..constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
1313

1414

1515
"""gpt2 base model"""

pyvene/models/gpt_neo/modelings_intervenable_gpt_neo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111

12-
from pyvene.models.constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
12+
from ..constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
1313

1414

1515
"""gpt_neo base model"""

pyvene/models/gpt_neox/modelings_intervenable_gpt_neox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111

12-
from pyvene.models.constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
12+
from ..constants import CONST_INPUT_HOOK, CONST_OUTPUT_HOOK, CONST_QKV_INDICES
1313

1414

1515
"""gpt_neox base model"""

0 commit comments

Comments
 (0)