Azula - Diffusion models in PyTorch
Azula is a Python package that implements diffusion models in PyTorch. Its goal is to unify the different formalisms and notations of the generative diffusion models literature into a single, convenient and hackable interface.
In the Avatar cartoon, Azula is a powerful fire and lightning bender ⚡️
Installation
The azula package is available on PyPI, which means it is installable via pip.
pip install azula
Alternatively, if you need the latest features, you can install it from the repository.
pip install git+https://github.com/probabilists/azula
Getting started
In Azula's formalism, a diffusion model is the composition of three elements: a noise schedule, a denoiser and a sampler.
-
A noise schedule is a mapping from a time $t \in [0, 1]$ to the signal scale $\alpha_t$ and the noise scale $\sigma_t$ in a perturbation kernel $p(X_t \mid X) = \mathcal{N}(X_t \mid \alpha_t X, \sigma_t^2 I)$ from a "clean" random variable $X \sim p(X)$ to a "noisy" random variable $X_t$.
-
A denoiser is a neural network trained to predict $X$ given $X_t$.
-
A sampler defines a series of transition kernels $q(X_s \mid X_t)$ from $t$ to $s < t$ based on a noise schedule and a denoiser. Simulating these transitions from $t = 1$ to $0$ samples approximately from $p(X)$.
This formalism is closely followed by Azula's API.
from azula.denoise import KarrasDenoiser
from azula.noise import VPSchedule
from azula.sample import DDPMSampler
# Choose the variance preserving (VP) noise schedule
schedule = VPSchedule()
# Initialize a denoiser
denoiser = KarrasDenoiser(
backbone=CustomNN(in_features=5, out_features=5),
schedule=schedule,
)
# Train to predict x given x_t
optimizer = torch.optim.Adam(denoiser.parameters(), lr=1e-3)
for x in train_loader:
t = torch.rand((batch_size,))
loss = denoiser.loss(x, t)
loss.backward()
optimizer.step()
optimizer.zero_grad()
# Generate 64 points in 1000 steps
sampler = DDPMSampler(denoiser.eval(), steps=1000)
x1 = sampler.init((64, 5))
x0 = sampler(x1)
Alternatively, Azula's plugin interface allows to load pre-trained models and use them with the same convenient interface.
from azula.plugins import adm
from azula.sample import DDIMSampler
# Download weights from openai/guided-diffusion
denoiser = adm.load_model("imagenet_256x256")
denoiser.to("cuda")
# Generate a batch of 4 images
sampler = DDIMSampler(denoiser, steps=64)
x1 = sampler.init((4, 3, 256, 256), device="cuda")
x0 = sampler(x1)
images = torch.clip((x0 + 1) / 2, min=0, max=1)
For more information, check out the documentation and tutorials at azula.readthedocs.io.
Contributing
If you have a question, an issue or would like to contribute, please read our contributing guidelines.
Metadata
Release files for azula 0.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| azula-0.11.1.tar.gz | 68.2 kB | Without provenance | Details for azula-0.11.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| azula-0.11.1-py3-none-any.whl | Python 3 | none | any | Details for azula-0.11.1-py3-none-any.whl |
Total release size: 160.7 kB
Release files / azula-0.11.1.tar.gz
| Download URL | azula-0.11.1.tar.gz |
|---|---|
| Size | 68.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e228ce1c6397a863bdefa1b59a39862e870be5be7e414315e6997761b4d181b
|
|
BLAKE2b-256 checksum How to use checksums |
2d2025391a73d3af1e790b69aade1d69567fa044de5eaef063df8d52469d3761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / azula-0.11.1-py3-none-any.whl
| Download URL | azula-0.11.1-py3-none-any.whl |
|---|---|
| Size | 92.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a98874de0351ba83800f89af11198f6f0fef837a6a053f9bc0fce14171f984a
|
|
BLAKE2b-256 checksum How to use checksums |
c82a7bf28bca883e11c9661f51c65e03e45e3d93c8d3621ef960750434fc53c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for azula 0.11.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.