https://github.com/jeakwon/ai-engram
Surgical unlearning of classes, concepts, and facts in any PyTorch model
https://github.com/jeakwon/ai-engram
deep-learning machine-unlearning model-editing pytorch
Last synced: 10 days ago
JSON representation
Surgical unlearning of classes, concepts, and facts in any PyTorch model
- Host: GitHub
- URL: https://github.com/jeakwon/ai-engram
- Owner: jeakwon
- License: mit
- Created: 2026-02-09T17:56:01.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-05-24T19:25:49.000Z (10 days ago)
- Last Synced: 2026-05-24T19:28:06.413Z (10 days ago)
- Topics: deep-learning, machine-unlearning, model-editing, pytorch
- Language: Python
- Homepage: https://jeakwon.github.io/ai-engram/
- Size: 59.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ai-engram
**Surgical unlearning of classes, concepts, and facts in any PyTorch model.**
[](https://pypi.org/project/ai-engram/)
[](https://pypi.org/project/ai-engram/)
[](LICENSE)
[](https://github.com/jeakwon/ai-engram/actions/workflows/ci.yml)
[](https://jeakwon.github.io/ai-engram/)
`ai-engram` identifies the directions in a network's weights that store
specific information — a class, a concept, a fact — and edits them out
in closed form, with no gradient descent. It works on `Linear`,
`Conv1d`, and `Conv2d` layers (grouped and depthwise convolutions
included) and has been verified end-to-end against 24 pretrained
vision, language, and diffusion models.
## Installation
```bash
pip install ai-engram
```
## Quickstart
```python
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
from ai_engram import EditorConfig, EngramEditor
model = nn.Sequential(nn.Linear(8, 16), nn.ReLU(), nn.Linear(16, 4))
forget_loader = DataLoader(TensorDataset(torch.randn(32, 8)), batch_size=8)
total_loader = DataLoader(TensorDataset(torch.randn(128, 8)), batch_size=8)
editor = EngramEditor(model, EditorConfig(device="cpu"))
forget_cov = editor.collect_statistics(forget_loader)
total_cov = editor.collect_statistics(total_loader)
edited = editor.edit(forget_cov, total_cov)
```
`forget_cov` carries the second-moment statistics of the data you want
the model to forget; `total_cov` carries the statistics of the full
training distribution. The edit removes the projection of the weights
onto the forget subspace while preserving the rest.
This exact snippet is executed in CI on every commit and on every
release, so a `pip install` always produces a runnable library.
## Documentation
Full guides, API reference, and the 24-model compatibility report live
at .
## License
[MIT](LICENSE) — see also [CHANGELOG.md](CHANGELOG.md).