Getting Started with TorchEBM¶
Welcome to the TorchEBM guides section! These comprehensive guides will help you understand how to use TorchEBM effectively for your energy-based modeling tasks.
Core Concepts¶
-
Energy Functions
Learn about the foundation of energy-based models and how to work with energy functions in TorchEBM.
-
Samplers
Discover how to generate samples from energy landscapes using various sampling algorithms.
-
Loss Functions
Explore different loss functions for training energy-based models.
-
Custom Neural Networks
Learn how to create and use neural networks as energy functions.
-
Training EBMs
Master the techniques for effectively training energy-based models.
-
Visualization
Visualize energy landscapes and sampling results to gain insights.
Quick Start¶
If you're new to energy-based models, we recommend the following learning path:
- Start with the Introduction to understand basic concepts
- Follow the Installation guide to set up TorchEBM
- Read the Energy Functions guide to understand the fundamentals
- Explore the Samplers guide to learn how to generate samples
- Study the Training guide to learn how to train your models
Basic Example¶
Here's a simple example to get you started with TorchEBM:
import torch
from torchebm.core import GaussianEnergy
from torchebm.samplers.langevin_dynamics import LangevinDynamics
# Create an energy function (2D Gaussian)
energy_fn = GaussianEnergy(
mean=torch.zeros(2),
cov=torch.eye(2)
)
# Create a sampler
sampler = LangevinDynamics(
energy_function=energy_fn,
step_size=0.01
)
# Generate samples
samples = sampler.sample_chain(
dim=2, n_steps=100, n_samples=1000
)
# Print sample statistics
print(f"Sample mean: {samples.mean(0)}")
print(f"Sample std: {samples.std(0)}")
Common Patterns¶
Here are some common patterns you'll encounter throughout the guides:
Next Steps¶
Once you're familiar with the basics, you can:
- Explore detailed Examples that demonstrate TorchEBM in action
- Check the API Reference for comprehensive documentation
- Learn how to contribute to TorchEBM in the Developer Guide
Remember that all examples in these guides are tested with the latest version of TorchEBM, and you can run them in your own environment to gain hands-on experience.