






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Generative modeling asks us to model the distribution of the data itself. Unlike supervised learning, where the goal is to predict a target y from an input x, the goal here is to generate new plausible samples x. We will use images as the main running example. A diffusion model does this by first defining a simple process that gradu- ally adds noise to data, and then learning to reverse that process one step at a time. The basic idea goes back to nonequilibrium thermodynamics based models [Sohl-Dickstein et al., 2015]; its modern form was developed in de- noising diffusion probabilistic models (DDPMs) [Ho et al., 2020], with later connections to score-based modeling [Song et al., 2021]. Beyond images, dif- fusion models are also prominent in video generation and in vision-language- action (VLA) models for robotics, and there are early promising results for applying diffusion-style methods to language.
Let pdata be the distribution of the data, such as images or normalized images, which we eventually aim to be able to generate samples from. The forward diffusion process defines a fixed Markov chain that grad- ually corrupts the clean data from pdata. This Markov chain consists of a sequence of random variables x 0 , x 1 ,... , xT , where x 0 ∼ pdata. The variables x 1 , x 2 ,... , xT are progressively noisier versions of x 0. Let q denote the joint distribution of this Markov chain. Its one-step transition density is
q(xt | xt− 1 ) = N
xt;
1 − βt xt− 1 , βtI
q(x 1 | x 0 ) q(x 2 | x 1 ) (^) q(xT | xT − 1 )
pθ (x 0 | x 1 ) pθ (x 1 | x 2 ) pθ (xT − 1 |^ xT )
· · · · · ·
x 0 ∼ pdata xT ∼ N (0, I)
Figure 14.1: The forward diffusion process gradually corrupts a clean sample, while the learned reverse process denoises one step at a time.
Here β 1 ,... , βT ∈ (0, 1) are scalars that indicate the noise level at each step.^1
Probability notation clarification. As throughout these lecture notes, N (μ, Σ) denotes the Gaussian distribution with mean μ and covariance Σ. Here we use N (x; μ, Σ) to denote the corresponding Gaussian density evalu- ated at x: N (x; μ, Σ) = (^) (2π)d/^12 |Σ| 1 / 2 exp
−^12 (x − μ)T^ Σ−^1 (x − μ)
. In machine
learning, simplified and overloaded notation is quite common. For example, xt can denote either the random variable itself or a particular numerical value taken by that random variable. Thus, the notation xt | xt− 1 denotes a condi- tional distribution where xt, xt− 1 are interpreted as random variables, while q(xt | xt− 1 ) denotes the conditional density evaluated at the particular val- ues written as xt and xt− 1. We will use this standard overloaded notation as well. Equation (14.1) therefore means that, under q, the conditional random variable xt given xt− 1 is Gaussian with mean
1 − βt xt− 1 and covariance βtI, even though the equation itself is written as an equality between density functions.^2 We may also write the following, which more explicitly empha- sizes that we are defining the distribution of xt | xt− 1 under the transition q, denoted by Lawq(xt | xt− 1 ).
Lawq(xt | xt− 1 ) = N
1 − βt xt− 1 , βtI
We will learn a model that runs this noising process backward. Before that, we will understand some properties of the forward process. It is con- venient to also define αt = 1 − βt. Then a sample from the forward process
(^1) Following the conventional notation in the diffusion-model literature, we write the variance as βt, rather than as β t^2. (^2) In machine learning, one also often sees the more overloaded notation q(xt | xt− 1 ) = N ( √ 1 − βt xt− 1 , βtI), where a density on the left is identified with a distribution on the right. We will avoid that usage in these notes.
Equation (14.5) shows that ¯αt controls the clean-data component: as ¯αt decreases, xt contains less information about x 0 and more Gaussian noise. In the limiting regime where T → ∞ and ¯αT → 0, for every x 0 ,
q(xT | x 0 ) → N (xT ; 0, I) , or in other words, Lawq(xT | x 0 ) → N (0, I). (14.10)
Thus, xT eventually converges to white Gaussian noise. Averaging over x 0 , this also means that the marginal distribution of xT under q is close to N (0, I) for large T. We will assume that q(xT ) is exactly spherical Gaussian in the rest of the chapter. We note that the forward process q is fixed rather than learned. This is one of the attractive features of diffusion models. The learning problem is not to discover how to corrupt the data, but only how to reverse a corruption process that we chose ourselves.
14.2 Parameterizing the reverse process
The previous section defined a fixed forward process. We now ask what it would mean to reverse it, and then replace the unknown reverse conditionals by a learned parameterized model. Because the forward process is Markov, the same joint distribution can also be factorized in the reverse direction in a Markov fashion. More precisely, under the distribution q,^3
q(x0:T ) = q(xT )
t=
q(xt− 1 | xt), (14.11)
where the conditionals q(xt− 1 | xt) define the true reverse Markov chain. The previous section argued that the marginal distribution of xT under q is the standard spherical Gaussian N (0, I). We will learn to approximate the unknown reverse conditionals q(xt− 1 | xt), so that we can generate from pdata by sampling xT ∼ N (0, I) and re- peatedly sampling backward, xT → xT − 1 → · · · → x 1 → x 0. We approximate each reverse kernel q(xt− 1 | xt) by a Gaussian distribu- tion with parameters produced by a neural network. Concretely, we define
pθ(xt− 1 | xt) = N
xt− 1 ; μθ(xt, t), σ^2 t I
i.e., Lawpθ (xt− 1 | xt) = N
μθ(xt, t), σ^2 t I
(^3) We use the shorthand x0:T to denote the whole trajectory (x 0 , x 1 ,... , xT ). Similarly,
x1:T denotes (x 1 ,... , xT ).
Together with the prior density pθ(xT ) = N (xT ; 0, I), or equivalently Lawpθ (xT ) = N (0, I), these conditionals define a full joint distribution over the trajectory.
pθ(x0:T ) = pθ(xT )
t=
pθ(xt− 1 | xt). (14.13)
The mean μθ(xt, t) is produced by a neural network with parameters θ; the timestep t is embedded and fed into the network along with xt. The scalar variance σ^2 t is fixed and will be determined later in this note, but it can also be learned [Nichol and Dhariwal, 2021]. This Gaussian reverse parametrization is not only a convenient modeling choice; it is also supported by the continuous-time reverse diffusion theorem. We return to this perspective in Section 14.4.
14.3 Training diffusion models by maximiz-
ing the ELBO
We now fit the parameterized reverse process by maximizing the likelihood using the standard variational approach. The goal is to maximize the likeli- hood pθ(x 0 ) over the parameter θ:^4
pθ(x 0 ) =
pθ(x0:T )dx 1 · · · dxT (14.14)
Since the integration is intractable, we maximize the variational lower bound of pθ(x 0 ). Using the standard ELBO identity, namely the definition in (11.9) together with the lower-bound statement in (11.10), with the latent vari- able z corresponding to the path x1:T and the auxiliary distribution Q(z) corresponding to q(x1:T | x 0 ), we have
log pθ(x 0 ) ≥ LELBO(x 0 ; q) = Ex1:T ∼Lawq(x1:T | x 0 )
log
pθ(x0:T ) q(x1:T | x 0 )
= Ex1:T ∼Lawq(x1:T | x 0 )
log pθ(x 0 | x1:T )
Lawq(x1:T | x 0 ) ‖ Lawpθ (x1:T )
Because the reverse model is Markov, pθ(x 0 | x1:T ) = pθ(x 0 | x 1 ). Thus the first term is the final reconstruction term. The second KL term can
(^4) More precisely, the goal is to maxθ 1 n
∑n i=1 log^ pθ^ (x
(i) 0 ), where the^ x (i)’s are empirical
examples. But here for simplicity we consider the case where there is just a single example x 0.
Recall that we assume the reverse transition under pθ is also Gaussian, which has a similar form: pθ(xt− 1 | xt) = N (xt− 1 ; μθ(xt, t), σ^2 t I) , It is natural to choose σ^2 t = β˜t so that the two distributions in the KL term, Lt− 1 , have the same covariance. The KL divergence between two Gaussians with the same covariance has the closed form
N (m 1 , Σ) ‖ N (m 2 , Σ)
(m 1 − m 2 )T^ Σ−^1 (m 1 − m 2 ). (14.20)
Therefore, for t = 2 ,... , T , the term Lt− 1 = Eq
q(xt− 1 | xt, x 0 ) ‖ pθ(xt− 1 | xt)
is the same as
Lt− 1 = Eq
2 β˜t
‖μ˜t(xt, x 0 ) − μθ(xt, t)‖^22
In other words, our model μθ(xt, t) is supposed to reconstruct ˜μt(xt, x 0 ), which is a linear combination of x 0 and xt by Equation (14.19).
Simplifying to Reconstructing the Noise. Because xt is a linear com- bination of x 0 and ˆt by Equation (14.5), the posterior mean ˜μt(xt, x 0 ) can also be written in terms of xt and ˆt. Thus, to reconstruct ˜μt(xt, x 0 ), we can equivalently reconstruct ˆt. Therefore, we can simplify further. First, by Equation (14.5), we have
x 0 = xt−
√ 1 − α¯ √ t^ ˆt ¯αt.^ Substituting this expression into the exact posterior mean (14.19), and using ¯αt = αt α¯t− 1 and αt = 1 − βt, gives that for t ≥ 2,
μ˜t(xt, x 0 ) =
αt
xt −
βt √ 1 − α¯t
ˆt
We therefore can also predict ˆt by a parameterized neural network θ(xt, t) parameterized by θ, and then let
μθ(xt, t) =
αt
xt −
βt √ 1 − α¯t
θ(xt, t)
Combining Equations (14.21) to (14.23), we have for t ≥ 2,
Lt− 1 =
β^2 t 2 β˜tαt(1 − α¯t)
Eˆt
‖ˆt − θ(xt, t)‖^22
The ELBO consists of terms that are weighted noise-prediction losses.
We note that across different timesteps, ˆt are not independent. However, for training at a single sampled timestep, only the marginal fact ˆt ∼ N (0, I) is needed, and that is why in other materials ˆt is often simply written as ∼ N (0, I). Moreover, the derivation above only applies to the denoising terms Lt− 1 for t ≥ 2 because L 0 has a different definition.
The L 0 term. In Equation (14.13), we parameterize the reverse process as a Markov process, so pθ(x 0 | x1:T ) = pθ(x 0 | x 1 ). A natural choice is to model pθ(x 0 | x 1 ) by a Gaussian distribution, pθ(x 0 | x 1 ) = N (x 0 ; μθ(x 1 , 1), σ 12 I). Therefore,
L 0 =
2 σ 12
Eq
‖x 0 − μθ(x 1 , 1)‖^22
d 2
log(2πσ 12 ). (14.25)
For t = 1, we have ¯α 1 = α 1 and x 0 = (x 1 −
1 − α¯ 1 ˆ 1 )/
√ α¯^1 = (x^1 − β 1 ˆ 1 )/
α 1. If we define ˜μ 1 (x 1 , x 0 ) = x 0 , then Equation (14.22) also holds at t = 1. Thus we can use the same noise-prediction parametrization as in Equation (14.23), namely μθ(x 1 , 1) = (x 1 −
β 1 θ(x 1 , 1))/
α 1. Combining these expressions gives
β 1 2 σ^21 α 1
‖ˆ 1 − θ(x 1 , 1)‖^22
d 2
log(2πσ^21 ). (14.26)
The weight has the same formal pattern as Equation (14.24) at t = 1, with the final-step variance σ^21 playing the role of the variance term in the denom- inator. Thus, up to constants independent of θ, the t = 1 reconstruction term and the t ≥ 2 denoising terms have the same weighted noise-prediction form.^5 In practice, one often drops these coefficients and trains with the un- weighted noise-prediction loss.
Training algorithm. The simplified objective leads to a particularly sim- ple training loop:
Theorem 14.4.1 (Reverse-time diffusion theorem, informal). Under suitable regularity conditions, the reverse-time process Yτ = XT −τ is again a diffusion process. Its dynamics are
dYτ =
−f (Yτ , T − τ ) + g(T − τ )^2 ∇x log pT −τ (Yτ )
dτ + g(T − τ ) d W¯τ , (14.32) where W¯τ is a Wiener process with respect to the reverse-time filtration.^6
The signs in Equation (14.32) come from using τ as the forward variable for the reversed process. The original drift f is traversed backward, giving the term −f (Yτ , T − τ ). The additional score term ∇x log pT −τ appears because the reverse transition must also account for which previous states are more likely under the marginal density at time T − τ. A short informal one-dimensional derivation gives the main intuition. Consider the special case
dXt = f (Xt, t) dt + dWt. (14.34)
For a small step size h, the forward transition from time T − τ − h to time T − τ is approximately Gaussian:
LawX (XT −τ | XT −τ −h = z) ≈ N (z + hf (z, T − τ ), h). (14.35)
Now condition on Yτ = y, which is the same event as XT −τ = y. By Bayes’ rule, as a density in z, (so that multiplicative dependencies in y in the de- nominator of Bayes rule is omitted)
p(Yτ +h = z | Yτ = y) ∝ p(XT −τ = y | XT −τ −h = z) pT −τ −h(z). (14.36)
The first factor in Equation (14.36) forces the norm of√ z − y to be of order h with high probability. We Taylor-expand the log density and drop all the terms smaller than O(h):
log pT −τ −h(z) = log pT −τ (y) + ∂x log pT −τ (y) (z − y) + O(h). (14.37) (^6) Equivalently, one often keeps the original time variable t, but integrates it from T down to 0. If X¯t denotes the same reverse process written with this decreasing original-time parameter, then
d X¯t =
( f ( X¯t, t) − g(t)^2 ∇x log pt( X¯t)
) dt + g(t) d W¯t, t : T → 0. (14.33)
Here dt is interpreted as a negative time increment, and d W¯t is the Wiener increment in reverse time. Setting t = T − τ recovers Equation (14.32).
Note that the second term is on the order of
h for most of the z. Letting u = z − y, and noting that u is mostly on the order of
h, we can derive the log of p(Yτ +h = z | Yτ = y) by Taylor expansion,
log p(Yτ +h = z | Yτ = y) (14.38)
= −
(y − z − hf (y, T − τ ))^2 2 h
u^2 2 h
− f (y, T − τ )u + ∂x log pT −τ (y)u + const + O(h)
= −
2 h
(u − h [−f (y, T − τ ) + ∂x log pT −τ (y)])^2 + const + O(h). (14.39)
Here const encapsulate all terms that are only a function of y. In other words, we have
Yτ +h | Yτ = y ≈ N
y + h
−f (y, T − τ ) + ∂x log pT −τ (y)
, h
This is the small-step form of (14.32) when g ≡ 1. The general case has infinitesimal variance g(T − τ )^2 h and therefore the score contribution be- comes g(T − τ )^2 ∇x log pT −τ. This explains why the reverse process is again locally Gaussian and why diffusion models parametrize the reverse kernels by Gaussians.