SongDiffusionSDE#
- class deepinv.sampling.SongDiffusionSDE(beta_t=None, B_t=None, xi_t=None, variance_preserving=False, variance_exploding=False, alpha=0.0, T=1.0, denoiser=None, solver=None, dtype=torch.float64, device=torch.device('cpu'), *args, **kwargs)[source]#
Bases:
EDMDiffusionSDEGenerative diffusion Stochastic Differential Equation.
This class implements the diffusion generative SDE based the formulation from Song et al.[1]:
\[d x_t = -\left(\frac{1}{2} \beta(t) x_t + \frac{1 + \alpha(t)}{2} \xi(t) \nabla \log p_t(x_t) \right) dt + \sqrt{\alpha(t) \xi(t)} d w_t\]where \(\beta(t)\) is a time-dependent linear drift, \(\xi(t)\) is a time-dependent linear diffusion, and \(\alpha(t)\) is weighting the diffusion term.
It corresponds to the reverse-time SDE of the following forward-time SDE:
\[d x_t = -\frac{1}{2} \beta(t) x_t dt + \sqrt{\xi(t)} d w_t\]Compared to the EDM formulation in
deepinv.sampling.EDMDiffusionSDE, the scale \(s(t)\) and noise \(\sigma(t)\) schedulers are defined with respect to \(\beta(t)\) and \(\xi(t)\) as follows:\[s(t) = \exp\left(-\int_0^t \beta(s) ds\right), \quad \sigma(t) = \sqrt{2 \int_0^t \frac{\xi(s)}{s(s)^2} ds}.\]Common choices include the variance-preserving formulation \(\beta(t) = \xi(t)\) and the variance-exploding formulation \(\beta(t) = 0\).
For choosing variance-preserving formulation, set
variance_preserving=Trueandbeta_tandxi_twill be automatically set to be the same function.For choosing variance-exploding formulation, set
variance_exploding=Trueandbeta_twill be automatically set to0.
Note
This SDE must be solved going reverse in time i.e. from \(t=T\) to \(t=0\).
- Parameters:
beta_t (Callable) β a time-dependent linear drift of the forward-time SDE.
B_t (Callable) β time integral of beta_t between 0 and t. If None, it is calculated by numerical integration.
xi_t (Callable) β a time-dependent linear diffusion of the forward-time SDE.
denoiser (deepinv.models.Denoiser) β a denoiser used to provide an approximation of the score at time \(t\): \(\nabla \log p_t\).
alpha (Callable, float) β a (possibly time-dependent) positive scalar weighting the diffusion term. A constant function \(\alpha(t) = 0\) corresponds to ODE sampling and \(\alpha(t) > 0\) corresponds to SDE sampling.
T (float) β the end time of the forward SDE.
solver (deepinv.sampling.BaseSDESolver) β the solver for solving the SDE.
dtype (torch.dtype) β data type of the computation, except for the
denoiserwhich will usetorch.float32. We recommend usingtorch.float64for better stability and less numerical error when solving the SDE in discrete time, since most computation cost is from evaluating thedenoiser, which will be always computed intorch.float32.device (torch.device) β device on which the computation is performed.
*args β additional arguments for the
deepinv.sampling.DiffusionSDE.**kwargs β additional keyword arguments for the
deepinv.sampling.DiffusionSDE.
- References:
Examples using SongDiffusionSDE:#
Building your diffusion posterior sampling method using SDEs