mi-crow 1.0.0.post1__py3-none-any.whl → 1.0.0.post2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mi_crow-1.0.0.post1.dist-info → mi_crow-1.0.0.post2.dist-info}/METADATA +190 -5
- {mi_crow-1.0.0.post1.dist-info → mi_crow-1.0.0.post2.dist-info}/RECORD +4 -4
- {mi_crow-1.0.0.post1.dist-info → mi_crow-1.0.0.post2.dist-info}/WHEEL +0 -0
- {mi_crow-1.0.0.post1.dist-info → mi_crow-1.0.0.post2.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mi-crow
|
|
3
|
-
Version: 1.0.0.
|
|
4
|
-
Summary:
|
|
5
|
-
Author
|
|
3
|
+
Version: 1.0.0.post2
|
|
4
|
+
Summary: Python library for mechanistic interpretability research on Large Language Models. Designed for researchers, provides unified interface for SAE training, activation hooks, and concept manipulation.
|
|
5
|
+
Author: Hubert Kowalski
|
|
6
|
+
Author-email: Adam Kaniasty <adam.kaniasty@gmail.com>
|
|
7
|
+
Maintainer: Hubert Kowalski
|
|
8
|
+
Maintainer-email: Adam Kaniasty <adam.kaniasty@gmail.com>
|
|
6
9
|
Requires-Python: >=3.10
|
|
7
10
|
Description-Content-Type: text/markdown
|
|
8
11
|
Requires-Dist: accelerate>=1.10.1
|
|
@@ -37,10 +40,153 @@ Requires-Dist: mkdocs-literate-nav>=0.6; extra == "docs"
|
|
|
37
40
|
Requires-Dist: mkdocs-gen-files>=0.5; extra == "docs"
|
|
38
41
|
Requires-Dist: mike>=2.1; extra == "docs"
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
<div align="center">
|
|
44
|
+
<img src="docs/logo.svg" alt="Mi-Crow Logo" width="200">
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
# Mi-Crow: Mechanistic Interpretability for Large Language Models
|
|
48
|
+
|
|
49
|
+
[](https://github.com/AdamKaniasty/Inzynierka/actions)
|
|
50
|
+
[](https://pypi.org/project/mi-crow/)
|
|
41
51
|
[](https://adamkaniasty.github.io/Inzynierka/)
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
**Mi-Crow** is a Python library for mechanistic interpretability research on Large Language Models (LLMs). Designed for researchers, it provides a unified interface for analyzing and controlling model behavior through Sparse Autoencoders (SAEs), activation hooks, and concept manipulation.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Unified Model Interface** - Work with any HuggingFace language model through a consistent API
|
|
58
|
+
- **Sparse Autoencoder Training** - Train SAEs to extract interpretable features from model activations
|
|
59
|
+
- **Hook System** - Intercept and manipulate model activations with minimal performance overhead
|
|
60
|
+
- **Concept Discovery & Manipulation** - Discover and control model behavior through learned concepts
|
|
61
|
+
- **Hierarchical Data Persistence** - Efficient storage and management of large-scale experiment data
|
|
62
|
+
- **Research Focused** - Comprehensive testing (85%+ coverage), extensive documentation, and designed for interpretability research workflows
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
### Install from PyPI
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install mi-crow
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Install from Source
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/AdamKaniasty/Mi-Crow.git
|
|
76
|
+
cd Mi-Crow
|
|
77
|
+
pip install -e .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Requirements
|
|
81
|
+
|
|
82
|
+
- **Python 3.12+** (required for modern type hints and features)
|
|
83
|
+
- **PyTorch** - Tensor operations and neural networks
|
|
84
|
+
- **Transformers** - Model loading and tokenization
|
|
85
|
+
- **Accelerate** - Distributed and mixed-precision training
|
|
86
|
+
- **Datasets** - Dataset loading and processing
|
|
87
|
+
- **overcomplete** - SAE implementations
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
### Basic Usage
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from mi_crow.language_model import LanguageModel
|
|
95
|
+
|
|
96
|
+
# Initialize a language model
|
|
97
|
+
lm = LanguageModel(model_id="bielik")
|
|
98
|
+
|
|
99
|
+
# Run inference
|
|
100
|
+
outputs = lm.forwards(["Hello, world!"])
|
|
101
|
+
|
|
102
|
+
# Access activations and outputs
|
|
103
|
+
print(outputs.logits)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Training an SAE
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from mi_crow.language_model import LanguageModel
|
|
110
|
+
from mi_crow.mechanistic.sae import SaeTrainer
|
|
111
|
+
from mi_crow.mechanistic.sae.modules import TopKSae
|
|
112
|
+
|
|
113
|
+
# Load model and collect activations
|
|
114
|
+
lm = LanguageModel(model_id="bielik")
|
|
115
|
+
activations = lm.save_activations(
|
|
116
|
+
dataset=["Your text data here"],
|
|
117
|
+
layers=["transformer_h_0_attn_c_attn"]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Train SAE
|
|
121
|
+
trainer = SaeTrainer(
|
|
122
|
+
model=lm,
|
|
123
|
+
layer="transformer_h_0_attn_c_attn",
|
|
124
|
+
sae_class=TopKSae,
|
|
125
|
+
hyperparams={"epochs": 10, "batch_size": 256}
|
|
126
|
+
)
|
|
127
|
+
sae = trainer.train(activations)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Concept Manipulation
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
# Load concepts and manipulate model behavior
|
|
134
|
+
concepts = lm.load_concepts(sae_id="your_sae_id")
|
|
135
|
+
concepts.manipulate(neuron_idx=0, scale_factor=1.5)
|
|
136
|
+
|
|
137
|
+
# Run inference with concept manipulation
|
|
138
|
+
outputs = lm.forwards(
|
|
139
|
+
["Your prompt"],
|
|
140
|
+
with_controllers=True,
|
|
141
|
+
concept_config=concepts
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
146
|
+
|
|
147
|
+
- **Full Documentation**: [adamkaniasty.github.io/Inzynierka](https://adamkaniasty.github.io/Inzynierka/)
|
|
148
|
+
- **GitHub Repository**: [github.com/AdamKaniasty/Mi-Crow](https://github.com/AdamKaniasty/Mi-Crow/)
|
|
149
|
+
- **Example Notebooks**: See `examples/` directory for Jupyter notebook tutorials
|
|
150
|
+
|
|
151
|
+
## Architecture
|
|
152
|
+
|
|
153
|
+
Mi-Crow follows a modular design with five core components:
|
|
154
|
+
|
|
155
|
+
1. **`language_model/`** - Unified interface for language models
|
|
156
|
+
- Model initialization from HuggingFace Hub or local files
|
|
157
|
+
- Unified inference interface with mixed-precision support
|
|
158
|
+
- Architecture-agnostic layer abstraction
|
|
159
|
+
|
|
160
|
+
2. **`hooks/`** - Flexible hook system for activation interception
|
|
161
|
+
- Detectors for observing activations
|
|
162
|
+
- Controllers for modifying model behavior
|
|
163
|
+
- Support for FORWARD and PRE_FORWARD hooks
|
|
164
|
+
|
|
165
|
+
3. **`mechanistic/`** - SAE training and concept manipulation
|
|
166
|
+
- Sparse Autoencoder training (TopK, L1 variants)
|
|
167
|
+
- Concept dictionary management
|
|
168
|
+
- Concept-based model steering
|
|
169
|
+
|
|
170
|
+
4. **`store/`** - Hierarchical data persistence
|
|
171
|
+
- Efficient tensor storage in safetensors format
|
|
172
|
+
- Batch iteration for large datasets
|
|
173
|
+
- Metadata management
|
|
174
|
+
|
|
175
|
+
5. **`datasets/`** - Dataset loading and processing
|
|
176
|
+
- HuggingFace dataset integration
|
|
177
|
+
- Local file dataset support
|
|
178
|
+
|
|
179
|
+
## Example Workflow
|
|
180
|
+
|
|
181
|
+
See the example notebooks in the `examples/` directory:
|
|
182
|
+
|
|
183
|
+
1. **`01_train_sae_model.ipynb`** - Train an SAE on model activations
|
|
184
|
+
2. **`02_attach_sae_and_save_texts.ipynb`** - Collect top activating texts
|
|
185
|
+
3. **`03_load_concepts.ipynb`** - Load and manipulate concepts
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
### Running Tests
|
|
44
190
|
|
|
45
191
|
The project uses pytest for testing. Tests are organized into unit tests and end-to-end tests.
|
|
46
192
|
|
|
@@ -78,6 +224,45 @@ pytest tests/e2e -q
|
|
|
78
224
|
|
|
79
225
|
The test suite is configured to require at least 85% code coverage. Coverage reports are generated in both terminal and XML formats.
|
|
80
226
|
|
|
227
|
+
The project maintains **85%+ code coverage** requirement.
|
|
228
|
+
|
|
229
|
+
### Code Quality
|
|
230
|
+
|
|
231
|
+
- **Linting**: Ruff for code formatting and linting
|
|
232
|
+
- **Pre-commit Hooks**: Automated quality checks
|
|
233
|
+
- **Type Hints**: Extensive use of Python type annotations
|
|
234
|
+
- **CI/CD**: GitHub Actions for automated testing and deployment
|
|
235
|
+
|
|
236
|
+
## Citation
|
|
237
|
+
|
|
238
|
+
If you use Mi-Crow in your research, please cite:
|
|
239
|
+
|
|
240
|
+
```bibtex
|
|
241
|
+
@thesis{kaniasty2025microw,
|
|
242
|
+
title={Mechanistic Interpretability for Large Language Models: A Production-Ready Framework},
|
|
243
|
+
author={Kaniasty, Adam and Kowalski, Hubert},
|
|
244
|
+
year={2025},
|
|
245
|
+
school={Warsaw University of Technology},
|
|
246
|
+
note={Engineering Thesis}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
See the main repository for license information: [Mi-Crow License](https://github.com/AdamKaniasty/Mi-Crow/)
|
|
253
|
+
|
|
254
|
+
## Contact
|
|
255
|
+
|
|
256
|
+
- **Maintainers**: Adam Kaniasty, Hubert Kowalski
|
|
257
|
+
- **Email**: adam.kaniasty@gmail.com
|
|
258
|
+
- **GitHub**: [@AdamKaniasty](https://github.com/AdamKaniasty)
|
|
259
|
+
|
|
260
|
+
## Acknowledgments
|
|
261
|
+
|
|
262
|
+
This work was developed in collaboration with the **Bielik** team and represents a contribution to the open-source mechanistic interpretability community.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
81
266
|
## Backend (FastAPI) quickstart
|
|
82
267
|
|
|
83
268
|
Install server-only dependencies (kept out of the core library) with uv:
|
|
@@ -48,7 +48,7 @@ mi_crow/store/__init__.py,sha256=DrYTpdgzrRzjHm9bigy-GiP0BGxzjmD3-lJCthtgxbE,123
|
|
|
48
48
|
mi_crow/store/local_store.py,sha256=0Djh3zIVYWx_NASUv6VXfVLV3gRzTduFFgO7wswYcZA,17571
|
|
49
49
|
mi_crow/store/store.py,sha256=ZxxIvhSPunUG7XsVGiDyqxk71Cmb0h-vSwLbZbDCRko,11299
|
|
50
50
|
mi_crow/store/store_dataloader.py,sha256=UkZhHCOTg56ozomPtU9vHBhxIMOPcOiyfMqiAxgqtQs,4341
|
|
51
|
-
mi_crow-1.0.0.
|
|
52
|
-
mi_crow-1.0.0.
|
|
53
|
-
mi_crow-1.0.0.
|
|
54
|
-
mi_crow-1.0.0.
|
|
51
|
+
mi_crow-1.0.0.post2.dist-info/METADATA,sha256=BUbZvRNArEuUWzk5fDV7z_CzzLgyrDNr-MAqiwE5ZiI,12475
|
|
52
|
+
mi_crow-1.0.0.post2.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
53
|
+
mi_crow-1.0.0.post2.dist-info/top_level.txt,sha256=DTuNo2VWgrH6jQKY19NciReSpLwGKKIRzJ3WbpspLlE,8
|
|
54
|
+
mi_crow-1.0.0.post2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|