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", damping_factor=1e-3))

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.1.0.tar.gz (16.2 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.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_engram-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 9717a5a33755846f2a99a98b609c9f5e900958cf7f6dd2fc1aacbc6a2cddc414
MD5 64003a3257305142d91156fe3dee2d5e
BLAKE2b-256 5d384bef708644f2e65bdc98013dd386dd610ded1c14f03833ab8c1e7e42ba23

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_engram-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_engram-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b423dafc46892a787abdaa44c9f83b9ad31d929bec55888b7d846feb78bf5a5
MD5 e9f5e84f300d4bd2ccf79347196ad9a6
BLAKE2b-256 ed8aab5ff695b232637440e02611e2ca49e5aab7040b81ff646c45c2e6da9e4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_engram-0.1.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