In the previous post, Multimodal Generation - Part 1, 3 sub-challenges in Multimodal Generation, namely, summation, translation, and creation, were introduced, representative works for each sub-challenge were explored and analyzed, and several important open challenges that remain unsolved were discussed.
Inside the Translation section, DALL·E was introduced as a canonical work and explained at a high level. The model adopts a discrete Variational Auto-Encoder (VAE) to encode an input image into a grid of image tokens. These image tokens are then concatenated with the text tokens of the matching caption and processed together by an autoregressive Transformer decoder.
Its successor, DALL·E 2, replaces the discrete VAE used in DALL·E with Diffusion Models, enabling high-quality image generation.
The core generative building blocks behind DALL·E and DALL·E2 are the VAE and Diffusion Model, respectively. VAE represents an important development in generative modeling by connecting deep neural networks with probabilistic latent-variable modeling. Diffusion Model introduces a different approach to generation by learning a denoising process, enabling high-quality image generation.
This post examines the math and core ideas behind Variational Auto-Encoder (VAE) and Diffusion Model (DM), starting from simple latent variable models, Gaussian Mixture Model, the Reparameterization Trick, and gradually building up to the two dominant generative models that underpin many generation systems today. Finally, this post concludes with a brief comparison of autoregressive models, VAEs, and diffusion models.
*Warning: There will be heavy probability theory and math ahead, but we're in this together, and I promise to do my best to explain every single term in detail. Also, this took me forever to write, so it might take you a while to get through it too. Please grab a snack before you dive in :)*
Images can vary along many dimensions, such as gender, eye color, hair color, pose, and so on. However, unless images are annotated, these factors of variation are not explicitly available. They are therefore treated as latent variables.
The core idea of a latent variable model is to introduce hidden variables $\mathbf{z}$ to represent these unobserved factors and explicitly formulate the generative process as $\mathbf{z} \rightarrow \mathbf{x}$, where only $\mathbf{x}$ (e.g., an image) are observed in the data, while $\mathbf{z}$ must be inferred.
Hand-coding what each dimension of $\mathbf{z}$ should represent is generally impractical since these underlying factors are never observed. Therefore, the goal is to learn the latent representation from observed data.
To model the unobserved latent variables underlying the observed data, latent variable models typically assume a prior distribution over the latent variables $p(\mathbf{z})$ and a conditional distribution $p(\mathbf{x}\mid \mathbf{z})$ that represents the generative process $\mathbf{z}\to \mathbf{x}$, and we wish to learn the parameters in these probability densities.The motivation is that $\mathbf{z}$ corresponds to meaningful factors of variation in the data, and using Bayes' theorem, the posterior distribution can be expressed as: $$ \begin{align*}\text{posterior} &= \frac{\text{likelihood}\times\text{prior}}{\text{evidence}} \\ p(\mathbf{z}\mid\mathbf{x}) &= \frac{p(\mathbf{x}\mid\mathbf{z}) p(\mathbf{z})}{p(\mathbf{x})} \end{align*}$$ Since $p(\mathbf{z}\mid \mathbf{x}) \propto p(\mathbf{x} \mid \mathbf{z})p(\mathbf{z})$, given an image $\mathbf{x}$, its underlying latent factors can be inferred through this relationship. Conversely, given sampled $\mathbf{z}$, a new image $\mathbf{x}$ can be generated via $p(\mathbf{x}\mid\mathbf{z})$, if the latent representation is interpretable.
One of the simplest examples of latent variable models is the Gaussian Mixture Model (GMM). A GMM models the observed data as being sampled from a mixture of several components, where each component is a Gaussian distribution.
Take, for example, the univariate case: let $z$ be a discrete latent variable indicating which Gaussian component the observation $x$ was assumed to be sampled from. Then, the generative process for the observed data can be expressed as follows:
$$\begin{align*}
z &\sim \text{Categorical}(1, \dots, K) \\ x \mid z = k &\sim \mathcal{N}(\mu_k, \sigma_k^2)
\end{align*}$$
where $K$ is the number of Gaussian components.
Notice that the conditional distribution $p(x\mid z)$ is a function of $z$ because the parameters, mean and variance, depend on the value of $z$.
By marginalizing out $z$ , the probability density function (PDF) of the observed variable $x$ can be computed:
$$
p(x) = \sum_{z} p(x, z) = \sum_{z} p(z)\, p(x \mid z) = \sum_{k=1}^{K} p(z = k)\, \mathcal{N}(x; \mu_k, \sigma_k^2)
$$
where $p(z)$, $\mu_k$, and $\sigma_k$ are parameters of the model.
Therefore, a GMM is a density estimator that can approximate any probability distribution with a sufficiently large number of Gaussian components.
Note that $x$ is observed in the data, while $z$ is the latent variable that is unobserved.
To estimate these parameters given the observed samples $x_1, \dots, x_N$, Expectation-Maximization (EM) can be used as follows:
1. Initialize parameters: $p(z=k)$, $\mu_k$, and $\sigma_k$ for $k=1,\dots,K$
2. Iterate until convergence:
Readers who are interested in the details of the derivation of Expectation-Maximization (EM) for GMM can refer to: Grosse, R., & Srivastava, N. (2015). Lecture 16: Mixture models. CSC321 Winter 2015: Introduction to Neural Networks.
A GMM's conditional distribution $p(\mathbf{x} \mid \mathbf{z})$ can be viewed as a lookup table of $K$ fixed Gaussian distributions. The key steps that lead from a GMM to the VAE are to keep the same generative process $\mathbf{z} \rightarrow \mathbf{x}$ but with the following differences:
Formally, the prior and the conditional distribution of the observed data in VAE are:
$$\begin{align*}p(\mathbf{z}) &= \mathcal{N}(\mathbf{0}, \mathbf{I}) \\ p(\mathbf{x} \mid \mathbf{z}) &= \mathcal{N}\big(\mu_\theta(\mathbf{z}), \Sigma_\theta(\mathbf{z})\big)\end{align*}$$
where $\mu_\theta$ and $\Sigma_\theta$ are neural networks, and $\Sigma_\theta(\mathbf{z})$ is a diagonal covariance matrix.
Even though the conditional distribution $p(\mathbf{x} \mid \mathbf{z})$ is still a Gaussian distribution, the VAE lets $\mathbf{z}$ be continuous random variables so that the marginal distribution $p(\mathbf{x})$ becomes an infinite mixture of Gaussians and passes $\mathbf{z}$ through neural networks so that the mean and variances can vary nonlinearly with $\mathbf{z}$.
Consider a dataset $\mathcal{D}=\{\mathbf{x}^{(i)}\}_{i=1}^{N}$ consisting of $N$ i.i.d. (independent and identically-distributed) samples of a vector of observed variables $\mathbf{x}$, and assume that the data are generated by some random process that involves unobserved continuous random variables $\mathbf{z}$, such that $\mathbf{z}\to \mathbf{x}$. Specifically, this process consists of a prior distribution $p(\mathbf{z})$ and a conditional distribution $p(\mathbf{x}\mid \mathbf{z};\theta)$, such that their joint distribution is: $$p(\mathbf{x},\mathbf{z};\theta) = p(\mathbf{z})p(\mathbf{x}\mid \mathbf{z};\theta)$$ Given the observed samples in $\mathcal{D}$, a natural approach to learning the parameters $\theta$ is through maximum likelihood estimation (MLE), where the marginal log-likelihood of the observed data is: $$ \begin{align*}\log \prod_{\mathbf{x} \in \mathcal{D}} p(\mathbf{x}; \theta) = \sum_{i=1}^{N} \log p(\mathbf{x}^{(i)}; \theta) = \sum_{i=1}^{N} \log \int_{\mathbf{z}} p(\mathbf{x}^{(i)}, \mathbf{z}; \theta)d\mathbf{z} = \sum_{i=1}^{N} \log \int_{\mathbf{z}} p(\mathbf{z})p(\mathbf{x}^{(i)}\mid \mathbf{z};\theta)d\mathbf{z}\end{align*} $$ The trouble is that the inner integral over $\mathbf{z}$ is generally intractable because it requires integration over the entire latent space. Furthermore, because the marginal likelihood $p(\mathbf{x};\theta)$ is intractable, the posterior distribution $$p(\mathbf{z}\mid \mathbf{x};\theta) = \frac{p(\mathbf{x}\mid \mathbf{z};\theta)p(\mathbf{z})}{p(\mathbf{x};\theta)}$$ is also intractable. Consequently, standard EM algorithms cannot be applied directly. Therefore, computationally efficient approximations of probability densities are needed.
The posterior distribution is central to Bayesian Inference because it frames every inference about unknown quantities as a calculation based on the posterior.
Variational Inference (also called Variational Bayes or Variational Approximation) is a method for approximating an intractable posterior distribution $p(\mathbf{z}\mid\mathbf{x};\theta)$ with an approximate posterior $q(\mathbf{z}\mid \mathbf{x}; \phi)$(known as the variational posterior), parameterized by variational parameters $\phi$, using optimization.
The optimization problem used in Variational Inference selects an approximate posterior $q(\mathbf{z}\mid \mathbf{x};\phi)$ from a family of tractable probability densities that is as close as possible to the true intractable posterior $p(\mathbf{z}\mid \mathbf{x}; \theta)$.
Let's revisit the marginal log-likelihood of an observation $\mathbf{x}$, $\log p(\mathbf{x};\theta)$, but this time rewrite it to include the variational posterior $q(\mathbf{z}\mid \mathbf{x};\phi)$: $$ \begin{align*} \log p(\mathbf{x}; \theta) &= \log \int_\mathbf{z} p(\mathbf{x}, \mathbf{z};\theta) d\mathbf{z} \\ &= \log \int_\mathbf{z} p(\mathbf{x}, \mathbf{z};\theta)\frac{q(\mathbf{z} \mid \mathbf{x};\phi)}{q(\mathbf{z}\mid \mathbf{x};\phi)} d\mathbf{z} \\ &= \log\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi)\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)}d\mathbf{z} \\ &= \log\Bigg[\mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ \frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} \right]\Bigg] \\ &\geq \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ \log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z}\mid \mathbf{x};\phi)} \right] \text{ by Jensen's inequality} \\ \end{align*} $$
Define $\mathcal{L}(\theta,\phi; \mathbf{x}) = \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z}\mid \mathbf{x};\phi)}\left[ \log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} \right]$. The equation above shows that $$\log p(\mathbf{x}; \theta) \geq \mathcal{L}(\theta,\phi; \mathbf{x})$$ where $\mathcal{L}(\theta,\phi; \mathbf{x})$ serves as a lower bound on the marginal log-likelihood of the observed data $\mathbf{x}$. Therefore, $\mathcal{L}(\theta,\phi; \mathbf{x})$ is known as the evidence lower bound (ELBO) or variational lower bound.
As mentioned earlier, Variational Inference approximates an intractable posterior by solving the optimization problem that selects a tractable variational posterior $q(\mathbf{z} \mid \mathbf{x};\phi)$ that is as close as possible to the intractable posterior $p(\mathbf{z} \mid \mathbf{x};\theta)$. Variational Inference measures the closeness of the two distributions with Kullback-Leibler divergence (KL-divergence).
KL-divergence quantifies the difference between a target distribution $P(x)$ and a model (approximate) distribution $Q(x)$, and it is defined as: $$D_{KL}(P(x)\parallel Q(x)) = \int_x P(x)\log\frac{P(x)}{Q(x)}dx$$ Some attributes of KL-divergence:
Instead of computing forward KL-divergence $D_{KL}\left( p(\mathbf{z} \mid \mathbf{x};\theta) \parallel q(\mathbf{z} \mid \mathbf{x};\phi) \right)$, Variational Inference selects a $q(\mathbf{z}\mid \mathbf{x};\phi)$ that minimizes $D_{KL}\left( q(\mathbf{z}\mid \mathbf{x};\phi) \parallel p(\mathbf{z}\mid \mathbf{x};\theta) \right)$, which is known as the reverse KL-divergence. This is because the forward KL would require taking the expectation with respect to the intractable posterior $p(\mathbf{z} \mid \mathbf{x}; \theta)$.
Let's expand the $D_{KL}\left( q(\mathbf{z}\mid \mathbf{x};\phi) \parallel p(\mathbf{z}\mid \mathbf{x};\theta) \right)$:
$$
\begin{align*}D_{KL}\left( q(\mathbf{z}\mid \mathbf{x};\phi) \parallel p(\mathbf{z} \mid \mathbf{x};\theta) \right) &= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log\frac{ q(\mathbf{z} \mid \mathbf{x};\phi)}{p(\mathbf{z} \mid \mathbf{x};\theta)} d\mathbf{z} \\ &= -\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log\frac{p(\mathbf{z} \mid \mathbf{x};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} d\mathbf{z} \\ &= -\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{p(\mathbf{x};\theta)q(\mathbf{z} \mid \mathbf{x};\phi)} d\mathbf{z} \\ &= -\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[\log p(\mathbf{x}, \mathbf{z};\theta) -\log p(\mathbf{x};\theta) - \log q(\mathbf{z} \mid \mathbf{x};\phi)\right] d\mathbf{z} \\ &= -\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[\log p(\mathbf{x}, \mathbf{z};\theta) - \log q(\mathbf{z} \mid \mathbf{x};\phi) -\log p(\mathbf{x};\theta)\right] d\mathbf{z} \\ &= -\left(\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[\log p(\mathbf{x}, \mathbf{z};\theta) - \log q(\mathbf{z} \mid \mathbf{x};\phi)\right] - q(\mathbf{z} \mid \mathbf{x};\phi) \log p(\mathbf{x};\theta) d\mathbf{z}\right) \\ &= -\left(\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log \frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} d\mathbf{z} -\int_\mathbf{z} q(\mathbf{z}\mid \mathbf{x};\phi)\log p(\mathbf{x};\theta) d\mathbf{z}\right) \\ &= -\int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log \frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} d\mathbf{z} + \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi)\log p(\mathbf{x} ; \theta) d\mathbf{z} \\ &= - \;\underbrace{ \mathbb{E}_{\mathbf{z}\sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[\log \frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} \right]}_{\text{ELBO: } \mathcal{L}(\theta,\phi;\mathbf{x})} + \log p(\mathbf{x};\theta) \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi)d\mathbf{z} \\ &= -\mathcal{L}(\theta,\phi; \mathbf{x}) + \log p(\mathbf{x};\theta) \end{align*}
$$
which can be rewritten as:
$$\log p(\mathbf{x};\theta) = \mathcal{L}(\theta,\phi; \mathbf{x}) + D_{KL}\left( q(\mathbf{z} \mid \mathbf{x};\phi) \parallel p(\mathbf{z} \mid \mathbf{x};\theta) \right) $$
Since KL-divergence is always non-negative, the equation above is consistent with the previously derived ELBO inequality: $\log p(\mathbf{x};\theta) \geq \mathcal{L}(\theta,\phi; \mathbf{x})$
Notice that $D_{KL}\left( q(\mathbf{z} \mid \mathbf{x};\phi) \parallel p(\mathbf{z} \mid \mathbf{x};\theta) \right)$ is intractable because it requires knowing the intractable posterior $p(\mathbf{z} \mid \mathbf{x};\theta) $. However, the equation above shows that, for fixed $\theta$, maximizing the ELBO with respect to $\phi$ is equivalent to minimizing the KL-divergence with respect to $\phi$. This is because the marginal log-likelihood $\log p(\mathbf{x};\theta)$ doesn't depend on $\phi$, and thus when $\theta$ is fixed, any increase in the ELBO corresponds exactly to a decrease in the KL-divergence between the variational posterior and the true intractable posterior.
The previous section introduced the core ideas behind Variational Inference and showed that its original objective of minimizing the KL-divergence can be reframed as maximizing the ELBO, which is defined as $$\mathcal{L}(\theta,\phi; \mathbf{x}) = \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ \log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} \right]$$ To give intuitions about the optimal variational posterior, rewrite the ELBO as: $$ \begin{align*}\mathcal{L}(\theta,\phi; \mathbf{x}) &= \mathbb{E}_{\mathbf{z}\sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ \log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)} \right] \\ &= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi)\log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z} \mid \mathbf{x};\phi)}d\mathbf{z} \\&= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi)\log\frac{p(\mathbf{x} \mid \mathbf{z};\theta)p(\mathbf{z})}{q(\mathbf{z} \mid \mathbf{x};\phi)}d\mathbf{z} \\&= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) + \log p(\mathbf{z}) -\log q(\mathbf{z} \mid \mathbf{x};\phi)\right]d\mathbf{z} \\&= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right] + q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log p(\mathbf{z}) -\log q(\mathbf{z} \mid \mathbf{x};\phi)\right]d\mathbf{z} \\&= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right] - q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log q(\mathbf{z} \mid \mathbf{x} ;\phi) - \log p(\mathbf{z}) \right]d\mathbf{z} \\&= \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right]d\mathbf{z} - \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \left[ \log q(\mathbf{z} \mid \mathbf{x};\phi) - \log p(\mathbf{z}) \right]d\mathbf{z} \\&= \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)} \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right] - \int_\mathbf{z} q(\mathbf{z} \mid \mathbf{x};\phi) \log \frac{q(\mathbf{z} \mid \mathbf{x};\phi)}{p(\mathbf{z})}d\mathbf{z} \\&= \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)} \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right] - D_{KL}(q(\mathbf{z} \mid \mathbf{x};\phi) \parallel p(\mathbf{z})) \end{align*} $$ The equation above splits the ELBO into two terms:
Together, these two terms in the ELBO in Variational Inference give the familiar encoder-decoder training infrastructure in VAEs, where the encoder, parameterized by $\phi$, maps $\mathbf{x}$ from the observation space into the latent space $\mathbf{z}$, while the decoder, parameterized by $\theta$, maps this $\mathbf{z}$ back to the observation space:
To jointly learn the encoder and decoder in an end-to-end manner using standard gradient methods, the VAE employs a reparameterization trick and introduces the Stochastic Gradient Variational Bayes (SGVB) estimator, which is a differentiable unbiased estimator of the ELBO with respect to $\phi$ and $\theta$.
Recall that the VAE assumes $p(\mathbf{z}) = \mathcal{N} (\mathbf{0}, \mathbf{I})$ and $p(\mathbf{x} \mid \mathbf{z};\theta) $ is a multivariate Gaussian with a diagonal covariance matrix. With these assumptions in place, optimizing the ELBO $$ \mathcal{L}(\theta,\phi; \mathbf{x}) = \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x} ;\phi)} \left[ \log p(\mathbf{x} \mid \mathbf{z};\theta) \right] - D_{KL}(q(\mathbf{z} \mid \mathbf{x};\phi) \parallel p(\mathbf{z})) $$ via gradient ascent requires computing $\nabla_\theta \mathcal{L}$ and $\nabla_\phi \mathcal{L}$.
The $\theta$-gradient is easy: since the sampling distribution $q(\mathbf{z} \mid \mathbf{x}; \phi)$ doesn't depend on $\theta$, the gradient can be moved straight inside the expectation, which allows the resulting expectation to be estimated via the usual sample-based approximation (Monte Carlo estimation). For a datapoint $\mathbf{x}^{(i)}$: $$\begin{align*} \nabla_\theta \mathcal{L}(\theta,\phi; \mathbf{x}^{(i)}) = \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x}^{(i)}; \phi)}\big[\nabla_\theta \log p(\mathbf{x}^{(i)} \mid \mathbf{z};\theta)\big] \approx \frac{1}{L}\sum_{j=1}^{L} \nabla_\theta \log p(\mathbf{x}^{(i)} \mid \mathbf{z}^{(j)};\theta) \end{align*}$$ The number of samples $L$ per datapoint for this approximation can be set to 1, as long as the batch size (the number of datapoints per batch), is large enough, such as 100. In this case, the decoder's parameters $\theta$ can be updated via gradient ascent with: $$ \nabla_\theta \tilde{\mathcal{L}} (\theta,\phi; \mathbf{x}) = \nabla_\theta \log p(\mathbf{x} \mid \mathbf{z};\theta) \hspace{1cm}\text{when batch size is large, e.g. 100}$$ On the other hand, the $\phi$-gradient is tricky. Since the expectation depends on $\phi$, the gradient and expectation can't simply be swapped as before.
Assume the intractable posterior $p(\mathbf{z}\mid\mathbf{x};\theta)$ is approximately Gaussian with an approximately diagonal covariance. In this case, let the variational posterior $q(\mathbf{z} \mid \mathbf{x} ;\phi)$ be a multivariate Gaussian distribution with a diagonal covariance matrix: $ \mathcal{N}(\bm{\mu}, \Sigma)$, where $\Sigma = \text{diag}(\sigma^2_1, \dots, \sigma^2_K )$, $\bm{\mu}=[\mu_{1},\dots,\mu_K]$, and $K$ denotes the dimensionality of the latent $\mathbf{z}$. Let $\bm{\sigma}=[\sigma_{1},\dots,\sigma_K]$ .
The assumption of a diagonal covariance matrix for a multivariate Gaussian distribution means that, given $\mathbf{x}$, each element of $\mathbf{z}$ is independently distributed as a univariate Gaussian :
$$z_k\mid\mathbf{x} \sim \mathcal{N}(\mu_k, \sigma^2_k)$$
where $k$ denotes the $k$-th element. There are two equivalent ways to sample $\mathbf{z}$:
Notice that $\bm{\epsilon}$ doesn't depend on $\phi$. Since $\mathbf{z}$ is reparameterized as $g(\bm{\epsilon};\phi)$, taking its expectation directly or via $\bm{\epsilon}$ gives the same result: $$\mathbb{E}_{\mathbf{z}}[\mathbf{z}]=\mathbb{E}_{\bm{\epsilon}}\left[g\left(\bm{\epsilon};\phi \right)\right]$$ This same logic extends to any function $r(\cdot)$ of $\mathbf{z}$, and thus the gradient of $\mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ r \left(\mathbf{z} \right)\right]$ can be written as: $$\begin{align*} \nabla_\phi\, \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z} \mid \mathbf{x};\phi)}\left[ r \left(\mathbf{z} \right)\right] = \nabla_\phi\, \mathbb{E}_{\bm{\epsilon}}\left[r\left(g(\bm{\epsilon};\phi)\right)\right] = \mathbb{E}_{\bm{\epsilon}}\big[\nabla_\phi\, r \left(g\left(\bm{\epsilon};\phi\right)\right)\big] \approx \frac{1}{L}\sum_{j=1}^{L} \nabla_\phi\, r (\,g(\bm{\epsilon}^{(j)};\phi)) \end{align*}$$ Applying this to $\nabla_\phi \mathcal{L}$, for a datapoint $\mathbf{x}^{(i)}$, gives: $$ \begin{align*} \nabla_\phi \mathcal{L}(\theta,\phi;\mathbf{x}^{(i)}) &= \nabla_\phi\mathbb{E}_{\mathbf{z} \sim q(\mathbf{z}\mid \mathbf{x}^{(i)};\phi)} \left[ \log p(\mathbf{x}^{(i)}\mid \mathbf{z};\theta) \right] - \nabla_\phi D_{KL}(q(\mathbf{z} \mid \mathbf{x}^{(i)};\phi) \parallel p(\mathbf{z})) \\ &= \nabla_\phi\mathbb{E}_{\bm{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})} \left[ \log p(\mathbf{x}^{(i)} \mid g(\bm{\epsilon};\phi);\theta) \right] - \nabla_\phi D_{KL}(q(\mathbf{z} \mid \mathbf{x}^{(i)};\phi) \parallel p(\mathbf{z})) \\ &= \mathbb{E}_{\bm{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})} \left[\nabla_\phi \log p(\mathbf{x}^{(i)} \mid g(\bm{\epsilon};\phi);\theta) \right] - \nabla_\phi D_{KL}(q(\mathbf{z} \mid \mathbf{x}^{(i)};\phi) \parallel p(\mathbf{z})) \\ &\approx \frac{1}{L}\sum_{j=1}^L \nabla_\phi \log p\left(\mathbf{x}^{(i)} \mid \bm{\mu}^{(i)}+\bm{\sigma}^{(i)}\odot\bm{\epsilon}^{(j)};\theta\right) - \nabla_\phi D_{KL}\big(q(\mathbf{z} \mid \mathbf{x}^{(i)}; \phi)\parallel p(\mathbf{z})\big) \end{align*}$$ where $\bm{\mu}^{(i)}$ and $\bm{\sigma}^{(i)}$, the variational mean and standard deviation vectors, are outputs of the encoder for datapoint $\mathbf{x}^{(i)}$. This reparameterization trick expresses $\mathbf{z}$ as $g(\bm{\epsilon};\phi)$, where $\bm{\epsilon}$ doesn't depend on $\phi$, so gradients can flow all the way back to the encoder's parameters $\phi$. The equation above gives the proposed SGVB estimator for the gradient of the ELBO with respect to $\phi$.
Another benefit of letting $q(\mathbf{z} \mid \mathbf{x} ;\phi)$ be a Gaussian distribution with a diagonal covariance matrix is that, since the VAE already assumes the prior $p(\mathbf{z}) = \mathcal{N}(\mathbf{0}, \mathbf{I})$, the KL-divergence term, $D_{KL}\left(q(\mathbf{z} \mid \mathbf{x} ;\phi)\parallel p(\mathbf{z})\right)$, has a simple closed-form expression: $$\begin{align*}D_{KL}\left(q(\mathbf{z} \mid \mathbf{x} ;\phi)\parallel p(\mathbf{z})\right) &= \int_{\mathbf{z}} q(\mathbf{z} \mid \mathbf{x} ;\phi) \log\frac{q(\mathbf{z} \mid \mathbf{x} ;\phi)}{p(\mathbf{z})} d\mathbf{z} \\ &= -\frac{1}{2}\sum_{k=1}^{K}\left(1 + \log((\sigma_k)^2) - \left(\mu_k\right)^2 - \left(\sigma_k\right)^2\right) \end{align*}$$ where $\mu_k$ and $\sigma_k$ denote the $k$-th element of the encoder's outputs $\bm{\mu}$ and $\bm{\sigma}$, respectively. Substituting this closed-form expression back into the $\nabla_\phi \mathcal{L}$ above gives: $$\begin{align*} \nabla_\phi \mathcal{L}(\theta,\phi;\mathbf{x}^{(i)}) \approx \frac{1}{L}\sum_{j=1}^L \nabla_\phi \log p\left(\mathbf{x}^{(i)}\mid \bm{\mu}^{(i)}+\bm{\sigma}^{(i)} \odot \bm{\epsilon}^{(j)};\theta\right) + \nabla_\phi \bigg[\frac{1}{2}\sum_{k=1}^{K}\left(1 + \log((\sigma_k^{(i)})^2) - (\mu_k^{(i)})^2 - (\sigma_k^{(i)})^2\right)\bigg] \end{align*}$$ Similarly, with a large enough batch size (e.g., 100), $L$ can be set to $1$. Then, the encoder's parameters $\phi$ can be updated with: $$\begin{align*} \nabla_\phi \tilde{\mathcal{L}}(\theta,\phi;\mathbf{x}) = \nabla_\phi \log p\left(\mathbf{x}\mid \bm{\mu}+\bm{\sigma} \odot \bm{\epsilon};\theta\right) + \nabla_\phi \bigg[\frac{1}{2}\sum_{k=1}^{K}\left(1 + \log((\sigma_k)^2) - \left(\mu_k\right)^2 - \left(\sigma_k\right)^2\right)\bigg] \end{align*}$$
Note that the reparameterization trick used in VAEs requires that $\mathbf{z}$ follow some distribution that can be expressed as a differentiable and deterministic function of another random vector that is independent of the model parameters, which limits $\mathbf{z}$ to continuous random variables .
Remember in reinforcement learning, the policy gradient involves taking the gradient of an expectation over an unknown distribution, that is, the transition distribution. Since the transition distribution is often non-differentiable, this distribution cannot be reparameterized the same way as in VAEs, so the same trick does not apply. Instead, the REINFORCE algorithm, explained in detail in previous post on multimodal reasoning, is used. REINFORCE is a general-purpose approach for rewriting the gradient of an expectation as an expectation involving the gradient of the log-probability, regardless of whether the underlying unknown distribution is discrete or continuous. As noted in the VAE paper, however, REINFORCE exhibits very high variance in its gradient estimates, resulting in unstable learning and slow convergence.
Though the theoretical math behind the VAE is complex, in practice, the models are relatively easy to train. Both the encoder and the decoder can be simple neural networks, such as MLPs, and are trained to output the mean and standard deviation vectors of Gaussian distributions. Note that in practice, both networks output log variances rather than standard deviations, for numerical stability. In addition, for image data, the pixel values are scaled to the range $[0, 1]$ before being fed into the encoder, and thus the values in the mean vector at the decoder output are constrained to $(0, 1)$ by using a sigmoid activation at the decoder output.
With batch size $M = 100$ and $L = 1$, the training pipeline involves:
The encoder's and decoder's parameters are updated together by gradient ascent: $$\begin{align*} \phi & \leftarrow \phi + \alpha \nabla_\phi \tilde{\mathcal{L}}(\theta,\phi;\mathbf{X}^M),\hspace{1cm} \text{where } \nabla_\phi \tilde{\mathcal{L}}(\theta,\phi;\mathbf{X}^M)= \frac{1}{M}\sum_{i=1}^{M}\nabla_\phi \tilde{\mathcal{L}}(\theta,\phi;\mathbf{x}^{(i)}) \\ \theta &\leftarrow \theta + \alpha \nabla_\theta \tilde{\mathcal{L}}(\theta,\phi;\mathbf{X}^M),\hspace{1cm} \text{where} \nabla_\theta \tilde{\mathcal{L}}(\theta,\phi;\mathbf{X}^M) = \frac{1}{M}\sum_{i=1}^{M}\nabla_\theta \tilde{\mathcal{L}}(\theta,\phi;\mathbf{x}^{(i)}) \end{align*}$$ where $\alpha$ is the learning rate.

The VAE is an unsupervised learning algorithm for latent representations $\mathbf{z}$ of the observed data $\mathbf{x}$. Several studies have suggested that learning disentangled latent representations is a crucial step towards better representation learning. According to Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations, while the field has yet to agree on a single formal definition and metric of disentanglement, the key idea is that a disentangled latent representation should separate and capture the informative factors of variation, such as hair color, hair length, sex, etc., in the data. For example, given two portraits $\mathbf{x}_A$ and $\mathbf{x}_B$ that are identical everywhere except for the hair color, their respective disentangled latent representations $\mathbf{z}_{A}$ and $\mathbf{z}_B$ should then be nearly identical across all dimensions except for the single dimension $z_i$ that is responsible for encoding hair color.
$\beta$-VAE enhances the disentanglement performance of the VAE by introducing a single adjustable hyperparameter $\beta$ into the objective function:
$$
\mathcal{L}_\beta(\theta, \phi ; \mathbf{x}) = \mathbb{E}_{\mathbf{z} \sim q(\mathbf{z}\mid \mathbf{x};\phi)}\big[\log p(\mathbf{x} \mid \mathbf{z};\theta)\big] - \beta \, D_{KL}\big(q(\mathbf{z}\mid \mathbf{x};\phi)\parallel p(\mathbf{z})\big)
$$
where $\beta$ acts as a regularization coefficient, and setting $\beta=1$ recovers the original VAE.
The paper posits that it is important to set $\beta > 1$ in order to learn disentangled latent representations, and further hypothesizes that higher values of $\beta$ should encourage a greater degree of disentanglement in the latent representation. This is because the prior $p(\mathbf{z}) = \mathcal{N}(\mathbf{0}, \mathbf{I})$ is an isotropic Gaussian, i.e., it has a diagonal covariance matrix where the variances are the same across all dimensions. When $\beta \gt 1$, the model puts a stronger constraint on the latent information capacity of $\mathbf{z}$, encouraging it to learn a more efficient latent representations of the data. These representations become disentangled if the data contains at least some underlying factors of variation that are independent.
The value of $\beta$ also creates a trade-off between the reconstruction performance and disentanglement quality of the latent representations. Different datasets will require different optimal values of $\beta$ but the optimal value of $\beta$ cannot be learned directly.
DALL·E, which was introduced and explained at a high level in the previous post, is a model for text-to-image generation tasks that turns a text prompt into a matching image. Readers interested in the full model architecture and how it works can refer to the Translation section of that post.
DALL·E adopts a discrete Variational Auto-Encoder (dVAE) to encode an input image into a grid of image tokens. These image tokens are then concatenated with the text tokens of the matching caption and processed together by an autoregressive Transformer decoder.
The discrete VAE is formulated by assuming $q(z\mid x;\phi)$ is a categorical distribution, rather than Gaussian distribution used in the original VAE. By doing so, $z$ becomes a discrete random variable, and the original reparameterization trick in the VAE must be adapted accordingly. Details of how to reparameterize a categorical distribution can be found in the paper.
In addition, DALL·E assumes that $p(x\mid z; \theta)$ is a logit-Laplace distribution instead of Gaussian distribution. This is because pixel values lie within a bounded interval, but the support of Gaussian distributions spans the entire real line; therefore, the authors proposed a variant of the Laplace distribution whose support is restricted to $(0, 1)$. Finally, during training, DALL·E attempts to maximize the $\beta$-ELBO objective, with $\beta$ increasing from $0$ to $6.6$ over the first $5000$ updates.
Diffusion probabilistic models (known as "diffusion models" for brevity) learn a generative model using a Markov chain that gradually converts a simple, tractable distribution into the data distribution. The authors emphasize that their idea and motivation behind the diffusion models is from nonequilibrium statistical physics and thermodynamics rather than from Variational Inference methods although they are both trained by maximizing a lower bound and involve approximating posterior distributions.
A diffusion model defines two Markov chains: one employs a forward diffusion process while the other employs a reverse, generative diffusion process. These processes have opposite goals:
Let $q(\mathbf{x}_0)$ be the data distribution of the observed data. The forward diffusion process is a Markov chain, and thus the joint distribution of the chain over any finite time steps $T$ satisfies:
$$q(\mathbf{x}_{0}, \dots, \mathbf{x}_{T}) = q(\mathbf{x}_{0:T}) = q(\mathbf{x}_0)\prod_{t=1}^{T}q(\mathbf{x}_t\mid\mathbf{x}_{t-1})$$
The goal of the forward diffusion process is to gradually convert the data distribution into a simple, tractable noise distribution $\pi(\mathbf{x}_T)$. For real-valued data such as images, diffusion models set $\pi(\mathbf{x}_T) = \mathcal{N}(\mathbf{0}, \mathbf{I})$, and the corresponding forward Markov diffusion kernel is then a Gaussian diffusion kernel:
$$q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}) = \mathcal{N}(\mathbf{x}_t;\sqrt{1-\beta_t}\mathbf{x}_{t-1}, \beta_t\mathbf{I}) $$
where $\beta_t\in(0,1)$ is the diffusion rate.
The reversal of such diffusion process is also a Markov chain, where the joint distribution of the chain is the same probability distribution over the same sequence of random variables $(\mathbf{x}_0,\dots, \mathbf{x}_T)$ in the forward diffusion process, but is simply written as its factorization in the opposite temporal direction:
$$q(\mathbf{x}_{0:T}) = q(\mathbf{x}_T)\prod_{t=1}^{T}q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t})$$
where $q(\mathbf{x}_T) = \pi(\mathbf{x}_T) = \mathcal{N}(\mathbf{0}, \mathbf{I})$.
By running this reverse process, we can generate samples from the data distribution, starting at a sample $\mathbf{x}_T \sim\mathcal{N}(\mathbf{0}, \mathbf{I})$. However, the true reverse Markov transitions
$q(\mathbf{x}_{t-1}\mid \mathbf{x}_t)$ are intractable, so the diffusion models are trained to approximate them with neural networks $p(\mathbf{x}_{t-1}\mid \mathbf{x}_t;\theta)$.
For the Gaussian diffusion kernel $q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}) $ in the forward process, when $\beta_t$ is small, the reverse Markov transition $q(\mathbf{x}_{t-1}\mid \mathbf{x}_t)$ will have the same functional form, that is, also be a Gaussian distribution. Therefore, training a diffusion model comes down to learning the mean and covariance of the Gaussian transition kernel at every time step $t$ of the reverse process: $$p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t}; \theta) = \mathcal{N}(\mathbf{x}_{t-1}; \bm{\mu}_\theta(\mathbf{x}_t, t), \bm{\Sigma}_\theta(\mathbf{x}_t, t) )$$ where $\bm{\mu}_\theta(\mathbf{x}_t, t)$ and $\bm{\Sigma}_\theta(\mathbf{x}_t, t) $ are neural networks, and $\bm{\Sigma}_\theta(\mathbf{x}_t, t)$ is a diagonal matrix.
The joint distribution of the reverse process then defines the generative model distribution in diffusion models: $$p(\mathbf{x}_{0:T}; \theta) = p(\mathbf{x}_T)\prod_{t=1}^Tp(\mathbf{x}_{t-1}\mid\mathbf{x}_{t}; \theta)$$ where $p(\mathbf{x}_T) = \pi(\mathbf{x}_T) = \mathcal{N}(\mathbf{0}, \mathbf{I})$
The log-likelihood that the generative model $p(\mathbf{x}_{0:T}; \theta)$ assigns to the observed data $\mathbf{x}_0$ can be obtained by marginalizing out $\mathbf{x}_{1:T}$, and a lower bound on it can be derived as follows: $$\begin{align*}\log p(\mathbf{x}_0; \theta) &= \log\int_{\mathbf{x}_{1:T}} p(\mathbf{x}_{0:T};\theta)d\mathbf{x}_{1:T} \\ &= \log\int_{\mathbf{x}_{1:T}} p(\mathbf{x}_{0:T};\theta) \frac{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}d\mathbf{x}_{1:T} \\ &= \log\int_{\mathbf{x}_{1:T}} q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}d\mathbf{x}_{1:T} \\ &= \log\Bigg[\mathbb{E}_{\mathbf{x}_{1:T}\sim q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)}\left[\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}\right] \Bigg] \\ &\geq \mathbb{E}_{\mathbf{x}_{1:T}\sim q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[\log\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)} \right] \;\text{by Jensen's inequality} \end{align*}$$ where $q(\mathbf{x}_{1:T}\mid\mathbf{x}_0) $ denotes the conditional forward trajectory.
This lower bound for diffusion models closely resembles the ELBO. Remember that the ELBO in Variational Inference is a lower bound on the marginal log-likelihood of the observed data $\mathbf{x}$: $$\log p(\mathbf{x};\theta) \geq \mathbb{E}_{\mathbf{z}\sim q(\mathbf{z}\mid \mathbf{x};\phi)}\left[\log\frac{p(\mathbf{x}, \mathbf{z};\theta)}{q(\mathbf{z}\mid\mathbf{x};\phi)}\right]$$
where $\mathbf{z}$ represents the latent variables.
To see the resemblance, let the latent $\mathbf{z}$ in Variational Inference be replaced by the noisy trajectory $\mathbf{x}_{1:T}$ in diffusion models, and let the observed data $\mathbf{x}$ in Variational Inference be replaced by the observed data $\mathbf{x}_0$ in diffusion models. This resemblance can be interpreted as follows: while the forward diffusion process in diffusion models gradually adds Gaussian noise to the data through the Gaussian transition kernel $q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})$ over $T$ diffusion steps until the data is mapped to $q(\mathbf{x}_T) = \mathcal{N}(\mathbf{0}, \mathbf{I})$. Variational Inference with a Gaussian variational posterior $q(\mathbf{z}\mid\mathbf{x};\phi)$ and prior $p(\mathbf{z})=\mathcal{N}(\mathbf{0}, \mathbf{I})$ figuratively performs this mapping in a single step.

However, as emphasized earlier, diffusion models are inspired by nonequilibrium statistical physics, where the distribution over a system's states gradually evolves into another distribution through a process modeled by a Markov chain. By analogy, every $\mathbf{x}_t$ in diffusion models describes the same underlying system as $\mathbf{x}_0$, and the forward process is defined as a Markov chain that gradually transforms the data distribution at $t=0$ into a simple, tractable noise distribution at $t=T$. Therefore, the entire sequence of $\mathbf{x}_{0:T}$ has the same dimensionality. On the other hand, the generative process $\mathbf{z}\to\mathbf{x}$ in Variational Inference is not subject to this constraint, so the observed $\mathbf{x}$ and the latent $\mathbf{z}$ can have different dimensionalities, and the latent dimension is usually set much smaller than the data dimension.
Below lists some of the noteworthy differences between diffusion models and VAEs:
The goal of diffusion models is to approximate the true data distribution $q(\mathbf{x}_0)$ as closely as possible with the model distribution $p(\mathbf{x}_0;\theta)$, where closeness is also measured by the
KL-divergence:
$$\begin{align*}D_{KL}(q(\mathbf{x}_0)\parallel p(\mathbf{x}_0;\theta)) &= \int_{\mathbf{x}_0}q(\mathbf{x}_0)\log\frac{q(\mathbf{x}_0)}{p(\mathbf{x}_0;\theta)}d\mathbf{x}_0 \\
&= \int_{\mathbf{x}_0}q(\mathbf{x}_0)[\log q(\mathbf{x}_0) - \log p(\mathbf{x}_0;\theta)]d\mathbf{x}_0 \\
&= \int_{\mathbf{x}_0}q(\mathbf{x}_0)\log q(\mathbf{x}_0)d\mathbf{x}_0 - \int_{\mathbf{x}_0}q(\mathbf{x}_0)\log p(\mathbf{x}_0;\theta)d\mathbf{x}_0 \\
&= \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log q(\mathbf{x}_0)] - \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)]
\end{align*}$$
where $\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)]$ is known as the expected log-likelihood.
Since the first term in the equation above doesn't depend on $\theta$, it is a constant with respect to $\theta$. Therefore, minimizing the KL-divergence between $q(\mathbf{x}_0)$ and $p(\mathbf{x}_0;\theta)$ is equivalent to maximizing the expected log-likelihood. That is, the diffusion models are trained to find the $\theta^*$ that satisfies:
$$\theta^* =\arg\max_{\theta} \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)]$$
However, evaluating $p(\mathbf{x}_0;\theta)$ is intractable because it requires integration over all possible trajectories $\mathbf{x}_{1:T}$ of the reverse process:
$$p(\mathbf{x}_0;\theta)=\int_{\mathbf{x}_{1:T}}p(\mathbf{x}_{0:T};\theta)d\mathbf{x}_{1:T}=\int_{\mathbf{x}_{1:T}}p(\mathbf{x}_{T})\prod_{t=1}^{T}p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)d\mathbf{x}_{1:T}$$
The lower bound on the log-likelihood of observed data $\mathbf{x}_0$ is derived for a fixed observation $\mathbf{x}_0$. To obtain a lower bound on the expected log-likelihood, $\mathbf{x}_0$ is now treated as a random variable drawn from the data distribution $q(\mathbf{x}_0)$ rather than as a fixed datapoint. The lower bound on the expected log-likelihood is then obtained by averaging this bound over $\mathbf{x}_0\sim q(\mathbf{x}_0)$: $$\begin{align*} \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)] &= \int_{\mathbf{x}_0}q(\mathbf{x}_0)\log p(\mathbf{x}_0;\theta)d\mathbf{x}_0 \\ &\geq \int_{\mathbf{x}_0}q(\mathbf{x}_0)\mathbb{E}_{\mathbf{x}_{1:T}\sim q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)}\left[\log \frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}\right] d\mathbf{x}_0 \hspace{0.2cm}\text{by the lower bound} \\ &= \int_{\mathbf{x}_0}q(\mathbf{x}_0) \int_{\mathbf{x}_{1:T}} q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)\log\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}d\mathbf{x}_{1:T} d\mathbf{x}_0 \\ &= \int_{\mathbf{x}_0}\int_{\mathbf{x}_{1:T}} q(\mathbf{x}_0) q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)\log\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}d\mathbf{x}_{1:T} d\mathbf{x}_0 \\ &= \int_{\mathbf{x}_{0:T}} q(\mathbf{x}_{0:T})\log\frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_0)}d\mathbf{x}_{0:T} \\ &= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\left[\log \frac{p(\mathbf{x}_{0:T};\theta)}{q(\mathbf{x}_{1:T}\mid\mathbf{x}_{0})}\right] \\ &= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\left[\log \frac{p(\mathbf{x}_{T})\prod_{t=1}^{T}p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{\prod_{t=1}^{T}q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\right] \\ &= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log \bigg[p(\mathbf{x}_{T})\prod_{t=1}^{T}\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\bigg]\Bigg] \\ &= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\log\bigg[\prod_{t=1}^{T}\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\bigg]\Bigg] \\ &= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=1}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\Bigg] \end{align*}$$ As a result, the lower bound on the expected log-likelihood is: $$\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)] \geq \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=1}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\Bigg]$$
Although the expected log-likelihood is intractable, its lower bound is tractable because it doesn't involve the evaluation of $p(\mathbf{x}_0;\theta)$ anymore. Instead, it contains an expectation with respect to trajectories $\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})=q(\mathbf{x}_0)\prod_{t=1}^{T}q(\mathbf{x}_t\mid\mathbf{x}_{t-1})$ drawn from the forward process.Therefore, when training diffusion models, this lower bound on the expected log-likelihood is maximized as the objective function instead of the expected log-likelihood.
The Denoising Diffusion Probabilistic Models (DDPM) paper employs the diffusion models for image generation tasks and proposes a re-weighted version of the lower bound on the expected log-likelihood as a new simplified training objective function for diffusion models. Their empirical results show that diffusion models that are trained with this weighted lower bound can generate high quality images.
In DDPM, the $\beta_t$ in the forward Gaussian diffusion kernel $q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})$ are fixed to constants using a linear schedule method rather than learned during training. They increase linearly from $\beta_1=10^{-4}$ to $\beta_T=0.02$ over $T=1000$ steps.
Recall that the lower bound for diffusion models on the expected log likelihood of $\mathbf{x}_0$ is:
$$\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0)}[\log p(\mathbf{x}_0;\theta)] \geq \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=1}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\Bigg]$$
One benefit of choosing the Gaussian transition kernel for the forward process,
$q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}) = \mathcal{N}(\mathbf{x}_t;\sqrt{1-\beta_t}\mathbf{x}_{t-1}, \beta_t\mathbf{I})$, is that the distribution $q(\mathbf{x}_t\mid\mathbf{x}_0)$ has a closed form. As a result, $\mathbf{x}_t$ can be sampled at any time step directly from $\mathbf{x}_0$, without simulating the whole chain:
$$ q(\mathbf{x}_t\mid\mathbf{x}_0) = \mathcal{N}(\mathbf{x}_t ; \sqrt{\bar{\alpha}_t}\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I})$$
where $\alpha_t := 1 - \beta_t$ and $\bar{\alpha}_t := \prod_{s=1}^{t}\alpha_s$.
Rewrite the lower bound on the expected log-likelihood as follows:
$$\begin{align*} & \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=1}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})}\Bigg] \\
&= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1})} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
&= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}, \mathbf{x}_0)} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \, (*) \\
&= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{\frac{q(\mathbf{x}_t\mid\mathbf{x}_0)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_0)} \frac{q(\mathbf{x}_{t}, \mathbf{x}_{t-1}, \mathbf{x}_{0})}{q(\mathbf{x}_t, \mathbf{x}_0)}} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
&= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{\frac{q(\mathbf{x}_t\mid\mathbf{x}_0)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_0)} q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
&= \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log\bigg[\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} \frac{q(\mathbf{x}_{t-1}\mid\mathbf{x}_0)}{q(\mathbf{x}_t\mid\mathbf{x}_0)} \bigg] + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} + \sum_{t=2}^{T}\log\frac{q(\mathbf{x}_{t-1}\mid\mathbf{x}_0)}{q(\mathbf{x}_t\mid\mathbf{x}_0)} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} + \sum_{t=2}^{T}\bigg[\log q(\mathbf{x}_{t-1}\mid\mathbf{x}_0) - \log q(\mathbf{x}_t\mid\mathbf{x}_0)\bigg] + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\bigg[\log q(\mathbf{x}_{1}\mid\mathbf{x}_0) - \log q(\mathbf{x}_T\mid\mathbf{x}_0)\bigg] + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log \frac{q(\mathbf{x}_{1}\mid\mathbf{x}_0)}{q(\mathbf{x}_T\mid\mathbf{x}_0)} + \log\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log \bigg[\frac{q(\mathbf{x}_{1}\mid\mathbf{x}_0)}{q(\mathbf{x}_T\mid\mathbf{x}_0)}\frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_{1}\mid\mathbf{x}_{0})}\bigg]\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log \frac{p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}{q(\mathbf{x}_T\mid\mathbf{x}_0)}\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T})+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta) - \log q(\mathbf{x}_T\mid\mathbf{x}_0)\Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log p(\mathbf{x}_{T}) - \log q(\mathbf{x}_T\mid\mathbf{x}_0)+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta) \Bigg] \\
& = \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\Bigg[\log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)}+\sum_{t=2}^{T}\log \frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)} +\log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta) \Bigg] \\
& = \mathbb{E}_{q}\Bigg[- D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T})) - \sum_{t=2}^{T} D_{KL}(q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)) +\log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta) \Bigg] \, (**)
\end{align*}$$
$(*)$ Recall that the forward process in diffusion models is a Markov chain, and thus by the Markov property, $q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}) = q(\mathbf{x}_{t}\mid\mathbf{x}_{t-1}, \mathbf{x}_{0}) $.
$(**)$ Expand to see step-by-step derivation of the last equation:
In the second to last equation, the expectation is taken over the joint distribution of $q(\mathbf{x}_{0:T})$, and each term inside the expectation is a logarithm or a sum of logarithms. For each term, by marginalization out the variables that are not inside the logarithm from $q(\mathbf{x}_{0:T})$, the integral over all variables $\mathbf{x}_{0:T}$ can be simplified to an integral over the ones inside the logarithm. Take, for example, the first term inside the expectation:
$$\begin{align*} \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\left[\log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)}\right] &= \int_{\mathbf{x}_{0:T}} q(\mathbf{x}_{0:T}) \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} d\mathbf{x}_{0:T} \\
&= \int_{\mathbf{x}_{0}} \int_{\mathbf{x}_{T}} \int_{\mathbf{x}_{1:T-1}} q(\mathbf{x}_{0:T}) \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} d\mathbf{x}_{1:T-1} d\mathbf{x}_{T}d\mathbf{x}_{0} \\
&= \int_{\mathbf{x}_{0}} \int_{\mathbf{x}_{T}} \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} \int_{\mathbf{x}_{1:T-1}} q(\mathbf{x}_{0:T}) d\mathbf{x}_{1:T-1} d\mathbf{x}_{T}d\mathbf{x}_{0}\\
&= \int_{\mathbf{x}_{0}} \int_{\mathbf{x}_{T}} \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} q(\mathbf{x}_{0}, \mathbf{x}_{T}) d\mathbf{x}_{T}d\mathbf{x}_{0} \hspace{0.3cm} \text{by marginalization} \\
&= \int_{\mathbf{x}_{0}} \int_{\mathbf{x}_{T}} q(\mathbf{x}_{0}, \mathbf{x}_{T}) \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} d\mathbf{x}_{T}d\mathbf{x}_{0} \\
&= \int_{\mathbf{x}_{0}} \int_{\mathbf{x}_{T}} q(\mathbf{x}_{T} \mid \mathbf{x}_{0}) q(\mathbf{x}_0) \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} d\mathbf{x}_{T}d\mathbf{x}_{0} \\
&= \int_{\mathbf{x}_{0}} q(\mathbf{x}_0) \int_{\mathbf{x}_{T}} q(\mathbf{x}_{T} \mid \mathbf{x}_{0}) \log \frac{p(\mathbf{x}_{T})}{q(\mathbf{x}_T\mid\mathbf{x}_0)} d\mathbf{x}_{T} d\mathbf{x}_{0} \\
&= -\int_{\mathbf{x}_{0}} q(\mathbf{x}_0) \int_{\mathbf{x}_{T}} q(\mathbf{x}_{T} \mid \mathbf{x}_{0}) \log \frac{q(\mathbf{x}_T\mid\mathbf{x}_0)}{p(\mathbf{x}_{T})} d\mathbf{x}_{T} d\mathbf{x}_{0} \\
&= -\int_{\mathbf{x}_{0}} q(\mathbf{x}_0) D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T})) d\mathbf{x}_{0} \\
&= -\mathbb{E}_{\mathbf{x}_0 \sim q(\mathbf{x}_0)} \bigg[D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T})) \bigg] \\
&= \mathbb{E}_{\mathbf{x}_0 \sim q(\mathbf{x}_0)} \bigg[-D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T})) \bigg]
\end{align*}$$
Similarly, although the second term is a sum of logarithms, each logarithm can be treated separately by linearity of expectation, and the variables that do not appear in it can be marginalized out from $q(\mathbf{x}_{0:T})$. Therefore, for $t = 2,\dots,T$:
$$\begin{align*} \mathbb{E}_{\mathbf{x}_{0:T}\sim q(\mathbf{x}_{0:T})}\left[\log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}\right] &= \int_{\mathbf{x}_{0:T}} q(\mathbf{x}_{0:T}) \log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}d\mathbf{x}_{0:T} \\
&= \int_{\mathbf{x}_{0}}\int_{\mathbf{x}_{t}}\int_{\mathbf{x}_{t-1}} q(\mathbf{x}_{0}, \mathbf{x}_{t-1}, \mathbf{x}_{t}) \log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}d\mathbf{x}_{t-1} d\mathbf{x}_{t} d\mathbf{x}_{0} \\
&= \int_{\mathbf{x}_{0}}\int_{\mathbf{x}_{t}} \int_{\mathbf{x}_{t-1}} q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) q( \mathbf{x}_{t}, \mathbf{x}_{0}) \log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}d\mathbf{x}_{t-1} d\mathbf{x}_{t} d\mathbf{x}_{0} \\
&= \int_{\mathbf{x}_{0}}\int_{\mathbf{x}_{t}} q( \mathbf{x}_{t}, \mathbf{x}_{0}) \int_{\mathbf{x}_{t-1}} q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \log\frac{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)}{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}d\mathbf{x}_{t-1} d\mathbf{x}_{t} d\mathbf{x}_{0} \\
&= - \int_{\mathbf{x}_{0}}\int_{\mathbf{x}_{t}} q( \mathbf{x}_{t},\mathbf{x}_{0}) \int_{\mathbf{x}_{t-1}} q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \log\frac{q(\mathbf{x}_{t-1}\mid\mathbf{x}_{t},\mathbf{x}_{0})}{p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)} d\mathbf{x}_{t-1} d\mathbf{x}_{t} d\mathbf{x}_{0} \\
&= - \int_{\mathbf{x}_{0}}\int_{\mathbf{x}_{t}} q( \mathbf{x}_{t},\mathbf{x}_{0}) D_{KL} (q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)) d\mathbf{x}_{t} d\mathbf{x}_{0} \\
&= -\mathbb{E}_{(\mathbf{x}_{t},\mathbf{x}_{0})\sim q( \mathbf{x}_{t},\mathbf{x}_{0})} \bigg[D_{KL} (q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)) \bigg] \\
&= \mathbb{E}_{(\mathbf{x}_{t},\mathbf{x}_{0})\sim q( \mathbf{x}_{t},\mathbf{x}_{0})} \bigg[-D_{KL} (q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)) \bigg]
\end{align*}$$
As a result, the lower bound on the expected log-likelihood can be rewritten as:
$$\begin{align*} \mathbb{E}_{q}[\log p(\mathbf{x}_0;\theta)] \ge \mathbb{E}_{q}\Bigg[- D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T})) - \sum_{t=2}^{T} D_{KL}(q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)) +\log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta) \Bigg] \end{align*}$$
Maximizing this lower bound is equivalent to minimizing its negative.
Following the notation in DDPM, where the training objective is a loss function to be minimized through gradient descent, the training loss $L$ for diffusion models is defined as the negative of the lower bound:
$$\begin{align*} L := \mathbb{E}_{q}\Bigg[\underbrace{D_{KL}(q(\mathbf{x}_T\mid\mathbf{x}_0) \parallel p(\mathbf{x}_{T}))}_{L_T} \;+ \sum_{t=2}^{T} \underbrace{D_{KL}(q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta)) }_{L_{t-1}} \;\; \underbrace{- \log p(\mathbf{x}_{0}\mid\mathbf{x}_{1};\theta)}_{L0} \Bigg] \end{align*}$$
DDPM decomposes the training loss $L$ into a sum of loss terms as $L=\sum_{t=0}^{T}L_t$.
and minimizing $L$ means minimizing each $L_t$ with respect to $\theta$ in this sum. Note that $L_T$ doesn't depend on $\theta$ because $q(\mathbf{x}_T\mid\mathbf{x}_0)$ has no learnable parameters and $p(\mathbf{x}_T) = \mathcal{N}(\mathbf{0},\mathbf{I})$. Therefore, $L_T$ is a constant with respect to $\theta$ during training and can be ignored in gradient descent. In addition, the linear schedule for $\beta_t$ in DDPM is set so that $q(\mathbf{x}_T\mid\mathbf{x}_0)\approx\mathcal{N}(\mathbf{0},\mathbf{I})$, and thus $L_T\approx 0$.
For $t=2,\dots,T:$
$$L_{t-1} = \mathbb{E}_{(\mathbf{x}_{t},\mathbf{x}_{0})\sim q( \mathbf{x}_{t},\mathbf{x}_{0})} \bigg[D_{KL} (q(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0}) \parallel p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)) \bigg] $$
First, the distribution $q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0)$ has a closed form. By Bayes' theorem and the Markov property, it can be written in terms of the Gaussian transition kernel and the closed form of $q(\mathbf{x}_t\mid\mathbf{x}_0)$:
$$\begin{align*}q(\mathbf{x}_{t-1}\mid\mathbf{x}_t,\mathbf{x}_0) &= \frac{q(\mathbf{x}_t\mid\mathbf{x}_{t-1},\mathbf{x}_0) q(\mathbf{x}_{t-1}\mid \mathbf{x}_0)}{q(\mathbf{x}_t\mid\mathbf{x}_0)} = \frac{q(\mathbf{x}_t\mid\mathbf{x}_{t-1}) q(\mathbf{x}_{t-1}\mid \mathbf{x}_0)}{q(\mathbf{x}_t\mid\mathbf{x}_0)}\\ \\
&= \frac{ \mathcal{N}(\mathbf{x}_t;\sqrt{1-\beta_t}\mathbf{x}_{t-1}, \beta_t\mathbf{I}) \mathcal{N}(\mathbf{x}_{t-1} ; \sqrt{\bar{\alpha}_{t-1}}\mathbf{x}_0, (1-\bar{\alpha}_{t-1})\mathbf{I})}{\mathcal{N}(\mathbf{x}_t ; \sqrt{\bar{\alpha}_t}\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I})} \\ \\
&= \mathcal{N}(\mathbf{x}_{t-1}; \tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0), \tilde{\beta}_t\mathbf{I})\\ \\
\text{where } \tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0) &:=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\mathbf{x}_0 + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t\;\;\text{and}\;\; \tilde{\beta}_t:=\frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t}\beta_t
\end{align*}$$
Recall that $\alpha_t := 1 - \beta_t$ and $\bar{\alpha}_t := \prod_{s=1}^{t}\alpha_s$.
Since the reverse Markov transition is also a Gaussian distribution, $p(\mathbf{x}_{t-1}\mid\mathbf{x}_{t};\theta) = \mathcal{N}(\mathbf{x}_{t-1};\bm{\mu}_\theta(\mathbf{x}_t,t), \bm{\Sigma}_\theta(\mathbf{x}_t, t))$, each loss term in $L_{1:T-1}$ is an expected KL divergence between Gaussian distributions.
Given two Gaussian distributions with diagonal covariance matrices, $p(\mathbf{x})=\mathcal{N}(\bm{\mu}_p, \bm{\Sigma}_p)$ and $q(\mathbf{x})=\mathcal{N}(\bm{\mu}_q,\bm{\Sigma}_q)$. Let $\bm{\Sigma}_p=\text{diag}(\sigma_{p1}^2, \dots, \sigma_{pD}^2)$ and $\bm{\Sigma}_q=\text{diag}(\sigma_{q1}^2, \dots, \sigma_{qD}^2)$, then the KL divergence between $p(\mathbf{x})$ and $q(\mathbf{x})$ has a closed form: $$D_{KL}(p(\mathbf{x})\parallel q(\mathbf{x})) = \frac{1}{2} \sum_{i=1}^{D}\left[ \log\frac{\sigma_{qi}^2}{\sigma_{pi}^2} +\frac{(\mu_{pi}-\mu_{qi})^2}{\sigma_{qi}^2} + \frac{\sigma_{pi}^2}{\sigma_{qi}^2} - 1 \right]$$ Since both the covariance matrices in $q(\mathbf{x}_{t-1}\mid\mathbf{x}_t, \mathbf{x}_0)$ and $p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)$ are diagonal, the KL divergence in each term of $L_{1:T-1}$ can be computed through the closed from above.
To further simplify training, DDPM sets the model covariance matrix to time-dependent constants, $\bm{\Sigma}_\theta(\mathbf{x}_t,t)= \sigma_t^2\mathbf{I} = \tilde{\beta}_t\mathbf{I}$ for all $t$ (another choice is $\beta_t\mathbf{I}$. Both choices had similar results according to DDPM). It is therefore independent of $\theta$, and only $\bm{\mu}_\theta$ needs to be learned. With $p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta) = \mathcal{N}(\mathbf{x}_{t-1};\bm{\mu}_\theta(\mathbf{x}_t, t), \sigma_t^2\mathbf{I})$ and the closed form of the KL divergence between Gaussian distributions, $L_{t-1}$ can be rewritten as: $$\begin{align*} L_{t-1} &= \mathbb{E}_{(\mathbf{x}_{t},\mathbf{x}_{0})\sim q( \mathbf{x}_{t},\mathbf{x}_{0})}\left[\frac{\|\tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0) - \bm{\mu}_\theta(\mathbf{x}_t, t)\|^2}{2\sigma_t^2}\right] + C \\ C &:= \frac{D}{2}\left( \log\frac{\sigma_t^2}{\tilde{\beta}_t} + \frac{\tilde{\beta}_t}{\sigma_t^2} - 1 \right) \end{align*}$$ where $\|\mathbf{z}\|^2=\sum z_i^2$ denotes the squared $\ell _{2}$-norm, and $C$ collects the remaining terms in the KL divergence that depend only on the fixed variances $\sigma_t^2$ and $\tilde\beta_t$, so $C$ is a constant with respect to $\theta$.
The expression for $L_{t-1}$ above shows that minimizing it during training pushes $\bm{\mu}_\theta$ towards $\tilde{\bm{\mu}}_t$, which motivates parameterizing $\bm{\mu}_\theta$ as a predictor of $\tilde{\bm{\mu}}_t$ for $t=2,\dots,T$.
Recall that $q(\mathbf{x}_t\mid\mathbf{x}_0)=\mathcal{N}(\mathbf{x}_t;\sqrt{\bar{\alpha}_t}\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I})$. Therefore, $\mathbf{x}_t$ can be reparameterized as a deterministic function of $\mathbf{x}_0$ and $\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$ : $$\mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}$$ This reparameterization can be interpreted as follows: $\mathbf{x}_t$ is generated by adding Gaussian noise $\bm{\epsilon}$, scaled by $ \sqrt{1-\bar{\alpha}_t}$, to the data $\mathbf{x}_0$, scaled by $\sqrt{\bar{\alpha}_t}$.
Rewriting this expression for $\mathbf{x}_0$ gives: $$ \mathbf{x}_0 = \frac{\mathbf{x}_t - \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}}{\sqrt{\bar{\alpha}_t}}$$ Substitute it into $ \tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0)$ to eliminate $\mathbf{x}_0$ :
$$\begin{align*} \tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0) &=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\mathbf{x}_0 + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t\\
&=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\left( \frac{\mathbf{x}_t - \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}}{\sqrt{\bar{\alpha}_t}} \right) + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t \\
&=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\left(\frac{\mathbf{x}_t}{\sqrt{\bar{\alpha}_t}}\right) - \frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\left( \frac{ \sqrt{1-\bar{\alpha}_t}}{\sqrt{\bar{\alpha}_t}}\bm{\epsilon} \right) + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t \\
&=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\frac{\mathbf{x}_t}{\sqrt{\bar{\alpha}_t}}+ \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t - \frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t} \frac{ \sqrt{1-\bar{\alpha}_t}}{\sqrt{\bar{\alpha}_t}}\bm{\epsilon} \\
&=\frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\frac{\mathbf{x}_t}{\sqrt{\bar{\alpha}_{t-1}\alpha_t}} + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\mathbf{x}_t - \frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{\sqrt{1-\bar{\alpha}_t}} \frac{ 1}{\sqrt{\bar{\alpha}_{t-1}\alpha_t}}\bm{\epsilon} \hspace{0.3cm}\text{recall that } \bar{\alpha}_t := \prod_{s=1}^{t}\alpha_s \\
&=\left(\frac{\beta_t}{(1-\bar{\alpha}_t)\sqrt{\alpha_t}} + \frac{\alpha_t(1-\bar{\alpha}_{t-1})}{(1-\bar{\alpha}_t)\sqrt{\alpha_t}}\right)\mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon} \\
&=\frac{\beta_t+\alpha_t -\alpha_t\bar{\alpha}_{t-1}}{(1-\bar{\alpha}_t)\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon} \\
&=\frac{\beta_t+ (1-\beta_t)-\bar{\alpha}_{t}}{(1-\bar{\alpha}_t)\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon} \hspace{0.3cm}\text{recall that } \alpha_t := 1-\beta_t \\
&=\frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon} \\
\end{align*}$$
As a result, $L_{t-1}$ is minimized when given $\mathbf{x}_t$, $\bm{\mu}_\theta(\mathbf{x}_t,t)$ predicts $\frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon}$.
The value of $\mathbf{x}_t$ is known since it is an input to the model $\bm{\mu}_\theta$, so the only unknown in this target is the noise $\bm{\epsilon}$ that was added to $\mathbf{x}_0$ to produce the given $\mathbf{x}_t$. This motivates DDPM to introduce a noise predictor $\bm{\epsilon}_\theta$ and to parameterize $\bm{\mu}_\theta$ in terms of it:
$$\bm{\mu}_\theta(\mathbf{x}_t,t) = \frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon}_\theta(\mathbf{x}_t, t)$$
where $\bm{\epsilon}_\theta(\mathbf{x}_t, t)$ is a model that takes $\mathbf{x}_t$ and the time step $t$ as inputs and predicts the added noise $\bm{\epsilon}$.
With the reparameterization of $\mathbf{x}_t=\sqrt{\bar{\alpha}_t}\,\mathbf{x}_0+\sqrt{1-\bar{\alpha}_t}\,\bm{\epsilon}$ in mind, expressing $L_{t-1}$ in terms of $\bm{\epsilon}_\theta$ gives the training loss for the noise predictor: $$\begin{align*}L_{t-1} - C &= \mathbb{E}_{(\mathbf{x}_{t},\mathbf{x}_{0})\sim q( \mathbf{x}_{t},\mathbf{x}_{0})}\left[\frac{\|\tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0) - \bm{\mu}_\theta(\mathbf{x}_t, t)\|^2}{2\sigma_t^2}\right] \\ &= \mathbb{E}_{\mathbf{x}_{0}\sim q( \mathbf{x}_{0}), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[\frac{1}{2\sigma_t^2}\Big\|\big(\frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon}\big) - \big( \frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon}_\theta(\mathbf{x}_t, t)\big)\Big\|^2\right] \\ &= \mathbb{E}_{\mathbf{x}_{0}\sim q( \mathbf{x}_{0}), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[\frac{1}{2\sigma_t^2}\Big\| - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}} \big( \bm{\epsilon} - \bm{\epsilon}_\theta(\mathbf{x}_t, t)\big)\Big\|^2\right] \\ &= \mathbb{E}_{\mathbf{x}_{0}\sim q( \mathbf{x}_{0}), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[\frac{\beta_t^2}{2\sigma_t^2(1-\bar{\alpha}_t)\alpha_t}\Big\| \bm{\epsilon} - \bm{\epsilon}_\theta(\mathbf{x}_t, t)\Big\|^2\right] \\ &= \mathbb{E}_{\mathbf{x}_{0}\sim q( \mathbf{x}_{0}), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[\frac{\beta_t^2}{2\sigma_t^2(1-\bar{\alpha}_t)\alpha_t}\Big\| \bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t)\Big\|^2\right] \end{align*}$$
To summarize, with the model covariance $\bm{\Sigma}_\theta$ fixed to time-dependent constants $\sigma_t^2\mathbf{I}$ for all $t$, the reverse transition $p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta)$ for $t= 2,\dots,T$ can be trained either as a
mean predictor $\bm{\mu}_\theta(\mathbf{x}_t, t)$ to predict $\tilde{\bm{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0)$, or as a
noise predictor $ \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t)$ to predict $\bm{\epsilon}$ under the reparameterization of $\mathbf{x}_t$.
In DDPM, image data $\mathbf{x}_0$ is assumed to consist of integers in $\{0,1,\dots,255\}$ and is scaled linearly to $[-1, 1]$ before fed into the model, by the operation:
$$x \leftarrow \frac{x}{127.5}-1$$
Recall that $$L_0 := \mathbb{E}_{\mathbf{x}_0,\mathbf{x_1}\sim q(\mathbf{x}_0,\mathbf{x}_1)}\left[-\log p(\mathbf{x}_0\mid\mathbf{x}_1;\theta)\right]$$
Notice that the image data $\mathbf{x}_0$ is discrete, whereas $\mathcal{N}(\mathbf{x}_0; \bm{\mu}_\theta(\mathbf{x}_1, 1), \sigma_1^2\mathbf{I})$ is a continuous Gaussian distribution. To obtain a log-likelihood of discrete random variables $\mathbf{x}_0$, DDPM defines a discrete decoder $p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta)$ to assign probability from $\mathcal{N}(\mathbf{x}_0; \bm{\mu}_\theta(\mathbf{x}_1, 1), \sigma_1^2\mathbf{I})$ as follows:
$$\begin{align*}p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta) &= \prod_{i=1}^D \int_{\delta_-(x_0^i)}^{\delta_+(x_0^i)}\mathcal{N}\left(x; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right)dx \\
\delta_+(x) &= \begin{cases} \infty & \text{if } x = 1 \\ x+\frac{1}{255} & \text{if } x < 1 \end{cases} \hspace{1cm} \delta_-(x) = \begin{cases} -\infty & \text{if } x = -1 \\ x-\frac{1}{255} & \text{if } x > -1 \;\; \end{cases}
\end{align*}$$
where $D$ denotes the data dimensionality, i.e., the total number of pixels in the image.
The equation above converts the continuous Gaussian distribution $\mathcal{N}(\mathbf{x}_0; \bm{\mu}_\theta(\mathbf{x}_1, 1), \sigma_1^2\mathbf{I})$ into a discrete probability distribution $p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta) $. For each discrete pixel values
$x_0^i \in [-1, 1]$ of $\mathbf{x}_0$, the Gaussian is integrated over a small interval, or bin, around it, and the resulting probabilities are multiplied across all $D$ to give the probability of $\mathbf{x}_0$.
The resulting negative discrete log-likelihood is:
$$\begin{align*}
-\log p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta) &= -\log\left( \prod_{i=1}^D \int_{\delta_-(x_0^i)}^{\delta_+(x_0^i)}\mathcal{N}\left(x; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right)dx \right) \\
&= - \sum_{i=1}^D \log\left( \int_{\delta_-(x_0^i)}^{\delta_+(x_0^i)}\mathcal{N}\left(x; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right)dx \right) \\
&\approx - \sum_{i=1}^D \log\left( \frac{2}{255} \mathcal{N}\left(x_0^i; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right) \right) \;(*)\\
&\approx - \sum_{i=1}^D\left( \log\frac{2}{255} +\log \mathcal{N}\left(x_0^i; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right) \right) \\
&\approx - (\log\frac{2}{255})D - \sum_{i=1}^D \log \mathcal{N}\left(x_0^i; {\mu}_\theta^i(\mathbf{x}_1, 1), \sigma_1^2\right) \\
&\approx - (\log\frac{2}{255})D - \sum_{i=1}^D \log\left(\frac{1}{\sqrt{2\pi\sigma_1^2}}\exp\Big(-\frac{\big(x_0^i - \mu_\theta^i(\mathbf{x}_1, 1)\big)^2}{2\sigma_1^2}\Big) \right) \\
&\approx - (\log\frac{2}{255})D - \sum_{i=1}^D \left(\log\frac{1}{\sqrt{2\pi\sigma_1^2}}-\frac{\big(x_0^i - \mu_\theta^i(\mathbf{x}_1, 1)\big)^2}{2\sigma_1^2}\right) \\
&\approx - (\log\frac{2}{255})D - (\log\frac{1}{\sqrt{2\pi\sigma_1^2}})D + \sum_{i=1}^D \frac{\big(x_0^i - \mu_\theta^i(\mathbf{x}_1, 1)\big)^2}{2\sigma_1^2} \\
&\approx - (\log\frac{2}{255})D - (\log\frac{1}{\sqrt{2\pi\sigma_1^2}})D + \frac{\sum_{i=1}^D\big(x_0^i - \mu_\theta^i(\mathbf{x}_1, 1)\big)^2}{2\sigma_1^2} \\
&\approx - (\log\frac{2}{255})D - (\log\frac{1}{\sqrt{2\pi\sigma_1^2}})D + \frac{\big\|\mathbf{x}_0 - \bm{\mu}_\theta(\mathbf{x}_1, 1)\big\|^2}{2\sigma_1^2} \\
&\approx \frac{\big\|\mathbf{x}_0 - \bm{ \mu}_\theta(\mathbf{x}_1, 1)\big\|^2}{2\sigma_1^2} + C_2 \qquad \text{where } C_2:=(\log\frac{255\sqrt{2\pi\sigma_1^2}}{2})D \\
\end{align*}$$
$C_2$ collects the remaining terms that depend only on the fixed variance $\sigma_1^2$, so $C_2$ is a constant with respect with $\theta$.
$(*)$ For a small bin width, the integral of a smooth probability density function, such as Gaussian, over a bin can be approximated by the product of the bin width and the density value at the center. For the $p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta)$ defined above, the bin width is $\frac{2}{255}$. In addition, the edge effects at $x_0^i=\pm 1$ are also ignored in this approxiamtion.
Therefore, the $L_0$ can be approximated by:
$$\begin{align*}L_0 &:= \mathbb{E}_{\mathbf{x}_0,\mathbf{x_1}\sim q(\mathbf{x}_0,\mathbf{x}_1)}\left[-\log p(\mathbf{x}_0\mid\mathbf{x}_1;\theta)\right] \\
&\approx \mathbb{E}_{\mathbf{x}_0,\mathbf{x_1}\sim q(\mathbf{x}_0,\mathbf{x}_1)}\left[ \frac{\big\|\mathbf{x}_0 - \bm{\mu}_\theta(\mathbf{x}_1, 1)\big\|^2}{2\sigma_1^2} \right]+ C_2 \end{align*}$$
This shows that $L_0$ is minimized when given $\mathbf{x}_1$, $\bm{\mu}_\theta(\mathbf{x}_1,1)$ predicts the denoised data $\mathbf{x}_0$, which motivates the parameterization $\bm{\mu}_\theta(\mathbf{x}_1,1)$ as a predictor of $\mathbf{x}_0$.
Similarly, $\mathbf{x}_1 $ can be reparameterized as a deterministic function of $\mathbf{x}_0$ and $\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$:
$$\begin{align*}\mathbf{x}_1&=\sqrt{\bar{\alpha}_1}\mathbf{x}_0+\sqrt{1-\bar{\alpha}_1}\bm{\epsilon}\\
&= \sqrt{\alpha}_1\mathbf{x}_0+\sqrt{1-\alpha}_1\bm{\epsilon} \hspace{0.3cm}\text{recall that } \bar{\alpha}_t := \prod_{s=1}^{t}\alpha_s\\
\end{align*}$$
Rewriting this expression for $\mathbf{x}_0$ gives:
$$\begin{align*} \mathbf{x}_0 &= \frac{1}{\sqrt{\alpha}_1}\mathbf{x}_1 - \frac{\sqrt{1-\alpha_1}}{\sqrt{\alpha}_1}\bm{\epsilon} \\
&= \frac{1}{\sqrt{\alpha}_1}\mathbf{x}_1 - \frac{\sqrt{\beta}_1}{\sqrt{\alpha}_1}\bm{\epsilon} \hspace{0.3cm}\text{recall that } \alpha_t := 1 - \beta_t\\
&= \frac{1}{\sqrt{\alpha}_1}\mathbf{x}_1 - \frac{\beta_1}{\sqrt{\beta_1\alpha}_1}\bm{\epsilon} \\
&= \frac{1}{\sqrt{\alpha}_1}\mathbf{x}_1 - \frac{\beta_1}{\sqrt{(1-\alpha_1)\alpha}_1}\bm{\epsilon}
\end{align*}$$
Parameterizing $\bm{\mu}_\theta(\mathbf{x}_1, 1)$ in terms of $\bm{\epsilon}_\theta$ in the same way as $\bm{\mu}_\theta(\mathbf{x}_t,t)$ in $L_{1:T-1}$ gives:
$$\begin{align*}\bm{\mu}_\theta(\mathbf{x}_1, 1) &= \frac{1}{\sqrt{\alpha_1}} \mathbf{x}_1 - \frac{\beta_1}{\sqrt{(1-\bar{\alpha}_1)\alpha_1}}\bm{\epsilon}_\theta(\mathbf{x}_1, 1) \\
&= \frac{1}{\sqrt{\alpha_1}} \mathbf{x}_1 - \frac{\beta_1}{\sqrt{(1- \alpha_1)\alpha_1}}\bm{\epsilon}_\theta(\mathbf{x}_1, 1)
\end{align*}$$
Plugging the parameterization of $\bm{\mu}_\theta(\mathbf{x}_1, 1)$ in terms of $\bm{\epsilon}_\theta$ and the reparameterization of $\mathbf{x}_1$ into the approximation of $L_0$ above gives:
$$\begin{align*}L_0 - C_2 &\approx \mathbb{E}_{\mathbf{x}_0,\mathbf{x_1}\sim q(\mathbf{x}_0,\mathbf{x}_1)}\left[ \frac{\big\|\mathbf{x}_0 - \bm{\mu}_\theta(\mathbf{x}_1, 1)\big\|^2}{2\sigma_1^2} \right] \\
&\approx \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[ \frac{1}{2\sigma_1^2}\Big\| \big( \frac{1}{\sqrt{\alpha}_1}\mathbf{x}_1 - \frac{\beta_1}{\sqrt{(1-\alpha_1)\alpha}_1}\bm{\epsilon} \big) - \big(\frac{1}{\sqrt{\alpha_1}} \mathbf{x}_1 - \frac{\beta_1}{\sqrt{(1- \alpha_1)\alpha_1}}\bm{\epsilon}_\theta(\mathbf{x}_1, 1)\big) \Big\|^2\right] \\
&\approx \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[ \frac{\beta_1^2}{2\sigma_1^2(1- \alpha_1)\alpha_1}\Big\| \big(\bm{\epsilon} - \bm{\epsilon}_\theta(\mathbf{x}_1, 1)\big) \Big\|^2\right] \\
&\approx \mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0), \bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})}\left[ \frac{\beta_1^2}{2\sigma_1^2(1- \alpha_1)\alpha_1}\Big\| \big(\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\alpha}_1\mathbf{x}_0+\sqrt{1-\alpha}_1\bm{\epsilon}, 1)\big) \Big\|^2\right] \\
\end{align*}$$
When $\mathbf{x}_t$ is reparameterized in terms of $\mathbf{x}_0$ and $\bm{\epsilon}$, and $\bm{\mu}_\theta$ is parameterized in terms of a noise predictor $\bm{\epsilon}_\theta$, this approximation of $L_0$ takes the same form as $L_{t-1}$ evaluated at $t=1$, once the constants $C$ and $C_2$ are ignored. (Recall that $L_{t-1}$ is defined only for $t=2,\dots,T$. )
The shared form of $L_{1:T-1}$ and the approximation of $L_0$ for $\bm{\epsilon}$-prediction motivates DDPM to define a simplified training loss function, which is not only simplier to implement but also yields high-quality images when models are trained with it:
$$L_{\text{simple}}(\theta):=\mathbb{E}_{t,\mathbf{x}_0, \bm{\epsilon}}\bigg[ \Big\|\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t) \Big\|^2\bigg]$$
where $t\sim\mathcal{U}\{1,2,\dots,T\}$ follows a discrete uniform distribution, $\mathbf{x}_0\sim q(\mathbf{x}_0)$,
$\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$, and $\|\cdot\|^2$ is the squared $\ell _{2}$-norm.
For $t>1$, $L_{\text{simple}}$ corresponds to an unweighted version of the loss terms in $L_{1:T-1}$.
For $t=1$, $L_{\text{simple}}$ corresponds to an unweighted version of the approximation of $L_0$.
The simplified training loss $L_{\text{simple}}$ is a plain mean squared error loss on the $\bm{\epsilon}$-prediction.
$L_{\text{simple}}$ drops the weighting terms in $L_{1:T-1}$ and in the approximation of $L_0$, making it a re-weighted version of the lower bound on the expected log-likelihood that emphasizes different denoising terms compared to the original lower bound.
The experimental setup in DDPM, $T=1000$ and increasing $\beta_1=10^{-4}$ linearly to $\beta_T=0.02$, lets $L_{\text{simple}}$ down-weight the loss terms corresponding to small $t$. When $t$ is small, the amount of the noise $\bm{\epsilon}$ added to the data $\mathbf{x}_0$, whose scale is controlled by $\sqrt{1-\bar{\alpha}_t}$, is also small, so the loss terms with small $t$ train the model to denoise data containing only a very small amount of noise. As a result, training the model with $L_{\text{simple}}$ encourages it to focus on the noisier, more challenging data at larger $t$. DDPM reports its best sample quality when training with $L_{\text{simple}}$.
To run the reverse process, for $t\in\{T,\cdots,2\}$, sampling $\mathbf{x}_{t-1} \sim p(\mathbf{x}_{t-1}\mid\mathbf{x}_t;\theta) = \mathcal{N}(\mathbf{x}_{t-1};\bm{\mu}_\theta(\mathbf{x}_t, t), \sigma_t^2\mathbf{I})$ given $\mathbf{x}_t$ is the same as computing
$$\mathbf{x}_{t-1} = \bm{\mu}_\theta(\mathbf{x}_t, t) + \sigma_t\mathbf{z} = \frac{1}{\sqrt{\alpha_t}} \mathbf{x}_t - \frac{\beta_t}{\sqrt{(1-\bar{\alpha}_t)\alpha_t}}\bm{\epsilon}_\theta(\mathbf{x}_t, t) + \sigma_t\mathbf{z}$$
where $\mathbf{z}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$.
For reconstructing $\mathbf{x}_0$ from $\mathbf{x}_1$, recalls that in the analysis of $L_0$: $$-\log p(\mathbf{x}_0 \mid \mathbf{x}_1;\theta) \approx \frac{\big\|\mathbf{x}_0 - \bm{ \mu}_\theta(\mathbf{x}_1, 1)\big\|^2}{2\sigma_1^2} + C_2$$
The $L_0$ loss term is minimized when $\bm{ \mu}_\theta(\mathbf{x}_1, 1)\approx\mathbf{x}_0$. Therefore, $\mathbf{x}_0$ can be reconstructed by setting it to $\bm{ \mu}_\theta(\mathbf{x}_1, 1)$ directly.
Though the mathematical theory behind DDPM is complex, the simplified training loss$L_\text{simple}$ makes the model relatively easy to train. The algorithms below present the complete training and sampling procedures using $L_{\text{simple}}$, along with a simple illustration of the training procedure.


This subsection will first briefly introduce another paradigm for generative modeling: score-based generative modeling, proposed in Generative Modeling by Estimating Gradients of the Data Distribution (often referred to as denoising Score Matching with Langevin dynamics (SMLD)), and then discuss its relationship with DDPM.
SMLD first perturbs the data distribution $p(\mathbf{x})$ with multiple isotropic Gaussian noise distributions. Consider a total of $L$ noise distributions $\mathcal{N}(\mathbf{0}, \sigma_i^2\mathbf{I})$ with different noise scales $\sigma_i$ such that $\sigma_1<\sigma_2<\dots<\sigma_L$, where both $L$ and $\sigma_i$ are hyperparameters.
The data distribution $p(\mathbf{x})$ is perturbed with each of the isotropic Gaussian noise $\mathcal{N}(\mathbf{0}, \sigma_i^2\mathbf{I})$ by adding the noise to the data. Therefore, $\mathbf{x}_i=\mathbf{x}+\sigma_i\bm{\epsilon}, \text{ where } \bm{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})$. This gives a sequence of conditional noise distributions $p(\mathbf{x}_i\mid\mathbf{x}) = \mathcal{N}(\mathbf{x}_i;\mathbf{x}, \sigma_i^2\mathbf{I})$, and their marginal densities, referred to as noise-perturbed data distributions, can be obtained by $p(\mathbf{x}_i) = \int_\mathbf{x} p(\mathbf{x}_i\mid\mathbf{x})p(\mathbf{x})d\mathbf{x}$.
Note that unlike in diffusion models, the noising process in SMLD is not a Markov Chain, and thus there is no notion of a time step. As a resut, the noised data $\mathbf{x}_i$ is marked with the underscript $i$ rather than $t$ to emphasize the difference.
SMLD then trains a score network $s_\theta(\mathbf{x}_i, \sigma_i)$ to model the score functions for all noise-perturbed data distributions $p(\mathbf{x}_i)$, using a denoising score matching (DSM) objective that relies on the score functions of the conditional noise distributions $p(\mathbf{x}_i\mid\mathbf{x})$.
The score (function) of a probability density $q(\mathbf{x})$ is defined as the gradient of the $\log q(\mathbf{x})$ with respect to input vector $\mathbf{x}$: $\nabla_{\mathbf{x}}\log q(\mathbf{x})$.
The denoising scoring matching (DSM) objective in SMLD is :
$$\begin{align*}L_{\text{DSM}}&=\frac{1}{L}\sum_{i=1}^{L}\frac{\sigma_i^2}{2}\mathbb{E}_{\mathbf{x}\sim p(\mathbf{x}),\, \mathbf{x}_i\sim p(\mathbf{x}_i\mid \mathbf{x})}\bigg[\Big\|s_\theta(\mathbf{x}_i, \sigma_i) - \nabla_{\mathbf{x}_i} \log p(\mathbf{x}_i\mid\mathbf{x})\Big\|^2\bigg] \\
&=\frac{1}{2L}\sum_{i=1}^{L}\sigma_i^2\mathbb{E}_{\mathbf{x}\sim p(\mathbf{x}),\, \mathbf{x}_i\sim p(\mathbf{x}_i\mid \mathbf{x})}\bigg[\Big\|s_\theta(\mathbf{x}_i, \sigma_i) - \nabla_{\mathbf{x}_i} \log p(\mathbf{x}_i\mid\mathbf{x})\Big\|^2\bigg]
\end{align*} $$
The optimal score network that minimizes $L_{\text{DSM}}$ satisfies $s_{\theta^*}(\mathbf{x}_i, \sigma_i) = \nabla_{\mathbf{x}_i}\log p(\mathbf{x}_i)$ almost surely for all $i\in\{1,2,\dots,L\}$.
To sample from the data distribution $p(\mathbf{x})$ using the optimal score network $s_{\theta^*}$, SMLD proposes an annealed Langevin dynamics to generate samples $\mathbf{x} \sim p(\mathbf{x})$ using only $\nabla_{\mathbf{x}_i}\log p(\mathbf{x}_i)$, that is, the score functions of the noise-perturbed data distributions $p(\mathbf{x}_i)$.
Annealed Langevin dynamics is an MCMC (Markov Chain Monte Carlo)-based method that runs a Markov chain which, in the long run, produces samples from the data distribution $p(\mathbf{x})$ using only the score functions of $p(\mathbf{x}_i)$ from $i=L, L-1,\dots, 1$. Because the chain moves from high to low noise scales $\sigma_i$ in this order, it resembles the reverse process in diffusion models.
For a tutorial and details about score-based generative models, I highly recommend this blog post written by Yong Song. Readers who are not familiar with score functions at all can start with this tutorial before diving in to the paper.
A detailed comparison between DDPM and SMLD can be found in this paper. In the rest of this section, I will show that any $\bm{\epsilon}_\theta$ trained with $L_{\text{simple}}$ is a parameterization of an $\mathbf{s}_\theta$ trained with a particular configuration of $L_{\text{DSM}}$, so every such $\bm{\epsilon}_\theta$ always has a corresponding $s_\theta$ . Since any of such learned $\bm{\epsilon}_\theta$ can be converted into $s_\theta$, $\bm{\epsilon}_\theta$ can also be used to estimate the score of $p(\mathbf{x}_t)$, i.e., $\nabla_{\mathbf{x}_t}\log p(\mathbf{x}_t)$, where $p(\mathbf{x}_t)$ corresponds to the marginal density of the noised data $\mathbf{x}_t$ at time step $t.$
Recall that $L_{\text{simple}}$ is defined as:
$$L_{\text{simple}}(\theta):=\mathbb{E}_{t,\mathbf{x}_0, \bm{\epsilon}}\bigg[ \Big\|\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t) \Big\|^2\bigg]$$
where $t\sim\mathcal{U}\{1,2,\dots,T\}$ follows a discrete uniform distribution, $\mathbf{x}_0\sim q(\mathbf{x}_0)$ follows the data distribution, and $\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$.
Given a univariate Gaussian distribution $p(x) = \mathcal{N}(\mu, \sigma^2)$, its score function $\nabla_x \log p(x)$ is:
$$\begin{align*}\nabla_x \log p(x) &= \nabla_x \log \left[\frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(\frac{(x-\mu)^2}{-2\sigma^2}\right) \right] \\
&= \nabla_x \left[\log \frac{1}{\sqrt{2\pi\sigma^2}}+\frac{(x-\mu)^2}{-2\sigma^2} \right] \\
&= \nabla_x \log \frac{1}{\sqrt{2\pi\sigma^2}}+ \nabla_x \frac{(x-\mu)^2}{-2\sigma^2} \\
&= \nabla_x \frac{(x-\mu)^2}{-2\sigma^2} \\
&= \frac{2(x-\mu)}{-2\sigma^2} \\
&= \frac{\mu-x}{\sigma^2}
\end{align*}$$
Recall that $q(\mathbf{x}_t\mid\mathbf{x}_0)=\mathcal{N}(\mathbf{x}_t;\sqrt{\bar{\alpha}_t}\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I})$, and thus its score function is:
$$\begin{align*}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) &= \frac{\sqrt{\bar{\alpha}_t}\mathbf{x}_0-\mathbf{x}_t}{ 1-\bar{\alpha}_t} \\
&= \frac{\sqrt{\bar{\alpha}_t}\mathbf{x}_0- ( \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon})}{ 1-\bar{\alpha}_t} \qquad\text{reparameterize } \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon} \\
&= \frac{- \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}}{ 1-\bar{\alpha}_t} \\
&= \frac{- \bm{\epsilon}}{ \sqrt{1-\bar{\alpha}_t}}
\end{align*}$$
Rewrite $L_\text{simple}$ as follows:
$$\begin{align*}L_{\text{simple}} &=\mathbb{E}_{t,\mathbf{x}_0, \bm{\epsilon}}\bigg[ \Big\|\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t) \Big\|^2\bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0, \bm{\epsilon}}\bigg[ \Big\|\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t) \Big\|^2\bigg] \qquad t\sim\mathcal{U}\{1,2,\dots,T\} \text{ (discrete uniform distribution)} \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\Bigg[ \bigg\|\Big( -\sqrt{1-\bar{\alpha}_t}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)\Big) - \bm{\epsilon}_\theta(\mathbf{x}_t, t) \bigg\|^2\Bigg] \\
\end{align*}$$
Notice that $ L_{\text{simple}}$ is minimized when given $\mathbf{x}_t$, $\bm{\epsilon}_\theta$ predicts $ -\sqrt{1-\bar{\alpha}_t}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)$, and the only unknown in this target is $\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)$, that is, the score of $q(\mathbf{x}_t\mid\mathbf{x}_0)$.
Déjà vu, right?
Let's introduce a score estimator $s_\theta$ for $\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)$ and parameterize $\bm{\epsilon}_\theta$ in terms of it:
$$\bm{\epsilon}_\theta(\mathbf{x}_t, t) = -\sqrt{1-\bar{\alpha}_t}s_\theta(\mathbf{x}_t, t)$$
Plugging this parameterization of $\bm{\epsilon}_\theta$ into the $ L_{\text{simple}}$ above:
$$\begin{align*}L_{\text{simple}} &=\mathbb{E}_{t,\mathbf{x}_0, \bm{\epsilon}}\bigg[ \Big\|\bm{\epsilon} - \bm{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}, t) \Big\|^2\bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\Bigg[ \bigg\|\Big( -\sqrt{1-\bar{\alpha}_t}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)\Big) - \bm{\epsilon}_\theta(\mathbf{x}_t, t) \bigg\|^2\Bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\Bigg[ \bigg\|\Big( -\sqrt{1-\bar{\alpha}_t}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)\Big) - \Big(-\sqrt{1-\bar{\alpha}_t}s_\theta(\mathbf{x}_t, t)\Big) \bigg\|^2\Bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\Bigg[ \bigg\|-\sqrt{1-\bar{\alpha}_t}\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) + \sqrt{1-\bar{\alpha}_t}s_\theta(\mathbf{x}_t, t) \bigg\|^2\Bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\Bigg[ \bigg\|\sqrt{1-\bar{\alpha}_t}\Big(- \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) + s_\theta(\mathbf{x}_t, t)\Big) \bigg\|^2\Bigg] \\
&=\frac{1}{T}\sum_{t=1}^{T}(1-\bar{\alpha}_t)\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\bigg[ \Big\|s_\theta(\mathbf{x}_t, t) - \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) \Big\|^2\bigg]
\end{align*}$$
Let's compare the $L_{\text{simple}}$ above with $L_{\text{DSM}}$: $$\begin{align*} L_{\text{simple}} &=\frac{1}{T}\sum_{t=1}^{T}(1-\bar{\alpha}_t)\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\bigg[ \Big\|s_\theta(\mathbf{x}_t, t) - \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) \Big\|^2\bigg] \\ \\ &\qquad \theta^*_\text{simple} = \argmin_\theta\sum_{t=1}^{T}(1-\bar{\alpha}_t)\mathbb{E}_{\mathbf{x}_0\sim q(\mathbf{x}_0),\, \mathbf{x}_t\sim q(\mathbf{x}_t\mid\mathbf{x}_0))}\bigg[ \Big\|s_\theta(\mathbf{x}_t, t) - \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0) \Big\|^2\bigg] \\ \\ L_{\text{DSM}}&=\frac{1}{2L}\sum_{i=1}^{L}\sigma_i^2\mathbb{E}_{\mathbf{x}\sim p(\mathbf{x}),\, \mathbf{x}_i\sim p(\mathbf{x}_i\mid \mathbf{x})}\bigg[\Big\|s_\theta(\mathbf{x}_i, \sigma_i) - \nabla_{\mathbf{x}_i} \log p(\mathbf{x}_i\mid\mathbf{x})\Big\|^2\bigg] \\ \\ &\qquad \theta^*_\text{DSM} = \argmin_\theta \sum_{i=1}^{L}\sigma_i^2\mathbb{E}_{\mathbf{x}\sim p(\mathbf{x}),\, \mathbf{x}_i\sim p(\mathbf{x}_i\mid \mathbf{x})}\bigg[\Big\|s_\theta(\mathbf{x}_i, \sigma_i) - \nabla_{\mathbf{x}_i} \log p(\mathbf{x}_i\mid\mathbf{x})\Big\|^2\bigg] \end{align*}$$
| $L_{\text{simple}}$ (for score estimator $s_\theta$) | $L_{\text{DSM}}$ |
|---|---|
| $T$ is the total diffusion time step. | $L$ is the total number of perturbing noise. |
| $(1-\bar{\alpha}_t)$ is the isotropic variance of $q(\mathbf{x}_t\mid\mathbf{x}_0)=\mathcal{N}(\mathbf{x}_t;\sqrt{\bar{\alpha}_t}\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I})$. |
$\sigma_i^2$ is the isotropic variance of $p(\mathbf{x}_i\mid\mathbf{x}) = \mathcal{N}(\mathbf{x}_i;\mathbf{x}, \sigma_i^2\mathbf{I})$. |
| $q(\mathbf{x}_0)$ is the data distribution. | $p(\mathbf{x})$ is the data distribution. |
| $\nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t\mid\mathbf{x}_0)= \frac{- \bm{\epsilon}}{ \sqrt{1-\bar{\alpha}_t}} $ | $\nabla_{\mathbf{x}_t}\log p(\mathbf{x}_i\mid\mathbf{x})= \frac{- \bm{\epsilon}}{ \sqrt{\sigma_i^2}} $ |
Therefore, $\theta^*_{\text{simple}}=\theta^*_{\text{DSM}}$ when $L=T$ and $p(\mathbf{x}_i\mid\mathbf{x})=q(\mathbf{x}_t\mid\mathbf{x}_0)$ (where $i=t$ and $p(\mathbf{x}) = q(\mathbf{x}_0)$).
Just as the optimal score network trained with $L_{\text{DSM}}$ satisfies $s_{\theta^*_{\text{DSM}}}(\mathbf{x}_i, \sigma_i) = \nabla_{\mathbf{x}_i}\log p(\mathbf{x}_i)$ almost surely for all $i\in\{1,2,\dots,L\}$, the optimal score estimator trained with $L_{\text{simple}}$ satisfies $s_{\theta^*_{\text{simple}}}(\mathbf{x}_t, t) = \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t)$ almost surely for all $t\in\{1,2,\dots,T\}$.
As a result, a well-trained $\bm{\epsilon}_\theta$ using $L_{\text{simple}}$ for $\bm{\epsilon}$-prediction can be converted into both the mean predictor $\bm{\mu}_\theta(\mathbf{x}_t, t)$ for the reverse Markov transition $p(\mathbf{x}_{t-1}\mid\mathbf{x}_t)=\mathcal{N}(\mathbf{x}_{t-1}; \bm{\mu}_\theta(\mathbf{x}_t, t), \sigma_t^2\mathbf{I})$ and the score estimator $s_\theta(\mathbf{x}_t, t)$ for $ \nabla_{\mathbf{x}_t}\log q(\mathbf{x}_t)$, the score of the marginal density $q(\mathbf{x}_t)$ at time step $t$.
The most direct way to control generation is to directly train the diffusion models with conditioning information $y$, such as a text prompt, turning the generative model distribution $p(\mathbf{x}_{0:T};\theta) $ into a conditional generative model distribution: $$p(\mathbf{x}_{0:T}\mid y;\theta) = p(\mathbf{x}_T)\prod_{t=1}^Tp(\mathbf{x}_{t-1}\mid\mathbf{x}_t, y; \theta)$$
DALL·E 2, which was introduced and explained at a high level in the previous post, is a successor to DALL·E. It replaces the discrete VAE and the autoregressive Transformer in DALL·E with a two-stage architecture consisting of a diffusion prior and a diffusion decoder, both of which are diffusion models.
The training dataset for DALL·E 2 consists of image-caption pairs. During the entire training procedure, given a pair of image $x$ and caption $y$, a frozen CLIP model is used to compute the CLIP image embedding $\mathbf{z}_i$ and the CLIP text embedding $\mathbf{z}_t$,
The training goals for the diffusion prior and diffusion decoder are as follows:
Stacking the diffusion decoder and the diffusion prior defines the conditional generative model $p(x \mid y)$ in DALL·E 2:
$$p(x\mid \mathbf{z}_i, y)p(\mathbf{z}_i\mid y)= p(x, \mathbf{z}_i\mid y) = p(x\mid y)$$
Because $\mathbf{z}_i$ is the output of the CLIP image encoder that takes only $x$ as input, it is a deterministic function of $x$. Knowing the value of $x$ therefore determines the value of $\mathbf{z}_i$, which means $p(x, \mathbf{z}_i)=p(x)$, with or without conditioning on $y$.
After training is complete, DALL·E 2 can generate an image that matches a given caption by first predicting the corresponding CLIP image embedding from the caption with the diffusion prior, and then generating an image from the predicted CLIP image embedding with the diffusion decoder. The entire generative process can be viewed as reversing the process of the CLIP image encoder, and thus the full stack is referred to as unCLIP in the paper.
DALL·E 2 uses a Gaussian diffusion model to model the CLIP image embedding $\mathbf{z}_i$ directly. In addition to the caption $y$, DALL·E 2 also conditions the diffusion prior on the CLIP text embedding $\mathbf{z}_t$, because it is a deterministic function of the caption $y$.
To improve sample fidelity for the diffusion prior, DALL·E 2 adopts the Classifier-Free Diffusion Guidance technique, which will be introduced in the final subsection.
The diffusion prior is a Transformer decoder with a causal attention mask. The input to the diffusion prior consists of, in order : the encoded caption generated by a frozen text encoder (e.g., Transformer decoder), the CLIP text embedding $\mathbf{z}_t$, the diffusion time step $ts$, the noised CLIP image embedding $\mathbf{z}_i^{(ts)}$, and a learnable embedding $\mathbf{e}_{\text{query}}$ whose state at the output of the model serves as the prediction of the denoised CLIP image embedding (this is similar to BERT’s [class] token).
Instead of training the diffusion prior with the $L_\text{simple}$ loss to predict the added Gaussian noise $\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$ on $\mathbf{z}_i$, DALL·E 2 found it better to train the model to directly predict the unnoised $\mathbf{z}_i$ and use mean squared error loss on the prediction.
The diffusion decoder model is trained to generate images conditioned on the CLIP image embeddings $\mathbf{z}_i$ (and optionally the caption $y$), and it also uses Classifier-Free Diffusion Guidance to improve sample fidelity. The architecture of the diffusion decoder is based on GLIDE , a text-conditional diffusion model, with modifications that allow it to condition on the CLIP image embedding $\mathbf{z}_i$ as well.
GLIDE adopts the architecture of the Ablated Diffusion Model (ARM), which was proposed as an unconditional diffusion model, and modifies it so that it can condition on texts by using a Transformer to encode the caption $y$ into a sequence of text token vectors.
To enable the GUIDE architecture to condition on the CLIP image embedding $\mathbf{z}_i$, the diffusion decoder projects the CLIP image embedding $\mathbf{z}_i$ into four extra token vectors and concatenates them to the sequence of the text tokens vectors output by the Transformer. In addition, the CLIP image embedding $\mathbf{z}_i$ is also projected into the same dimensionality of the diffusion time step $t$ embedding and added to it element-wise.
Note that the diffusion prior and diffusion decoder are trained independently, and the diffusion decoder is conditioned on the ground-truth CLIP image embedding $\mathbf{z}_i$ during training.

For high-resolution image generation tasks, running the diffusion process directly in pixel space is computationally expensive. Latent Diffusion Model (LDM), also known as stable diffusion, proposes a perceptual compression model to learn a low-dimensional latent space that is perceptually equivalent to the pixel space. The diffusion model then operates on the learned latent space during training and sampling. Therefore, LDM is a two-stage image synthesis approach, where the perceptual compression model is pretrained and kept frozen during the training of the diffusion model.
The perceptual compression model is an autoencoder model that consists of an encoder model $\mathcal{E}$, and a decoder model $\mathcal{D}$. Given an image $x\in\mathbb{R}^{H\times W\times 3}$ in RGB space, where $H$ and $W$ denote the height and width of the image, the encoder $\mathcal{E}$ is responsible to encode $x$ into a latent representation $z=\mathcal{E}(x)$, and the decoder $\mathcal{D}$ is responsible for reconstructing the image $\tilde{x}=\mathcal{D}(z) = \mathcal{D}({\mathcal{E}(x)})$.
The diffusion model $\epsilon_\theta$ is a UNet model, which has a U-shaped architecture with multiple skip connections between the downsampling and upsampling paths. With the latent representation $z=\mathcal{E}(x)$ from the pretrained autoencoder replacing the pixel-space image $x$, the loss function of the diffusion model is then defined as:
$$L_{\text{LDM}}:=\mathbb{E}_{z_t\sim\mathcal{E}(x), \epsilon\sim\mathcal{N}(0,1),t} [\|\epsilon-\epsilon_\theta(z_t,t)\|^2_2]$$
After training is complete, denoised samples $z$ from the learned reverse process can be decoded back to pixel space through the pretrained decoder $\mathcal{D}$.
For conditional image generation, given conditioning information $y$ (such as a text caption), LDM uses a doman-specific encoder $\tau_\theta$ to project $y$ to $\tau_\theta(y)$, and then feeds $\tau_\theta(y)$ into the intermediate layers of the UNet $\epsilon_\theta$ via cross-attention:
$$\begin{align*} \text{Attention(Q,K,V)} \, &= \, \text{softmax}(\frac{QK^T}{\sqrt{d}})V \\
\text{where } Q = W^{(i)}_Q\varphi_i(z_t), \,K &= W^{(i)}_K\tau_\theta(y), \, V = W^{(i)}_V\tau_\theta(y)
\end{align*}$$
where $\varphi_i(z_t)$ denotes the intermediate representation of $z_t$ at the $i$-layer of $\epsilon_\theta$. That is, in the cross-attention layers, the keys and values come from $\tau_\theta(y)$, while the queries come from $\varphi_i(z_t)$.The conditional loss function $L_{LDM}$ is then defined as:
$$l_{LDM}:=\mathbb{E}_{\mathcal{E}(x),y,\epsilon,t}[\|\epsilon-\epsilon_\theta(z_t,t,\tau_\theta(y))\|_2^2]$$
where both the domain-specific encoder $\tau_\theta$ and $\epsilon_\theta$ are jointly optimized.

For conditional image generation that conditions on class labels $y$, Diffusion Models Beat GANs on Image Synthesis trains a classifier $p(y\mid \mathbf{x}_t,t; \phi)$ on a noisy image $\mathbf{x}_t$ at time step $t$ to predict the class label $y$. During sampling, the gradient of the classifier’s log-probability for class $y$ with respect to $\mathbf{x}_t$, $\nabla_{\mathbf{x}_t}\log p(y\mid \mathbf{x}_t,t; \phi)$, can be used to guide each reverse step $\mathbf{x}_t \sim p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)$ of a pretrained unconditional diffusion model so that the generated sample is pushed towards class $y$.
The diffusion model and the classifier are trained independently. The classifier’s noisy training images $\mathbf{x}_t$ are generated by the same noising process used to train the diffusion model, $\mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\bm{\epsilon}$, where $\bm{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I})$.
The reverse transition of a diffution model conditioning on $y$ can be written as:
$$p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi) = Zp(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi)$$
where $Z$ is a normalizing constant that ensures the right-hand side integrate to $1$ over $\mathbf{x}_t$. (Readers who are interested in the proof can refer to the paper)
Let $p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta) = \mathcal{N}(\bm{\mu}, \bm{\Sigma})$. With the assumption that the number of diffusion steps $T$ is large enough, we have:
$$\begin{align*}\log\Big[p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi) \Big] \approx \log \mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) + C
\end{align*}$$
where $g=\nabla_{\mathbf{x}_t}\log p(y\mid\mathbf{x}_t,t;\phi)|_{\mathbf{x}_t=\bm{\mu}}$ is the gradient of
$\log p(y\mid\mathbf{x}_t,t;\phi) $ with respect to $\mathbf{x}_t$, evaluated at $\mathbf{x}_t=\bm{\mu}$, and $C$ is a constant. (Check the paper for the details of the derivation of this approximation.)
Exponentiating both sides gives the approximation of $p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi)$:
$$\begin{align*}p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi)
&\approx \exp\Big(\log \mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) + C\Big) \\
&= \exp\Big(\log \mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) \Big) \exp(C)\\
&= \mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) \exp(C)\\
&= \exp(C)\mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma})
\end{align*}$$
Therefore, $p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi) $ can be approximated as follows:
$$\begin{align*} p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi) &= Zp(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi) \\
&\approx Z \exp(C)\mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) \\
&=\mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma})\qquad (*)
\end{align*}$$
$(*)$ Expand to see step-by-step derivation of the last equation:
Since $p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi)$ on the left-hand side is a valid probability density function, it integrates to $1$ with respect to $\mathbf{x}_t$:
$$\begin{align*} 1 &= \int_{\mathbf{x}_t} p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi) dx \\
&= \int_{\mathbf{x}_t}Zp(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)p(y\mid\mathbf{x}_t,t;\phi) dx\\
&\approx Z \exp(C)\int_{\mathbf{x}_t}\mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) dx \\
&\approx Z \exp(C)
\end{align*}$$
As a result, $Z \exp(C)$ cancels each other out in the approxiamtion.
In conclusion,
$$p(\mathbf{x}_t\mid\mathbf{x}_{t+1}, y;\theta,\phi) \approx \mathcal{N}(\bm{\mu}+\bm{\Sigma}g, \bm{\Sigma}) = p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta) + \bm{\Sigma}g$$
where $g=\nabla_{\mathbf{x}_t}\log p(y\mid\mathbf{x}_t,t;\phi)|_{\mathbf{x}_t=\bm{\mu}}$, and $\bm{\mu}$ and $\bm{\Sigma}$ are the mean and covariance matrix of $p(\mathbf{x}_t\mid\mathbf{x}_{t+1};\theta)$, respectively.
This approximation shows that when the number of diffusion steps $T$ is large enough, the conditional reverse transition can be approximated by the reverse transition of the unconditional diffusion model with its mean shifted by $\bm{\Sigma}g$.
In addition, the authors also include a gradient scale $s$, a hyperparameter to control the strength of the classifier guidance, and the gradient $\nabla_{\mathbf{x}_t}\log p_\phi(y\mid\mathbf{x}_t,t)$ is evaluated at the current noisy sample $\mathbf{x}_t$, instead of at the mean $\bm{\mu}$, in practice.
Given $\bm{\mu}_\theta(\mathbf{x}_t,t)$ and $\bm{\Sigma}_\theta(\mathbf{x}_t,t)$ from a pretrained unconditional diffusion model, and a pretrained classifier $p(y\mid\mathbf{x}_t, t;\phi)$, the complete classifier guided diffusion sampling procedure is as follows:
$$\begin{align*}
&\text{Input: } \text{class label } y, \text{gradient scale } s \\
& \mathbf{x}_T \sim\mathcal{N}(\mathbf{0},\mathbf{I})\\
&\textbf{for } t=T,\dots,1 \textbf{ do}\\
&\qquad \bm{\mu} \leftarrow \bm{\mu}_\theta(\mathbf{x}_t,t)\\
&\qquad \bm{\Sigma} \leftarrow \bm{\Sigma}_\theta(\mathbf{x}_t,t)\\
&\qquad g \leftarrow \nabla_{\mathbf{x}_t}\log p(y\mid\mathbf{x}_t,t;\phi)|_{\mathbf{x}_t=\mathbf{x}_t}\\
&\qquad \mathbf{x}_{t-1} \sim \mathcal{N}(\bm{\mu}+s\bm{\Sigma}g, \bm{\Sigma})\\
&\textbf{end for}\\
&\textbf{return } \mathbf{x}_0
\end{align*}$$
The gradient scale $s$ serves as a trade-off between sample diversity and sample fidelity: a larger $s$ steers reverse process more strongly towards class $y$, producing higher fidelity but less diverse samples.
Classifier-Free Diffusion Guidance shows that guidance can be achieved without any classifier. To enable it, the authors jointly train a conditional diffusion model and an unconditional diffusion model using a single network. After training is complete, the conditional and unconditional predictions from the network are combined at every denoising sampling step to produce the guided prediction, and there is also a hyperparameter to control the guidance strength during sampling.
During training, the diffusion network $\bm{\epsilon}_\theta$ randomly drops the conditioning information $y$ by replacing it with a null token $\varnothing$ with some probability $p_\text{uncond}$, which is a hyperparameter and typically set to a small value such as $0.1$. The null token $\varnothing$ serves as the unconditional class identifier for the network so that the unconditional prediction and conditional prediction from the same network can be obtiaind through, $\bm{\epsilon}_\theta(\mathbf{x}_t, t, \varnothing)$ and $\bm{\epsilon}_\theta(\mathbf{x}_t, t, y)$, respectively. Training with this random replacement therefore trains a conditional diffusion model and an unconditional diffusion model jointly within a single network.
After training is complete, during sampling, a linear combination of the predictions with and without conditioning information is used as the guided prediction $\tilde{\bm{\epsilon}}_\theta$ from the diffusion network $\bm{\epsilon}_\theta$:
$$\begin{align*}\tilde{\bm{\epsilon}}_\theta(\mathbf{x}_t, t, y) &= (1+w)\bm{\epsilon}_\theta(\mathbf{x}_t, t, y) - w\bm{\epsilon}_\theta(\mathbf{x}_t, t, \varnothing) \\
&= \bm{\epsilon}_\theta(\mathbf{x}_t, t, y) + w\Big(\bm{\epsilon}_\theta(\mathbf{x}_t, t, y) - \bm{\epsilon}_\theta(\mathbf{x}_t, t, \varnothing) \Big)
\end{align*}$$
where $w$ is the guidance strength.
When $w=0$, classifier-free guidance reduces to ordinary conditional sampling.
When $w > 0$ the guided prediction extrapolates beyond the conditional prediction, away from the unconditional one. This can result in generated samples that follow the conditioning information $y$ more closely but are less diverse. As a result, $w$ also control the trade-off between sample diversity and sample fidelity, similar to the gradient scale $s$ in calssifier guidance.
Empirical reports from GLIDE show that samples that are generated using classifier-free guidance are more favored by human evaluators.
A potential disadvantage of classifier-free guidance compared to classifier guidance is that to get the guided prediction, the diffusion network needs to be run twice to get the unconditional prediction and conditional prediction.
Below compares three paradigms of generative modeling:
Latent variable models assume a latent representation $\mathbf{z}$ and a generative process $p(\mathbf{x}\mid\mathbf{z})$ responsible for the observed data $\mathbf{x}$, where the latent $\mathbf{z}$ is unobserved.
The goal is the to learn the parameters of $p(\mathbf{z})$ and $p(\mathbf{x}\mid\mathbf{z})$ so that given a sampled $\mathbf{z}$, new data $\mathbf{x}$ can be generated via $p(\mathbf{x}\mid\mathbf{z})$, if the latent representation is interpretable.
Variational Inference (also called Variational Bayes or Variational Approximation) is a method for approximating the intractable posterior $p(\mathbf{z}\mid\mathbf{x}; \theta)$ with a variational posterior $q(\mathbf{z}\mid\mathbf{x}; \phi)$ by maximizing the Evidence Lower BounD (ELBO) on the marginal log-likelihood $\log p(\mathbf{x};\theta)$).
One of the core contribution of the VAE is the reparameterization trick for the latent $\mathbf{z}$ in the ELBO, which enables the variational posterior $q(\mathbf{z}\mid\mathbf{x})$ to be trained directly via standard stochastic gradient ascent on the ELBO.
Diffusion models frame the generation task as a multi-step denoising Markov procedure that reverses a fixed noising procedure, which can be viewed as a multi-level VAEs. This multi-step approach delivers higher generation quality but requires far more sampling time compared with VAEs.