Thanks for your interest! This library aims to be narrow and reliable — a small, well-tested set of energy-based-model primitives — so contributions that deepen correctness, clarity, and evaluation are especially welcome.
The project uses uv. No manual venv needed:
git clone https://github.com/davidkhjo/ebmkit
cd ebmkit
uv run pytest # full test suite (CPU-only, seeded)
uv run ruff check . # lint
uv run ruff format . # formattorch is the only runtime dependency; matplotlib is an optional [viz]
extra used by the examples and ebm.viz.
These are load-bearing — please keep them intact:
- Sign convention:
p(x) ∝ exp(-E(x))everywhere. Low energy = high probability. Samplers descend the energy gradient; training pushes data energy down. Never flip this. - Energy functions are any callable
(B, *event_shape) -> (B,)— a plain function, a lambda, or annn.Module. - Stop-gradients: MCMC negatives are detached before the loss, and the
energy network's parameters are frozen during sampling
(
ebm.utils.frozen_params). Score-matching losses instead keep the graph withcreate_graph=True. - Losses are
nn.Modules returningLossOutput(loss, metrics, x_neg). Supervised losses (e.g.JEMLoss) set a class attributesupervised = True. - Networks: no BatchNorm in energy networks (it breaks per-sample energies and MCMC); SiLU activations; spectral norm is an opt-in flag.
Every core module has a test file under tests/. Prefer closed-form or
distributional checks over smoke tests — the suite verifies samplers against
known Gaussians, AIS against analytic log Z, lattice energies against
hand-computed values, and so on. Dataset tests are offline (they build
synthetic archives in tmp_path); never add a test that hits the network.
- Branch from
main. - Keep the change focused; add or update tests.
- Ensure
make check(lint, type-check, tests) is green — or runuv run ruff check .,uv run ruff format --check .,uv run mypy, anduv run pytestindividually. - Open a PR against
main. CI runs the suite on Python 3.10–3.13, and every PR is reviewed by Claude before it can be merged. Only a maintainer merges.
- A loss subclasses
nn.Module, lives undersrc/ebm/losses/, and returns aLossOutput. Add a distributional test (e.g. recover a known parameter). - A sampler subclasses
ebm.samplers.base.Samplerand implementsstep; the base class handles the detach/freeze loop. Add a test that it targets a known distribution and, for MH samplers, exposeslast_accept_rate.
The version lives in one place, src/ebm/__init__.py, and hatchling reads it.
To cut a release:
# 1. update CHANGELOG.md, then bump (also commits + tags):
make bump-patch # or bump-minor / bump-major
# 2. publish:
git push --follow-tags
gh release create vX.Y.Z --title vX.Y.Z --notes "See CHANGELOG.md"The GitHub release triggers publish.yml, which builds and uploads to PyPI via
trusted publishing.