TorchEBM provides composable PyTorch primitives for energy-based generative modeling: energies, samplers, losses, interpolants, couplings, integrators, and schedulers. This page takes you from installation to the core workflows the library is built around.
importtorchfromtorchebm.coreimportGaussianModelfromtorchebm.samplersimportLangevinDynamicsmodel=GaussianModel(mean=torch.zeros(2),cov=torch.tensor([[1.0,0.8],[0.8,1.0]]))sampler=LangevinDynamics(model=model,step_size=0.02,noise_scale=1.0)samples=sampler.sample(dim=2,n_samples=2000,n_steps=500)# (2000, 2)print(torch.cov(samples.T))# recovers the target covariance
Every sampler is vectorized over chains: the call above runs 2000 independent chains as one tensor program. Swap in HamiltonianMonteCarlo or change integrator= without touching the rest.
The pieces are interchangeable by construction: the interpolant string selects the probability path, the integrator string selects the numerics, and a coupling= argument on transport-based losses selects how noise is paired with data.