Diffusion Models#
Diffusion Model Types#
- class diffuse.diffusion.sde.SDE(beta: Schedule)[source]#
Bases:
DiffusionModelVariance Preserving (VP) SDE for diffusion models.
Implements the forward SDE:
\[dX(t) = -\frac{1}{2}\beta(t) X(t) dt + \sqrt{\beta(t)} dW(t)\]where \(\beta(t)\) is the noise schedule and \(dW(t)\) is the Wiener process.
This formulation preserves the variance of the data distribution and is the standard choice for diffusion probabilistic models.
- Parameters:
beta – Noise schedule (LinearSchedule or CosineSchedule)
- noise_level(t: Array) Array[source]#
Compute noise level \(\sigma(t)\) for diffusion process.
The solution to the VP-SDE is:
\[X(t) = \alpha(t) X_0 + \sigma(t) \varepsilon, \quad \varepsilon \sim \mathcal{N}(0, I)\]where \(\alpha(t) = \exp\left(-\frac{1}{2}\int_0^t \beta(s) ds\right)\) and \(\sigma(t) = \sqrt{1 - \alpha^2(t)}\)
- Returns:
Noise level \(\sigma(t)\) clipped for numerical stability
- sde_coefficients(t: Array) tuple[Array, Array][source]#
Compute SDE coefficients \(f(t)\) and \(g(t)\).
For the VP-SDE: \(dX(t) = -\frac{1}{2}\beta(t) X(t) dt + \sqrt{\beta(t)} dW(t)\)
- Returns:
Tuple of drift coefficient \(f(t) = -\frac{1}{2}\beta(t)\) and diffusion coefficient \(g(t) = \sqrt{\beta(t)}\)
- class diffuse.diffusion.sde.Flow(tf: float = 1.0)[source]#
Bases:
DiffusionModelRectified Flow diffusion model with straight-line interpolation paths.
Implements the rectified flow formulation from Liu et al. (2022) with linear schedules:
\[\alpha(t) = 1 - t, \quad \sigma(t) = t\]This creates straight-line interpolation paths:
\[x_t = (1-t)x_0 + t\varepsilon, \quad \varepsilon \sim \mathcal{N}(0, I)\]which are more amenable to ODE-based sampling with fewer discretization steps.
- Parameters:
tf – Final time for the diffusion process (default: 1.0)
References
Liu, X., Gong, C., & Liu, Q. (2022). Flow straight and fast: Learning to generate and transfer data with rectified flow. arXiv:2209.03003
- noise_level(t: Array) Array[source]#
Compute noise level \(\sigma(t) = t\).
- Returns:
Noise level clipped for numerical stability
- class diffuse.diffusion.sde.EDM(tf: float = 1.0)[source]#
Bases:
DiffusionModelEfficient Diffusion Model (EDM) from Karras et al. (2022).
Implements the EDM formulation with constant signal and increasing noise:
\[\alpha(t) = 1, \quad \sigma(t) = t\]This creates the simple interpolation:
\[x_t = x_0 + t\varepsilon, \quad \varepsilon \sim \mathcal{N}(0, I)\]which simplifies the probability-flow ODE and is particularly effective with Heun’s integration method.
- Parameters:
tf – Final time for the diffusion process (default: 1.0)
References
Karras, T., Aittala, M., Aila, T., & Laine, S. (2022). Elucidating the design space of diffusion-based generative models. NeurIPS 35, 26565-26577.
- noise_level(t: Array) Array[source]#
Compute noise level \(\sigma(t) = t\).
- Returns:
Noise level clipped for numerical stability
Noise Schedules#
- class diffuse.diffusion.sde.LinearSchedule(b_min: float, b_max: float, t0: float, T: float)[source]#
Bases:
objectLinear noise schedule for diffusion processes.
Implements a linear interpolation between minimum and maximum noise levels:
\[\beta(t) = \beta_{\min} + \frac{\beta_{\max} - \beta_{\min}}{T - t_0}(t - t_0)\]- Parameters:
b_min – The minimum noise value \(\beta_{\min}\)
b_max – The maximum noise value \(\beta_{\max}\)
t0 – The starting time \(t_0\)
T – The ending time \(T\)
- class diffuse.diffusion.sde.CosineSchedule(b_min: float, b_max: float, t0: float, T: float, s: float = 0.008)[source]#
Bases:
ScheduleCosine noise schedule for improved denoising.
Implements the cosine schedule from Nichol & Dhariwal (2021) which provides better signal-to-noise ratio properties than linear schedules. The schedule is based on:
\[\bar{\alpha}(t) = \frac{\cos\left(\frac{t/T + s}{1+s} \cdot \frac{\pi}{2}\right)^2}{\cos\left(\frac{s}{1+s} \cdot \frac{\pi}{2}\right)^2}\]- Parameters:
b_min – The minimum beta value \(\beta_{\min}\)
b_max – The maximum beta value \(\beta_{\max}\)
t0 – The starting time \(t_0\)
T – The ending time \(T\)
s – Offset parameter for numerical stability (default: 0.008)
References
Nichol, A., & Dhariwal, P. (2021). Improved Denoising Diffusion Probabilistic Models. arXiv:2102.09672