Overview
This quickstart guide will show you how to:- Create a normalizing flow
- Train it on data using maximum likelihood
- Generate samples from the learned distribution
p(x | c).
Basic Example
Import dependencies
First, import the necessary libraries:That’s it! Zuko is designed to be minimal and intuitive.
Create a normalizing flow
Create a Neural Spline Flow with 3 sample features and 5 context features:The flow is a
The
NSF class creates a Neural Spline Flow with rational-quadratic splines, one of the most powerful and flexible flow architectures available.torch.nn.Module, so you can inspect its parameters:Prepare your data
For this example, let’s create a simple synthetic dataset:In real applications,
x and c would be your actual data samples and conditioning variables.Train the flow
Train the flow by maximizing the log-likelihood of the data:
The key line is
flow(c).log_prob(x): passing context c to the flow returns a distribution p(x | c), which we can then evaluate at points x.Complete Working Example
Here’s a complete, runnable script that ties everything together:Other Flow Architectures
Zuko provides many pre-built flow architectures. Here are some popular alternatives to NSF:log_prob, and sample from the learned distribution.
Building Custom Flows
For more control, you can build custom flows using theFlow class:
- The sequence of transformations
- The base distribution
- Which layers are conditional vs unconditional
- Architecture details of each transformation
Key Takeaways
Simple API
Create flows with a single line, train with standard PyTorch patterns
Conditional Modeling
Built-in support for
p(x | c) - just pass context to the flowMultiple Architectures
12+ pre-built flows from recent research papers
Full Control
Build custom flows with the
Flow class for maximum flexibilityWhat’s Next?
Now that you’ve built your first flow, explore more advanced topics:Flow Architectures
Learn about different flow architectures and when to use them
API Reference
Detailed documentation of all flows and their parameters
Examples
Real-world examples and tutorials
Custom Flows
Build your own flow architectures
