Skip to main content

Bergson

Bergson is a python library which provides scalable, state-of-the-art data attribution methods for large language models. Data attribution methods estimate the effect on a behavior of interest of removing data points from a model's training corpus. We support EK-FAC (2023), TrackStar (2024), SOURCE (2024), MAGIC (2025), gradient cosine similarity, and more.

We try to make research and application straightforward. You can reproduce any of your runs with a single line, use a few CLI flags to save and re-use useful intermediate artifacts, do everything using just the CLI or just code, train models here or use existing ones, tune and evaluate your methods, and scale them up to multi-node runs with 70B+ parameters. More information is available in the Bergson docs.

Installation

Bergson can be installed using pip:

pip install bergson

Or you can clone the repository and install locally:

git clone https://github.com/EleutherAI/bergson.git
cd bergson
pip install -e .

Functionality

Method LDS (GPT-2 fine-tune) Training Optimizer
MAGIC 0.983 ± 0.005 Adam
Shampoo 0.522 ± 0.037 Muon
EK-FAC 0.474 ± 0.036 Muon
SOURCE 0.387 ± 0.039 Adam
EK-FAC 0.257 ± 0.015 Adam
TrackStar 0.184 ± 0.015 Adam

Attribute through Training

bergson magic runs a powerful attribution method that backpropagates through the training process to compute the gradient of a model behavior loss with respect to a weighting placed on each training item. It is powered by our twice-differentiable trainer, which can also be called directly using bergson train.

Note: unrolled differentiation efficacy is proportional to metasmoothness. Untuned training hyperparameters can result in disappointing linear datamodeling scores. Check your run's estimated metasmoothness with bergson metasmoothness.

bergson approxunrolling is an approximation of bergson magic that uses a handful of training checkpoints to run the multi-step SOURCE attribution pipeline. This is roughly equivalent to an influence function averaged over several checkpoints.

To build a train‑time gradient store, use our HF Trainer callback. This will incur a ~17% performance overhead.

Attribute Post-Hoc

Bergson supports on-disk gradient stores and on-the-fly queries, and per-token and per-sequence attribution.

bergson trackstar and bergson ekfac both orchestrate multi-step attribution recipes over a model checkpoint.

At a lower level, you can build your own gradient store for efficient serial queries using bergson build. Collection-time gradient compression makes the store space-efficient, and a FAISS integration enables fast KNN search over large stores - see bergson query, or Attributor in the programmatic interface. For small queries and methods that don't use gradient compression (e.g., EK-FAC), you can score a dataset in a single pass using an in-memory query index of precomputed gradients. Dataset items may be scored using max, mean, and individual scoring strategies, enabling LESS-style data filtering. See bergson score and bergson build or bergson reduce.

Per-module and per-attention head gradients can be extracted from the store.

Note: influence functions can be sensitive to both Hessian approximation inversion hyperparameters and metasmoothness. Untuned hyperparameters can result in a linear datamodeling score of zero.

Evaluate

Use bergson validate and bergson recall to compute LDS and recall@k metrics respectively.

Examples

There are many example YAMLs in the examples directory. use bergson <yaml_path> to try them. For example, to MAGIC-attribute a GPT-2 WikiText fine-tune:

bergson examples/magic/gpt2_wikitext_tiny.yaml

Or check out a notebook for programmatic usage:

Notebook Description
Open In Colab Poison Detection Detect poisoned training examples with gradient attribution (T4, ~5 min)
Open In Colab Style Ablation Suppress style to recover semantic matching (A100, ~20 min)

Construct and query an on-disk index of randomly projected gradients:

bergson build runs/index --model EleutherAI/pythia-14m --dataset NeelNanda/pile-10k --truncation --token_batch_size 4096 --projection_dim 16
bergson query --index runs/index --unit_norm

Collect TrackStar attribution scores for an I.I.D sample query:

bergson trackstar runs/trackstar --model EleutherAI/pythia-14m --query.dataset NeelNanda/pile-10k --data.dataset NeelNanda/pile-10k --data.truncation --token_batch_size 4096 --query.truncation --query.split "train[:20]"

Development

pip install -e ".[dev]"
pre-commit install
pytest
pyright

We use conventional commits for releases.

If you have multiple GPUs, you can run pytest in distributed mode: pytest -n 8 --dist loadgroup.

Citation

If you found Bergson useful in your research, please cite us:

@misc{quirke2026bergsonopensourcelibrary,
      title={Bergson: An Open Source Library for Data Attribution},
      author={Lucia Quirke and Louis Jaburi and David Johnston and William Z. Li and Gonçalo Paulo and Guillaume Martres and Girish Gupta and Stella Biderman and Nora Belrose},
      year={2026},
      eprint={2606.11660},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2606.11660},
}

Support

If you have suggestions, questions, or would like to collaborate, please email lucia@eleuther.ai or drop us a line in the #data-attribution channel of the EleutherAI Discord!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bergson-0.23.1.tar.gz (307.3 kB view details)

Uploaded Source

Built Distribution

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

bergson-0.23.1-py3-none-any.whl (226.4 kB view details)

Uploaded Python 3

File details

Details for the file bergson-0.23.1.tar.gz.

File metadata

  • Download URL: bergson-0.23.1.tar.gz
  • Upload date:
  • Size: 307.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bergson-0.23.1.tar.gz
Algorithm Hash digest
SHA256 868a975641712c668a407769fce15f208fec8ae0678068e87e5b3fc6a696da44
MD5 13cae49f7aef0c488b4cec8071d5183a
BLAKE2b-256 0b79fefce69189d1e6924f7235960724d256d83e43b7dcae22c33e00af9d72d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bergson-0.23.1.tar.gz:

Publisher: build.yml on EleutherAI/bergson

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

File details

Details for the file bergson-0.23.1-py3-none-any.whl.

File metadata

  • Download URL: bergson-0.23.1-py3-none-any.whl
  • Upload date:
  • Size: 226.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bergson-0.23.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2646978e48f12cb086507aebf4a43771ba6500d2a400aa7a5cb9df2a73d9957d
MD5 74ed23b3d0b67a07314e29e0d0113e69
BLAKE2b-256 093c7fbba35a3448400e85ccec7059e6107cc455d4abd546e808f352d6e904b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bergson-0.23.1-py3-none-any.whl:

Publisher: build.yml on EleutherAI/bergson

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

Release history Release notifications | RSS feed

0.26.2

2 files

0.26.1

2 files

0.26.0

2 files

0.25.1

2 files

0.25.0

2 files

0.24.6

2 files

0.24.5

2 files

0.24.4

2 files

0.24.3

2 files

0.24.2

2 files

0.24.1

2 files

0.24.0

2 files

This release

0.23.1 This release

2 files

0.23.0

2 files

0.22.1

2 files

0.22.0

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.1

2 files

0.16.0

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.13.4

2 files

0.13.3

2 files

0.13.2

2 files

0.13.1

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.1

2 files

0.5.1

2 files

0.5.0

2 files

0.4.6

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page