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.2.0.tar.gz (14.3 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.2.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_engram-0.2.0.tar.gz
  • Upload date:
  • Size: 14.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 6cd5183ed317dd7e5dc307ed9551657f9b6accd169d65b1726ec906a914b3df6
MD5 e1b5c57c41d0d8002fefe3e4df722cc7
BLAKE2b-256 4f47210103e634ddfb608ef03bae790f5c935ca0ec44b7dd60fe91f3d401c89c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ai_engram-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49fe354cb5bac6691689923be41923c530b7bcca4d81b00c826815eb2a2ddc4b
MD5 7940eae3108de0075b3356ec08c18649
BLAKE2b-256 2bf84fa5129e19452846c0f3c9dbb0c6c60355fcf3a5097b40bc88efc087c560

See more details on using hashes here.

Provenance

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