TorchEBM provides composable PyTorch primitives for generative models that learn dynamics on data space, from energy-based models to diffusion, flow matching, and equilibrium and energy matching: energies and fields, samplers, losses, interpolants, couplings, integrators, and schedulers. This page takes you from installation to the core workflows the library is built around.
An energy \(E(x)\) defines a density \(p(x) \propto e^{-E(x)}\). Samplers draw from it using only the energy's gradient, here with Langevin dynamics. The model is an argument of the call, as the function is for torchdiffeq:
Every sampler is vectorized over chains: the call above runs 2000 independent chains as one tensor program and recovers the target covariance. Swap in HamiltonianMonteCarlo or change integrator= without touching the rest.
Any differentiable module mapping (N, d) to (N,) is a valid energy. Train it with contrastive divergence: the sampler draws negatives from the current model and the loss compares the energies of data and negatives:
The same library expresses continuous-time generation. Equilibrium matching regresses a time-invariant field onto the velocity of the interpolant path, and FlowSampler integrates it from noise:
Each piece is chosen independently: the interpolant selects the probability path, the integrator string selects the numerics, and a coupling called before the interpolant selects how noise is paired with data.