A PyTorch library for energy-based modeling, with support for flow and diffusion methods.
What is TorchEBM 🍓?¶
Energy-based models assign a scalar energy to each input, implicitly defining a probability distribution where lower energy means higher probability. This formulation is remarkably general. MCMC sampling, score matching, contrastive divergence, and even flow/diffusion-based generation all operate within or connect naturally to the energy-based framework.
TorchEBM gives you composable PyTorch building blocks that span this entire landscape. You can define energy functions, train models with different learning objectives, and generate samples via MCMC, energy minimization, or learned continuous-time dynamics.
In Action¶
Equilibrium matching with different interpolants transforming noise into structured distributions.
Core Components¶
-
Core
Base classes, energy models (analytical potentials and custom neural networks), schedulers, and the device/dtype management layer shared across all components.
-
Samplers
Draw samples from energy landscapes via MCMC methods, gradient-based optimization, or learned flow/diffusion dynamics (ODE/SDE).
-
Loss Functions
Training objectives for energy-based and flow-based models, including contrastive divergence variants, score matching variants, and equilibrium matching.
-
Interpolants
Define how noise and data are mixed along a continuous time path. Used in flow matching, diffusion, and related generative schemes.
-
Integrators
Numerical solvers for SDEs, ODEs, and Hamiltonian systems. Pluggable into samplers and flow-based generation pipelines.
-
Models
Neural network architectures for parameterizing energy functions and velocity fields, including vision transformers and guidance wrappers.
-
Datasets
Synthetic 2D distributions for rapid prototyping and visual evaluation. All are PyTorch
Datasetobjects. -
CUDA
CUDA-accelerated kernels and mixed precision support for performance-critical sampling and training.
Energy Landscapes¶
Synthetic Datasets¶
Quick Start¶
Define an energy model, create a sampler, and draw samples in a few lines:
See the tutorials and examples for training loops, flow-based generation, and more.
Community & Contribution¶
TorchEBM is open-source and developed with the research community in mind.
- Issues & feature requests on GitHub Issues
- Contributing via developer guide and code guidelines
- Star the repo on GitHub if you find it useful
Citation¶
If TorchEBM is useful in your research, please cite it:
License¶
MIT License. See the LICENSE file for details.
















