azula.sample¶
Reverse diffusion samplers.
For a distribution \(p(X)\) over \(\mathbb{R}^D\), the perturbation kernel (see
azula.noise)
defines a series of marginal distributions
The goal of diffusion models is to generate samples from \(p(X_0)\). To this end, reverse transition kernels \(q(X_s \mid X_t)\) from \(t\) to \(s < t\) are chosen. Then, starting from \(x_1 \sim p(X_1)\), \(T\) transitions \(x_{t_{i-1}} \sim q(X_{t_{i-1}} \mid x_{t_i})\) are simulated from \(t_T = 1\) to \(t_0 = 0\). If the kernels are consistent with the marginals \(p(X_t)\), that is if
for all \(i = 1, \dots, T\), the vectors \(x_{t_i}\) are distributed according to \(p(X_{t_i})\), including the last one \(x_{t_0} = x_0\).
Classes¶
Abstract reverse diffusion sampler. |
|
Creates an DDPM sampler. |
|
Creates a DDIM sampler. |
Descriptions¶
- class azula.sample.Sampler(steps)¶
Abstract reverse diffusion sampler.
- Parameters:
steps (int) – The number of discretization steps \(T\). By default, the step size \(t - s\) is constant.
- forward(x_1, **kwargs)¶
Simulates the reverse process from \(t = 1\) to \(0\).
- abstract step(x_t, t, s, **kwargs)¶
Simulates the reverse process from \(t\) to \(s \leq t\).
- Parameters:
- Returns:
The new vector \(x_s \sim q(X_s \mid x_t)\), with shape \((*, D)\).
- Return type:
- class azula.sample.DDPMSampler(denoiser, **kwargs)¶
Creates an DDPM sampler.
\[x_s = \alpha_s \mu_\phi(x_t) + \sigma_s \, \sqrt{1 - \tau} \, \frac{x_t - \alpha_t \mu_\phi(x_t)}{\sigma_t} + \sigma_s \, \sqrt{\tau} \, \epsilon\]where \(\epsilon \sim \mathcal{N}(0, I)\) and
\[\tau = 1 - \frac{\alpha_t^2}{\alpha_s^2} \frac{\sigma_s^2}{\sigma_t^2} \, .\]References
Denoising Diffusion Probabilistic Models (Ho et al., 2020)- Parameters:
denoiser (GaussianDenoiser) – A Gaussian denoiser.
kwargs – Keyword arguments passed to
Sampler.
- class azula.sample.DDIMSampler(denoiser, eta=None, **kwargs)¶
Creates a DDIM sampler.
\[x_s = \alpha_s \mu_\phi(x_t) + \sigma_s \, \sqrt{1 - \eta \, \tau} \, \frac{x_t - \alpha_t \mu_\phi(x_t)}{\sigma_t} + \sigma_s \, \sqrt{\eta \, \tau} \, \epsilon\]where \(\epsilon \sim \mathcal{N}(0, I)\) and
\[\tau = 1 - \frac{\alpha_t^2}{\alpha_s^2} \frac{\sigma_s^2}{\sigma_t^2} \, .\]References
Denoising Diffusion Implicit Models (Song et al., 2021)- Parameters:
denoiser (GaussianDenoiser) – A Gaussian denoiser.
eta (float | None) – The stochasticity hyperparameter \(\eta \in \mathbb{R}_+\). If \(\eta = 1\),
DDIMSampleris equivalent toDDPMSampler. Ifeta is None, \(\eta = 0\) and the sampler is deterministic.kwargs – Keyword arguments passed to
Sampler.