Denoising Diffusion Implicit Models

Jiaming Song, Chenlin Meng, Stefano Ermon

Introduction

Deep generative models have demonstrated the ability to produce high quality samples in many domains (Karras et al., 2020; van den Oord et al., 2016a). In terms of image generation, generative adversarial networks (GANs, Goodfellow et al. (2014)) currently exhibits higher sample quality than likelihood-based methods such as variational autoencoders (Kingma & Welling, 2013), autoregressive models (van den Oord et al., 2016b) and normalizing flows (Rezende & Mohamed, 2015; Dinh et al., 2016). However, GANs require very specific choices in optimization and architectures in order to stabilize training (Arjovsky et al., 2017; Gulrajani et al., 2017; Karras et al., 2018; Brock et al., 2018), and could fail to cover modes of the data distribution (Zhao et al., 2018).

Recent works on iterative generative models (Bengio et al., 2014), such as denoising diffusion probabilistic models (DDPM, Ho et al. (2020)) and noise conditional score networks (NCSN, Song & Ermon (2019)) have demonstrated the ability to produce samples comparable to that of GANs, without having to perform adversarial training. To achieve this, many denoising autoencoding models are trained to denoise samples corrupted by various levels of Gaussian noise. Samples are then produced by a Markov chain which, starting from white noise, progressively denoises it into an image. This generative Markov Chain process is either based on Langevin dynamics (Song & Ermon, 2019) or obtained by reversing a forward diffusion process that progressively turns an image into noise (Sohl-Dickstein et al., 2015).

A critical drawback of these models is that they require many iterations to produce a high quality sample. For DDPMs, this is because that the generative process (from noise to data) approximates the reverse of the forward diffusion process (from data to noise), which could have thousands of steps; iterating over all the steps is required to produce a single sample, which is much slower compared to GANs, which only needs one pass through a network. For example, it takes around 20 hours to sample 50k images of size 32×3232\times 32 from a DDPM, but less than a minute to do so from a GAN on a Nvidia 2080 Ti GPU. This becomes more problematic for larger images as sampling 50k images of size 256×256256\times 256 could take nearly 10001000 hours on the same GPU.

To close this efficiency gap between DDPMs and GANs, we present denoising diffusion implicit models (DDIMs). DDIMs are implicit probabilistic models (Mohamed & Lakshminarayanan, 2016) and are closely related to DDPMs, in the sense that they are trained with the same objective function. In Section 3, we generalize the forward diffusion process used by DDPMs, which is Markovian, to non-Markovian ones, for which we are still able to design suitable reverse generative Markov chains. We show that the resulting variational training objectives have a shared surrogate objective, which is exactly the objective used to train DDPM. Therefore, we can freely choose from a large family of generative models using the same neural network simply by choosing a different, non-Markovian diffusion process (Section 4.1) and the corresponding reverse generative Markov Chain. In particular, we are able to use non-Markovian diffusion processes which lead to "short" generative Markov chains (Section 4.2) that can be simulated in a small number of steps. This can massively increase sample efficiency only at a minor cost in sample quality.

In Section 5, we demonstrate several empirical benefits of DDIMs over DDPMs. First, DDIMs have superior sample generation quality compared to DDPMs, when we accelerate sampling by 10×10\times to 100×100\times using our proposed method. Second, DDIM samples have the following ``consistency'' property, which does not hold for DDPMs: if we start with the same initial latent variable and generate several samples with Markov chains of various lengths, these samples would have similar high-level features. Third, because of ``consistency'' in DDIMs, we can perform semantically meaningful image interpolation by manipulating the initial latent variable in DDIMs, unlike DDPMs which interpolates near the image space due to the stochastic generative process.

Background

Given samples from a data distribution q(x0)q({\bm{x}}_{0}), we are interested in learning a model distribution pθ(x0)p_{\theta}({\bm{x}}_{0}) that approximates q(x0)q({\bm{x}}_{0}) and is easy to sample from. Denoising diffusion probabilistic models (DDPMs, Sohl-Dickstein et al. (2015); Ho et al. (2020)) are latent variable models of the form

where x1,…,xT{\bm{x}}_{1},\ldots,{\bm{x}}_{T} are latent variables in the same sample space as x0{\bm{x}}_{0} (denoted as X{\mathcal{X}}). The parameters θ\theta are learned to fit the data distribution q(x0)q({\bm{x}}_{0}) by maximizing a variational lower bound:

where q(x1:T∣x0)q({\bm{x}}_{1:T}|{\bm{x}}_{0}) is some inference distribution over the latent variables. Unlike typical latent variable models (such as the variational autoencoder (Rezende et al., 2014)), DDPMs are learned with a fixed (rather than trainable) inference procedure q(x1:T∣x0)q({\bm{x}}_{1:T}|{\bm{x}}_{0}), and latent variables are relatively high dimensional. For example, Ho et al. (2020) considered the following Markov chain with Gaussian transitions parameterized by a decreasing sequence α1:T∈(0,1]T\alpha_{1:T}\in(0,1]^{T}:

where the covariance matrix is ensured to have positive terms on its diagonal. This is called the forward process due to the autoregressive nature of the sampling procedure (from x0{\bm{x}}_{0} to xT{\bm{x}}_{T}). We call the latent variable model pθ(x0:T)p_{\theta}({\bm{x}}_{0:T}), which is a Markov chain that samples from xT{\bm{x}}_{T} to x0{\bm{x}}_{0}, the generative process, since it approximates the intractable reverse process q(xt−1∣xt)q({\bm{x}}_{t-1}|{\bm{x}}_{t}). Intuitively, the forward process progressively adds noise to the observation x0{\bm{x}}_{0}, whereas the generative process progressively denoises a noisy observation (Figure 1, left).

A special property of the forward process is that

so we can express xt{\bm{x}}_{t} as a linear combination of x0{\bm{x}}_{0} and a noise variable ϵ\epsilon:

When we set αT\alpha_{T} sufficiently close to , q(xT∣x0)q({\bm{x}}_{T}|{\bm{x}}_{0}) converges to a standard Gaussian for all x0{\bm{x}}_{0}, so it is natural to set pθ(xT):=N(0,I)p_{\theta}({\bm{x}}_{T}):={\mathcal{N}}({\bm{0}},{\bm{I}}). If all the conditionals are modeled as Gaussians with trainable mean functions and fixed variances, the objective in Eq. (2) can be simplified toPlease refer to Appendix C.2 for details.:

where ϵθ:={ϵθ(t)}t=1T\epsilon_{\theta}:=\{\epsilon_{\theta}^{(t)}\}_{t=1}^{T} is a set of TT functions, each ϵθ(t):X→X\epsilon_{\theta}^{(t)}:{\mathcal{X}}\to{\mathcal{X}} (indexed by tt) is a function with trainable parameters θ(t)\theta^{(t)}, and γ:=[γ1,…,γT]\gamma:=[\gamma_{1},\ldots,\gamma_{T}] is a vector of positive coefficients in the objective that depends on α1:T\alpha_{1:T}. In Ho et al. (2020), the objective with γ=1\gamma={\bm{1}} is optimized instead to maximize generation performance of the trained model; this is also the same objective used in noise conditional score networks (Song & Ermon, 2019) based on score matching (Hyvärinen, 2005; Vincent, 2011). From a trained model, x0{\bm{x}}_{0} is sampled by first sampling xT{\bm{x}}_{T} from the prior pθ(xT)p_{\theta}({\bm{x}}_{T}), and then sampling xt−1{\bm{x}}_{t-1} from the generative processes iteratively.

The length TT of the forward process is an important hyperparameter in DDPMs. From a variational perspective, a large TT allows the reverse process to be close to a Gaussian (Sohl-Dickstein et al., 2015), so that the generative process modeled with Gaussian conditional distributions becomes a good approximation; this motivates the choice of large TT values, such as T=1000T=1000 in Ho et al. (2020). However, as all TT iterations have to be performed sequentially, instead of in parallel, to obtain a sample x0{\bm{x}}_{0}, sampling from DDPMs is much slower than sampling from other deep generative models, which makes them impractical for tasks where compute is limited and latency is critical.

Variational Inference for non-Markovian Forward Processes

Because the generative model approximates the reverse of the inference process, we need to rethink the inference process in order to reduce the number of iterations required by the generative model. Our key observation is that the DDPM objective in the form of LγL_{\gamma} only depends on the marginalsWe slightly abuse this term (as well as joints) when only conditioned on x0{\bm{x}}_{0}. q(xt∣x0)q({\bm{x}}_{t}|{\bm{x}}_{0}), but not directly on the joint q(x1:T∣x0)q({\bm{x}}_{1:T}|{\bm{x}}_{0}). Since there are many inference distributions (joints) with the same marginals, we explore alternative inference processes that are non-Markovian, which leads to new generative processes (Figure 1, right). These non-Markovian inference process lead to the same surrogate objective function as DDPM, as we will show below. In Appendix A, we show that the non-Markovian perspective also applies beyond the Gaussian case.

where qσ(xT∣x0)=N(αTx0,(1−αT)I)q_{\sigma}({\bm{x}}_{T}|{\bm{x}}_{0})={\mathcal{N}}(\sqrt{\alpha_{T}}{\bm{x}}_{0},(1-\alpha_{T}){\bm{I}}) and for all t>1t>1,

The mean function is chosen to order to ensure that qσ(xt∣x0)=N(αtx0,(1−αt)I)q_{\sigma}({\bm{x}}_{t}|{\bm{x}}_{0})={\mathcal{N}}(\sqrt{\alpha_{t}}{\bm{x}}_{0},(1-\alpha_{t}){\bm{I}}) for all tt (see Lemma 1 of Appendix B), so that it defines a joint inference distribution that matches the ``marginals'' as desired. The forward processWe overload the term “forward process” for cases where the inference model is not a diffusion. can be derived from Bayes' rule:

which is also Gaussian (although we do not use this fact for the remainder of this paper). Unlike the diffusion process in Eq. (3), the forward process here is no longer Markovian, since each xt{\bm{x}}_{t} could depend on both xt−1{\bm{x}}_{t-1} and x0{\bm{x}}_{0}. The magnitude of σ\sigma controls the how stochastic the forward process is; when σ→0\sigma\to{\bm{0}}, we reach an extreme case where as long as we observe x0{\bm{x}}_{0} and xt{\bm{x}}_{t} for some tt, then xt−1{\bm{x}}_{t-1} become known and fixed.

2 Generative process and unified variational inference objective

Next, we define a trainable generative process pθ(x0:T)p_{\theta}({\bm{x}}_{0:T}) where each pθ(t)(xt−1∣xt)p_{\theta}^{(t)}({\bm{x}}_{t-1}|{\bm{x}}_{t}) leverages knowledge of qσ(xt−1∣xt,x0)q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{t},{\bm{x}}_{0}). Intuitively, given a noisy observation xt{\bm{x}}_{t}, we first make a predictionLearning a distribution over the predictions is also possible, but empirically we found little benefits of it. of the corresponding x0{\bm{x}}_{0}, and then use it to obtain a sample xt−1{\bm{x}}_{t-1} through the reverse conditional distribution qσ(xt−1∣xt,x0)q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{t},{\bm{x}}_{0}), which we have defined.

For some x0∼q(x0){\bm{x}}_{0}\sim q({\bm{x}}_{0}) and ϵt∼N(0,I)\epsilon_{t}\sim{\mathcal{N}}({\bm{0}},{\bm{I}}), xt{\bm{x}}_{t} can be obtained using Eq. (4). The model ϵθ(t)(xt)\epsilon_{\theta}^{(t)}({\bm{x}}_{t}) then attempts to predict ϵt\epsilon_{t} from xt{\bm{x}}_{t}, without knowledge of x0{\bm{x}}_{0}. By rewriting Eq. (4), one can then predict the denoised observation, which is a prediction of x0{\bm{x}}_{0} given xt{\bm{x}}_{t}:

We can then define the generative process with a fixed prior pθ(xT)=N(0,I)p_{\theta}({\bm{x}}_{T})={\mathcal{N}}({\bm{0}},{\bm{I}}) and

where qσ(xt−1∣xt,fθ(t)(xt))q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{t},f_{\theta}^{(t)}({\bm{x}}_{t})) is defined as in Eq. (7) with x0{\bm{x}}_{0} replaced by fθ(t)(xt)f_{\theta}^{(t)}({\bm{x}}_{t}). We add some Gaussian noise (with covariance σ12I\sigma_{1}^{2}{\bm{I}}) for the case of t=1t=1 to ensure that the generative process is supported everywhere.

We optimize θ\theta via the following variational inference objective (which is a functional over ϵθ\epsilon_{\theta}):

where we factorize qσ(x1:T∣x0)q_{\sigma}({\bm{x}}_{1:T}|{\bm{x}}_{0}) according to Eq. (6) and pθ(x0:T)p_{\theta}({\bm{x}}_{0:T}) according to Eq. (1).

From the definition of JσJ_{\sigma}, it would appear that a different model has to be trained for every choice of σ\sigma, since it corresponds to a different variational objective (and a different generative process). However, JσJ_{\sigma} is equivalent to LγL_{\gamma} for certain weights γ\gamma, as we show below.

The variational objective LγL_{\gamma} is special in the sense that if parameters θ\theta of the models ϵθ(t)\epsilon_{\theta}^{(t)} are not shared across different tt, then the optimal solution for ϵθ\epsilon_{\theta} will not depend on the weights γ\gamma (as global optimum is achieved by separately maximizing each term in the sum). This property of LγL_{\gamma} has two implications. On the one hand, this justified the use of L1L_{\bm{1}} as a surrogate objective function for the variational lower bound in DDPMs; on the other hand, since JσJ_{\sigma} is equivalent to some LγL_{\gamma} from Theorem 1, the optimal solution of JσJ_{\sigma} is also the same as that of L1L_{\bm{1}}. Therefore, if parameters are not shared across tt in the model ϵθ\epsilon_{\theta}, then the L1L_{\bm{1}} objective used by Ho et al. (2020) can be used as a surrogate objective for the variational objective JσJ_{\sigma} as well.

Sampling from Generalized Generative Processes

With L1L_{\bm{1}} as the objective, we are not only learning a generative process for the Markovian inference process considered in Sohl-Dickstein et al. (2015) and Ho et al. (2020), but also generative processes for many non-Markovian forward processes parametrized by σ\sigma that we have described. Therefore, we can essentially use pretrained DDPM models as the solutions to the new objectives, and focus on finding a generative process that is better at producing samples subject to our needs by changing σ\sigma.

From pθ(x1:T)p_{\theta}({\bm{x}}_{1:T}) in Eq. (10), one can generate a sample xt−1{\bm{x}}_{t-1} from a sample xt{\bm{x}}_{t} via:

where ϵt∼N(0,I)\epsilon_{t}\sim{\mathcal{N}}({\bm{0}},{\bm{I}}) is standard Gaussian noise independent of xt{\bm{x}}_{t}, and we define α0:=1\alpha_{0}:=1. Different choices of σ\sigma values results in different generative processes, all while using the same model ϵθ\epsilon_{\theta}, so re-training the model is unnecessary. When σt=(1−αt−1)/(1−αt)1−αt/αt−1\sigma_{t}=\sqrt{(1-\alpha_{t-1})/(1-\alpha_{t})}\sqrt{1-\alpha_{t}/\alpha_{t-1}} for all tt, the forward process becomes Markovian, and the generative process becomes a DDPM.

We note another special case when σt=0\sigma_{t}=0 for all ttAlthough this case is not covered in Theorem 1, we can always approximate it by making σt\sigma_{t} very small.; the forward process becomes deterministic given xt−1{\bm{x}}_{t-1} and x0{\bm{x}}_{0}, except for t=1t=1; in the generative process, the coefficient before the random noise ϵt\epsilon_{t} becomes zero. The resulting model becomes an implicit probabilistic model (Mohamed & Lakshminarayanan, 2016), where samples are generated from latent variables with a fixed procedure (from xT{\bm{x}}_{T} to x0{\bm{x}}_{0}). We name this the denoising diffusion implicit model (DDIM, pronounced /d:Im/), because it is an implicit probabilistic model trained with the DDPM objective (despite the forward process no longer being a diffusion).

2 Accelerated generation processes

In the previous sections, the generative process is considered as the approximation to the reverse process; since of the forward process has TT steps, the generative process is also forced to sample TT steps. However, as the denoising objective L1L_{\bm{1}} does not depend on the specific forward procedure as long as qσ(xt∣x0)q_{\sigma}({\bm{x}}_{t}|{\bm{x}}_{0}) is fixed, we may also consider forward processes with lengths smaller than TT, which accelerates the corresponding generative processes without having to train a different model.

Let us consider the forward process as defined not on all the latent variables x1:T{\bm{x}}_{1:T}, but on a subset {xτ1,…,xτS}\{{\bm{x}}_{\tau_{1}},\ldots,{\bm{x}}_{\tau_{S}}\}, where τ\tau is an increasing sub-sequence of [1,…,T][1,\ldots,T] of length SS. In particular, we define the sequential forward process over xτ1,…,xτS{\bm{x}}_{\tau_{1}},\ldots,{\bm{x}}_{\tau_{S}} such that q(xτi∣x0)=N(ατix0,(1−ατi)I)q({\bm{x}}_{\tau_{i}}|{\bm{x}}_{0})={\mathcal{N}}(\sqrt{\alpha_{\tau_{i}}}{\bm{x}}_{0},(1-\alpha_{\tau_{i}}){\bm{I}}) matches the ``marginals'' (see Figure 2 for an illustration). The generative process now samples latent variables according to reversed(τ)\text{reversed}(\tau), which we term (sampling) trajectory. When the length of the sampling trajectory is much smaller than TT, we may achieve significant increases in computational efficiency due to the iterative nature of the sampling process.

Using a similar argument as in Section 3, we can justify using the model trained with the L1L_{\bm{1}} objective, so no changes are needed in training. We show that only slight changes to the updates in Eq. (12) are needed to obtain the new, faster generative processes, which applies to DDPM, DDIM, as well as all generative processes considered in Eq. (10). We include these details in Appendix C.1.

In principle, this means that we can train a model with an arbitrary number of forward steps but only sample from some of them in the generative process. Therefore, the trained model could consider many more steps than what is considered in (Ho et al., 2020) or even a continuous time variable tt (Chen et al., 2020). We leave empirical investigations of this aspect as future work.

3 Relevance to Neural ODEs

Moreover, we can rewrite the DDIM iterate according to Eq. (12), and its similarity to Euler integration for solving ordinary differential equations (ODEs) becomes more apparent:

where the initial conditions is x(T)∼N(0,σ(T)){\bm{x}}(T)\sim{\mathcal{N}}(0,\sigma(T)) for a very large σ(T)\sigma(T) (which corresponds to the case of α≈0\alpha\approx 0). This suggests that with enough discretization steps, the we can also reverse the generation process (going from t=0t=0 to TT), which encodes x0{\bm{x}}_{0} to xT{\bm{x}}_{T} and simulates the reverse of the ODE in Eq. (14). This suggests that unlike DDPM, we can use DDIM to obtain encodings of the observations (as the form of xT{\bm{x}}_{T}), which might be useful for other downstream applications that requires latent representations of a model.

In a concurrent work, (Song et al., 2020) proposed a ``probability flow ODE'' that aims to recover the marginal densities of a stochastic differential equation (SDE) based on scores, from which a similar sampling schedule can be obtained. Here, we state that the our ODE is equivalent to a special case of theirs (which corresponds to a continuous-time analog of DDPM).

The ODE in Eq. (14) with the optimal model ϵθ(t)\epsilon_{\theta}^{(t)} has an equivalent probability flow ODE corresponding to the ``Variance-Exploding'' SDE in Song et al. (2020).

We include the proof in Appendix B. While the ODEs are equivalent, the sampling procedures are not, since the Euler method for the probability flow ODE will make the following update:

Experiments

In this section, we show that DDIMs outperform DDPMs in terms of image generation when fewer iterations are considered, giving speed ups of 10×10\times to 100×100\times over the original DDPM generation process. Moreover, unlike DDPMs, once the initial latent variables xT{\bm{x}}_{T} are fixed, DDIMs retain high-level image features regardless of the generation trajectory, so they are able to perform interpolation directly from the latent space. DDIMs can also be used to encode samples that reconstruct them from the latent code, which DDPMs cannot do due to the stochastic sampling process.

For each dataset, we use the same trained model with T=1000T=1000 and the objective being LγL_{\gamma} from Eq. (5) with γ=1\gamma={\bm{1}}; as we argued in Section 3, no changes are needed with regards to the training procedure. The only changes that we make is how we produce samples from the model; we achieve this by controlling τ\tau (which controls how fast the samples are obtained) and σ\sigma (which interpolates between the deterministic DDIM and the stochastic DDPM).

We consider different sub-sequences τ\tau of [1,…,T][1,\ldots,T] and different variance hyperparameters σ\sigma indexed by elements of τ\tau. To simplify comparisons, we consider σ\sigma with the form:

In Table 1, we report the quality of the generated samples with models trained on CIFAR10 and CelebA, as measured by Frechet Inception Distance (FID (Heusel et al., 2017)), where we vary the number of timesteps used to generate a sample (dim⁡(τ)\dim(\tau)) and the stochasticity of the process (η\eta). As expected, the sample quality becomes higher as we increase dim⁡(τ)\dim(\tau), presenting a trade-off between sample quality and computational costs. We observe that DDIM (η=0\eta=0) achieves the best sample quality when dim⁡(τ)\dim(\tau) is small, and DDPM (η=1\eta=1 and σ^\hat{\sigma}) typically has worse sample quality compared to its less stochastic counterparts with the same dim⁡(τ)\dim(\tau), except for the case for dim⁡(τ)=1000\dim(\tau)=1000 and σ^\hat{\sigma} reported by Ho et al. (2020) where DDIM is marginally worse. However, the sample quality of σ^\hat{\sigma} becomes much worse for smaller dim⁡(τ)\dim(\tau), which suggests that it is ill-suited for shorter trajectories. DDIM, on the other hand, achieves high sample quality much more consistently.

In Figure 3, we show CIFAR10 and CelebA samples with the same number of sampling steps and varying σ\sigma. For the DDPM, the sample quality deteriorates rapidly when the sampling trajectory has 10 steps. For the case of σ^\hat{\sigma}, the generated images seem to have more noisy perturbations under short trajectories; this explains why the FID scores are much worse than other methods, as FID is very sensitive to such perturbations (as discussed in Jolicoeur-Martineau et al. (2020)).

In Figure 4, we show that the amount of time needed to produce a sample scales linearly with the length of the sample trajectory. This suggests that DDIM is useful for producing samples more efficiently, as samples can be generated in much fewer steps. Notably, DDIM is able to produce samples with quality comparable to 1000 step models within 2020 to 100100 steps, which is a 10×10\times to 50×50\times speed up compared to the original DDPM. Even though DDPM could also achieve reasonable sample quality with 100×100\times steps, DDIM requires much fewer steps to achieve this; on CelebA, the FID score of the 100 step DDPM is similar to that of the 20 step DDIM.

2 Sample consistency in DDIMs

For DDIM, the generative process is deterministic, and x0{\bm{x}}_{0} would depend only on the initial state xT{\bm{x}}_{T}. In Figure 5, we observe the generated images under different generative trajectories (i.e. different τ\tau) while starting with the same initial xT{\bm{x}}_{T}. Interestingly, for the generated images with the same initial xT{\bm{x}}_{T}, most high-level features are similar, regardless of the generative trajectory. In many cases, samples generated with only 20 steps are already very similar to ones generated with 1000 steps in terms of high-level features, with only minor differences in details. Therefore, it would appear that xT{\bm{x}}_{T} alone would be an informative latent encoding of the image; and minor details that affects sample quality are encoded in the parameters, as longer sample trajectories gives better quality samples but do not significantly affect the high-level features. We show more samples in Appendix D.4.

3 Interpolation in deterministic generative processes

Since the high level features of the DDIM sample is encoded by xT{\bm{x}}_{T}, we are interested to see whether it would exhibit the semantic interpolation effect similar to that observed in other implicit probabilistic models, such as GANs (Goodfellow et al., 2014). This is different from the interpolation procedure in Ho et al. (2020), since in DDPM the same xT{\bm{x}}_{T} would lead to highly diverse x0{\bm{x}}_{0} due to the stochastic generative processAlthough it might be possible if one interpolates all TT noises, like what is done in Song & Ermon (2020).. In Figure 6, we show that simple interpolations in xT{\bm{x}}_{T} can lead to semantically meaningful interpolations between two samples. We include more details and samples in Appendix D.5. This allows DDIM to control the generated images on a high level directly through the latent variables, which DDPMs cannot.

4 Reconstruction from Latent Space

As DDIM is the Euler integration for a particular ODE, it would be interesting to see whether it can encode from x0{\bm{x}}_{0} to xT{\bm{x}}_{T} (reverse of Eq. (14)) and reconstruct x0{\bm{x}}_{0} from the resulting xT{\bm{x}}_{T} (forward of Eq. (14))Since xT{\bm{x}}_{T} and x0{\bm{x}}_{0} have the same dimensions, their compression qualities are not our immediate concern.. We consider encoding and decoding on the CIFAR-10 test set with the CIFAR-10 model with SS steps for both encoding and decoding; we report the per-dimension mean squared error (scaled to $)inTable2.OurresultsshowthatDDIMshavelowerreconstructionerrorforlarger) in Table 2. Our results show that DDIMs have lower reconstruction error for largerS$ values and have properties similar to Neural ODEs and normalizing flows. The same cannot be said for DDPMs due to their stochastic nature.

Related Work

Our work is based on a large family of existing methods on learning generative models as transition operators of Markov chains (Sohl-Dickstein et al., 2015; Bengio et al., 2014; Salimans et al., 2014; Song et al., 2017; Goyal et al., 2017; Levy et al., 2017). Among them, denoising diffusion probabilistic models (DDPMs, Ho et al. (2020)) and noise conditional score networks (NCSN, Song & Ermon (2019; 2020)) have recently achieved high sample quality comparable to GANs (Brock et al., 2018; Karras et al., 2018). DDPMs optimize a variational lower bound to the log-likelihood, whereas NCSNs optimize the score matching objective (Hyvärinen, 2005) over a nonparametric Parzen density estimator of the data (Vincent, 2011; Raphan & Simoncelli, 2011).

Despite their different motivations, DDPMs and NCSNs are closely related. Both use a denoising autoencoder objective for many noise levels, and both use a procedure similar to Langevin dynamics to produce samples (Neal et al., 2011). Since Langevin dynamics is a discretization of a gradient flow (Jordan et al., 1998), both DDPM and NCSN require many steps to achieve good sample quality. This aligns with the observation that DDPM and existing NCSN methods have trouble generating high-quality samples in a few iterations.

DDIM, on the other hand, is an implicit generative model (Mohamed & Lakshminarayanan, 2016) where samples are uniquely determined from the latent variables. Hence, DDIM has certain properties that resemble GANs (Goodfellow et al., 2014) and invertible flows (Dinh et al., 2016), such as the ability to produce semantically meaningful interpolations. We derive DDIM from a purely variational perspective, where the restrictions of Langevin dynamics are not relevant; this could partially explain why we are able to observe superior sample quality compared to DDPM under fewer iterations. The sampling procedure of DDIM is also reminiscent of neural networks with continuous depth (Chen et al., 2018; Grathwohl et al., 2018), since the samples it produces from the same latent variable have similar high-level visual features, regardless of the specific sample trajectory.

Discussion

We have presented DDIMs – an implicit generative model trained with denoising auto-encoding / score matching objectives – from a purely variational perspective. DDIM is able to generate high-quality samples much more efficiently than existing DDPMs and NCSNs, with the ability to perform meaningful interpolations from the latent space. The non-Markovian forward process presented here seems to suggest continuous forward processes other than Gaussian (which cannot be done in the original diffusion framework, since Gaussian is the only stable distribution with finite variance). We also demonstrated a discrete case with a multinomial forward process in Appendix A, and it would be interesting to investigate similar alternatives for other combinatorial structures.

Moreover, since the sampling procedure of DDIMs is similar to that of an neural ODE, it would be interesting to see if methods that decrease the discretization error in ODEs, including multi-step methods such as Adams-Bashforth (Butcher & Goodwin, 2008), could be helpful for further improving sample quality in fewer steps (Queiruga et al., 2020). It is also relevant to investigate whether DDIMs exhibit other properties of existing implicit models (Bau et al., 2019).

Acknowledgements

The authors would like to thank Yang Song and Shengjia Zhao for helpful discussions over the ideas, Kuno Kim for reviewing an earlier draft of the paper, and Sharvil Nanavati and Sophie Liu for identifying typos. This research was supported by NSF (#1651565, #1522054, #1733686), ONR (N00014-19-1-2145), AFOSR (FA9550-19-1-0024), and Amazon AWS.

References

Appendix A Non-Markovian Forward Processes for a Discrete Case

In this section, we describe a non-Markovian forward processes for discrete data and corresponding variational objectives. Since the focus of this paper is to accelerate reverse models corresponding to the Gaussian diffusion, we leave empirical evaluations as future work.

For a categorical observation x0{\bm{x}}_{0} that is a one-hot vector with KK possible values, we define the forward process as follows. First, we have q(xt∣x0)q({\bm{x}}_{t}|{\bm{x}}_{0}) as the following categorical distribution:

which is consistent with how we have defined q(xt∣x0)q({\bm{x}}_{t}|{\bm{x}}_{0}).

Similarly, we can define our reverse process pθ(xt−1∣xt)p_{\theta}({\bm{x}}_{t-1}|{\bm{x}}_{t}) as:

where fθ(t)(xt)f_{\theta}^{(t)}({\bm{x}}_{t}) maps xt{\bm{x}}_{t} to a KK-dimensional vector. As (1−αt−1)−(1−αt)σt→0(1-\alpha_{t-1})-(1-\alpha_{t})\sigma_{t}\to 0, the sampling process will become less stochastic, in the sense that it will either choose xt{\bm{x}}_{t} or the predicted x0{\bm{x}}_{0} with high probability. The KL divergence

is well-defined, and is simply the KL divergence between two categoricals. Therefore, the resulting variational objective function should be easy to optimize as well. Moreover, as KL divergence is convex, we have this upper bound (which is tight when the right hand side goes to zero):

The right hand side is simply a multi-class classification loss (up to constants), so we can arrive at similar arguments regarding how changes in σt\sigma_{t} do not affect the objective (up to re-weighting).

Appendix B Proofs

For qσ(x1:T∣x0)q_{\sigma}({\bm{x}}_{1:T}|{\bm{x}}_{0}) defined in Eq. (6) and qσ(xt−1∣xt,x0)q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{t},{\bm{x}}_{0}) defined in Eq. (7), we have:

Assume for any t≤Tt\leq T, qσ(xt∣x0)=N(αtx0,(1−αt)I)q_{\sigma}({\bm{x}}_{t}|{\bm{x}}_{0})={\mathcal{N}}(\sqrt{\alpha_{t}}{\bm{x}}_{0},(1-\alpha_{t}){\bm{I}}) holds, if:

then we can prove the statement with an induction argument for tt from TT to 11, since the base case (t=Tt=T) already holds.

From Bishop (2006) (2.115), we have that qσ(xt−1∣x0)q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{0}) is Gaussian, denoted as N(μt−1,Σt−1){\mathcal{N}}(\mu_{t-1},\Sigma_{t-1}) where

Therefore, qσ(xt−1∣x0)=N(αt−1x0,(1−αt−1)I)q_{\sigma}({\bm{x}}_{t-1}|{\bm{x}}_{0})={\mathcal{N}}(\sqrt{\alpha_{t-1}}{\bm{x}}_{0},(1-\alpha_{t-1}){\bm{I}}), which allows us to apply the induction argument. ∎

where we use ≡\equiv to denote ``equal up to a value that does not depend on ϵθ\epsilon_{\theta} (but may depend on qσq_{\sigma})''. For t>1t>1:

where dd is the dimension of x0{\bm{x}}_{0}. For t=1t=1:

Therefore, when γt=1/(2dσt2αt)\gamma_{t}=1/(2d\sigma_{t}^{2}\alpha_{t}) for all t∈{1,…,T}t\in\{1,\ldots,T\}, we have

for all ϵθ\epsilon_{\theta}. From the definition of ``≡\equiv'', we have that Jσ=Lγ+CJ_{\sigma}=L_{\gamma}+C. ∎

In the context of the proof, we consider tt as a continous, independent ``time'' variable and x{\bm{x}} and α\alpha as functions of tt. First, let us consider a reparametrization between DDIM and the VE-SDERefer to (Song et al., 2020) for more details of VE-SDE. by introducing the variables xˉ\bar{{\bm{x}}} and σ\sigma:

We can then define α(t)\alpha(t) and x(t){\bm{x}}(t) corresponding to DDIM case as:

which establishes an bijection between (x,α)({\bm{x}},\alpha) and (xˉ,σ)(\bar{{\bm{x}}},\sigma). From Equation (4) we have (note that α(0)=1\alpha(0)=1):

which can be reparametrized into a form that is consistent with VE-SDE:

Now, we derive the ODE forms for both DDIM and VE-SDE and show that they are equivalent.

Divide both sides by (−Δt)(-\Delta t) and as Δt→0\Delta t\to 0, we have:

which is exactly what we have in Equation (14).

We note that for the optimal model, ϵθ(t)\epsilon_{\theta}^{(t)} is a minimizer:

where x(t)=α(t)x(t)+1−α(t)ϵ{\bm{x}}(t)=\sqrt{\alpha(t)}{\bm{x}}(t)+\sqrt{1-\alpha(t)}\epsilon.

ODE form for VE-SDE

Define pt(xˉ)p_{t}(\bar{{\bm{x}}}) as the data distribution perturbed with σ2(t)\sigma^{2}(t) variance Gaussian noise. The probability flow for VE-SDE is defined as Song et al. (2020):

The σ(t)\sigma(t)-perturbed score function ∇xˉlog⁡pt(xˉ)\nabla_{\bar{{\bm{x}}}}\log p_{t}(\bar{{\bm{x}}}) is also a minimizer (from denoising score matching (Vincent, 2011)):

where xˉ(t)=xˉ(t)+σ(t)ϵ\bar{{\bm{x}}}(t)=\bar{{\bm{x}}}(t)+\sigma(t)\epsilon.

Since there is an equivalence between x(t){\bm{x}}(t) and xˉ(t)\bar{{\bm{x}}}(t), we have the following relationship:

from Equation (46) and Equation (48). Plug Equation (49) and definition of g(t)g(t) in Equation (47), we have:

and we have the following by rearranging terms:

which is equivalent to Equation (45). In both cases the initial conditions are xˉ(T)∼N(0,σ2(T)I)\bar{{\bm{x}}}(T)\sim{\mathcal{N}}({\bm{0}},\sigma^{2}(T){\bm{I}}), so the resulting ODEs are identical. ∎

Appendix C Additional Derivations

In the accelerated case, we can consider the inference process to be factored as:

where τ\tau is a sub-sequence of [1,…,T][1,\ldots,T] of length SS with τS=T\tau_{S}=T, and let τˉ:={1,…,T}∖τ\bar{\tau}:=\{1,\ldots,T\}\setminus\tau be its complement. Intuitively, the graphical model of {xτi}i=1S\{{\bm{x}}_{\tau_{i}}\}_{i=1}^{S} and x0{\bm{x}}_{0} form a chain, whereas the graphical model of {xt}t∈τˉ\{{\bm{x}}_{t}\}_{t\in\bar{\tau}} and x0{\bm{x}}_{0} forms a star graph. We define:

where the coefficients are chosen such that:

The corresponding ``generative process'' is defined as:

where only part of the models are actually being used to produce samples. The conditionals are:

where we leverage qσ,τ(xτi−1∣xτi,x0)q_{\sigma,\tau}({\bm{x}}_{\tau_{i-1}}|{\bm{x}}_{\tau_{i}},{\bm{x}}_{0}) as part of the inference process (similar to what we have done in Section 3). The resulting variational objective becomes (define xτL+1=∅{\bm{x}}_{\tau_{L+1}}=\varnothing for conciseness):

where each KL divergence is between two Gaussians with variance independent of θ\theta. A similar argument to the proof used in Theorem 1 can show that the variational objective JJ can also be converted to an objective of the form LγL_{\gamma}.

C.2 Derivation of denoising objectives for DDPMs

We note that in Ho et al. (2020), a diffusion hyperparameter βt\beta_{t}In this section we use teal to color notations used in Ho et al. (2020). is first introduced, and then relevant variables αt:=1−βt\alpha_{t}:=1-\beta_{t} and αˉt=∏t=1Tαt\bar{\alpha}_{t}=\prod_{t=1}^{T}\alpha_{t} are defined. In this paper, we have used the notation αt\alpha_{t} to represent the variable αˉt\bar{\alpha}_{t} in Ho et al. (2020) for three reasons. First, it makes it more clear that we only need to choose one set of hyperparameters, reducing possible cross-references of the derived variables. Second, it allows us to introduce the generalization as well as the acceleration case easier, because the inference process is no longer motivated by a diffusion. Third, there exists an isomorphism between α1:T\alpha_{1:T} and 1,…,T1,\ldots,T, which is not the case for βt\beta_{t}.

In this section, we use βt\beta_{t} and αt\alpha_{t} to be more consistent with the derivation in Ho et al. (2020), where

can be uniquely determined from αt\alpha_{t} (i.e. αˉt\bar{\alpha}_{t}).

First, from the diffusion forward process:

Ho et al. (2020) considered a specific type of pθ(t)(xt−1∣xt)p_{\theta}^{(t)}({\bm{x}}_{t-1}|{\bm{x}}_{t}):

which leads to the following variational objective:

Ho et al. (2020) chose the parametrization

Appendix D Experimental Details

We consider 4 image datasets with various resolutions: CIFAR10 (32×3232\times 32, unconditional), CelebA (64×6464\times 64), LSUN Bedroom (256×256256\times 256) and LSUN Church (256×256256\times 256). For all datasets, we set the hyperparameters α\alpha according to the heuristic in (Ho et al., 2020) to make the results directly comparable. We use the same model for each dataset, and only compare the performance of different generative processes. For CIFAR10, Bedroom and Church, we obtain the pretrained checkpoints from the original DDPM implementation; for CelebA, we trained our own model using the denoising objective L1L_{\bm{1}}.

Our architecture for ϵθ(t)(xt)\epsilon_{\theta}^{(t)}({\bm{x}}_{t}) follows that in Ho et al. (2020), which is a U-Net (Ronneberger et al., 2015) based on a Wide ResNet (Zagoruyko & Komodakis, 2016). We use the pretrained models from Ho et al. (2020) for CIFAR10, Bedroom and Church, and train our own model for the CelebA 64×6464\times 64 model (since a pretrained model is not provided). Our CelebA model has five feature map resolutions from 64×6464\times 64 to 4×44\times 4, and we use the original CelebA dataset (not CelebA-HQ) using the pre-processing technique from the StyleGAN (Karras et al., 2018) repository.

D.2 Reverse process sub-sequence selection

We consider two types of selection procedure for τ\tau given the desired dim⁡(τ)<T\dim(\tau)<T:

Linear: we select the timesteps such that τi=⌊ci⌋\tau_{i}=\lfloor ci\rfloor for some cc;

Quadratic: we select the timesteps such that τi=⌊ci2⌋\tau_{i}=\lfloor ci^{2}\rfloor for some cc.

The constant value cc is selected such that τ−1\tau_{-1} is close to TT. We used quadratic for CIFAR10 and linear for the remaining datasets. These choices achieve slightly better FID than their alternatives in the respective datasets.

D.3 Closed form equations for each sampling step

From the general sampling equation in Eq. (12), we have the following update equation:

For the case of σ^\hat{\sigma} (DDPM with a larger variance), the update equation becomes:

which uses a different coefficient for ϵ\epsilon compared with the update for η=1\eta=1, but uses the same coefficient for the non-stochastic parts. This update is more stochastic than the update for η=1\eta=1, which explains why it achieves worse performance when dim⁡(τ)\dim(\tau) is small.

D.4 Samples and Consistency

We show more samples in Figure 7 (CIFAR10), Figure 8 (CelebA), Figure 10 (Church) and consistency results of DDIM in Figure 9 (CelebA).

D.5 Interpolation

To generate interpolations on a line, we randomly sample two initial xT{\bm{x}}_{T} values from the standard Gaussian, interpolate them with spherical linear interpolation (Shoemake, 1985), and then use the DDIM to obtain x0{\bm{x}}_{0} samples.

where θ=arccos⁡((xT(0))⊤xT(1)∥xT(0)∥∥xT(1)∥)\theta=\arccos\left(\frac{({\bm{x}}_{T}^{(0)})^{\top}{\bm{x}}_{T}^{(1)}}{{\lVert{{\bm{x}}_{T}^{(0)}}\rVert}{\lVert{{\bm{x}}_{T}^{(1)}}\rVert}}\right). These values are used to produce DDIM samples.

To generate interpolations on a grid, we sample four latent variables and separate them in to two pairs; then we use slerp with the pairs under the same α\alpha, and use slerp over the interpolated samples across the pairs (under an independently chosen interpolation coefficient). We show more grid interpolation results in Figure 11 (CelebA), Figure 12 (Bedroom), and Figure 13 (Church).