Skip to main content

Surgical unlearning of classes, concepts, and facts in any PyTorch model

Project description

ai-engram

Surgical unlearning of classes, concepts, and facts in any PyTorch model.

PyPI version Python versions License: MIT CI Docs

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

pip install ai-engram

Quickstart

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 https://jeakwon.github.io/ai-engram/.

License

MIT — see also CHANGELOG.md.

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

ai_engram-0.3.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

ai_engram-0.3.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_engram-0.3.0.tar.gz.

File metadata

  • Download URL: ai_engram-0.3.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ai_engram-0.3.0.tar.gz
Algorithm Hash digest
SHA256 88f7299acaa7b1f2fcd9f05b6392d852e07078c9801aaa8fae297b00a9fd0761
MD5 e0287a8d442acbd8c92ac8198372baa2
BLAKE2b-256 332b793279406d7987c20907423839270e7f22173eea7bd295374742bb1bb5dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_engram-0.3.0.tar.gz:

Publisher: publish.yml on jeakwon/ai-engram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_engram-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ai_engram-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ai_engram-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5297c2a64c741267e4b729dc5c46969e5d135209a98c434f2b8d837d4ef84c7c
MD5 4a52810d7ed4c4e189e27081f0b92ae8
BLAKE2b-256 eff0efa175860ce36b2e28bb3041a0925e7d7c20b506c5d9fe3b4f67942b685d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_engram-0.3.0-py3-none-any.whl:

Publisher: publish.yml on jeakwon/ai-engram

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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