ai papers
Improved DDPM + Diffusion Beats GANs + Classifier-Free Diffusion Guidance Paper Review
Junyoung Park · 2023-04-30 · 21 min
Introduction
This review covers a series of three papers. All build on diffusion models—DDPM and DDIM—and seek to improve diffusion sampling quality. Improved DDPM adds several modifications to DDPM’s basic experiments and improves sample log likelihood. Diffusion Beats GANs presents broader architecture ablations and classifier guidance, showing that diffusion models can exceed GAN sampling quality. Finally, Classifier-Free Diffusion Guidance discusses the limitations of classifier guidance and proposes a method that retains the advantages of conditional generation without explicitly training a classifier. Since little additional proof is required, it seems useful to cover all three together.
Improved DDPM
After DDPM attracted attention as a new way to train and sample a generative model, researchers began asking whether it could handle datasets with diverse samples, such as ImageNet, beyond CIFAR-10 and LSUN. GANs offered fast, high-quality sampling but struggled with training instability and low sample diversity. Likelihood methods such as VAEs provided stability and diversity, but sampled more slowly and with lower quality than GANs. DDPM arrived in this context, but it too was no universal solution. It was only a new methodology, with network design and training still open to future work.
The paper improves sampling quality in two main ways. First, it uses a hybrid objective. DDPM optimized a simplified modification of the variational lower bound (VLB); this work adds VLB loss back into the objective.
Second, it learns rather than fixes the variance. DDPM needed hundreds of forward-process steps for good samples, but the learned variance achieves similar quality with as few as forward passes. Unlike DDIM, which introduces a non-Markovian sampling process, this work preserves DDPM’s Markovian process and modifies training itself.
Conventional DDPM
The earlier post covers the full DDPM derivation. Omitting those proofs, let data follow . The forward noising process adds tiny Gaussian perturbations:
Given a sufficiently long time and a well-scheduled , the parameterized prior can sample : the forward process gradually approaches Gaussian noise. If the reverse conditional were known, we could sample from arbitrary Gaussian noise, but this distribution is intractable.
A parameterized neural network therefore predicts from each noised sample , gradually removes noise, and samples . The reverse of adding tiny Gaussian noise can be approximated as subtracting Gaussian noise.
The variational lower bound optimized by DDPM is
The first term is naturally near zero after perturbing arbitrary data for sufficiently long , so it need not be optimized. The middle term is a KL divergence that trains the reverse-predicting network to follow the forward-process posterior. The last projects the probability of the 256-valued RGB image when generating from . See the DDPM post for the detailed proof and an explanation of every term. Simplifying the bound gives
Increasing DDPM log likelihood
DDPM achieved strong FID and IS (Inception Score), common sample-quality metrics, but weak log likelihood. Log likelihood measures how well a generative model reflects the modes of the data distribution. Optimizing it encourages the model to capture the distribution’s overall form. A network that produces attractive samples from only one portion of the true distribution cannot be said to model that data well. This paper analyzes why DDPM’s log likelihood is weak, then shows that improving it can substantially improve actual sample quality.
Learnable standard deviation (variance)
DDPM fixes a predefined variance . Curiously, sampling quality differs little whether is set to or to the forward-posterior value . The former makes the th kernel variance isotropic Gaussian with respect to , while the latter makes it a delta function. If and are the two endpoints available to the variance, why do they affect sampling so little? I failed to address this adequately in the earlier DDPM post, where I speculated:
The paper says that using , the variance at step , as makes little difference in practice. I thought this was because the cumulative variance product varies little with when the number of steps is large—though I might be wrong.
In retrospect, perhaps ten percent of that was right. Let us examine the Improved DDPM analysis.
As the diffusion step grows, and become nearly identical. Setting therefore has little effect on sample quality at large diffusion steps. Their meaningful difference lies near , where the image is nearly complete and contains little noise, so sample quality again changes little.
As the number of diffusion steps grows, changing has little influence on determining the image distribution. But this does not imply that fixing is optimal. Consider the next graph.
Optimizing log likelihood means optimizing the diffusion VLB. The closer a step is to the sample at , rather than noise at , the more important its loss becomes. One reason DDPM failed to improve log likelihood effectively is that it did not model where the variance endpoints differ most. , which DDPM omitted from the loss, must also be predicted. The authors reason that if the prediction range of is too small—as grows, even its log infimum and supremum barely differ—it is difficult for a neural network to predict. They instead parameterize variance by interpolating between and . The network predicts a vector , one element per dimension, and interpolates the variance as
Interpolating in log space is numerically more stable than interpolating directly. Although is allowed outside rather than being restricted to a convex combination, the trained network never predicted outside that interval. The simplified loss discards every variance-normalization term from the VLB, so it cannot learn the parameterized variance. The paper therefore combines with a weighted VLB term:
Because contributes to DDPM’s easy optimization, the paper uses the small value . It also stops gradients through while optimizing the VLB term. Thus learns stable variance under guidance from the simplified loss through , while is optimized only by the simplified loss.
Better noise scheduling
The paper also proposes a replacement for DDPM’s noise schedule. Linear scheduling works for high-dimensional, high-resolution images but is less effective for low-resolution () images, whose forward process approaches Gaussian noise too rapidly.
With the linear schedule in the upper row, almost all image information disappears after only a few processes. To learn an effective sampling process, cumulative variance should make samples noisy more gradually.
Models trained with a linear schedule can skip of the diffusion process with little FID loss. Those extra steps therefore contribute nothing to sample quality.
The authors use a cosine schedule, producing variance that decreases more progressively—approximately linearly:
This definition makes approach too closely near , so it is clipped at to avoid the resulting singularity. A small offset also prevents values near from becoming too small. Accounting for pixel bins gives , which determines .
Reducing gradient noise
Why use the hybrid loss? If the direct objective is better log likelihood, optimizing the VLB alone seems natural. The results are less cooperative.
Although VLB is the loss directly related to log likelihood, the graph shows much noisier training and poorer convergence than the hybrid objective. Hybrid loss has a lower loss curve overall. The authors hypothesize that pure VLB performs worse because its gradients contain more noise than hybrid-loss gradients.
Unlike simplified loss, has different magnitudes at different steps. Uniformly sampling therefore does not help the VLB objective. The paper introduces importance sampling:
This resembles focal loss. Sampling follows probabilities continually updated from the previous ten loss records at each time step. Initially, is sampled uniformly until ten observations have accumulated for every value.
Improved DDPM appears to focus on improving DDPM log likelihood relative to likelihood-based networks. Parameterizing the variance also seems to improve FID considerably.
Diffusion Beats GANs
The next paper proposes a way to surpass GAN sampling quality. Baseline DDPM was relatively weak at sampling complex datasets such as ImageNet. With a provocative title from OpenAI, an organization that clearly loves diffusion, “Diffusion Beats GANs” became one of the papers that popularized diffusion. It beats the then-state-of-the-art BigGAN on ImageNet and covers both unconditional and conditional generation.
Why was diffusion not good enough?
Despite strong sample diversity and stable training, why had diffusion sampling quality remained insufficient? The paper’s core is to form hypotheses about the problem and address them. The authors identify two reasons:
- GANs had received much longer study than diffusion, producing extensive research into optimal architectures, training methods, and hyperparameters.
- GANs trade diversity for fidelity, making them difficult to beat on sample quality alone.
DDPM was simply young—this paper appeared about one year later—while GANs were explicitly designed to sacrifice diversity for high-quality samples. The paper begins by importing both GAN advantages—optimized network structure and sampling quality—into diffusion, with the ambition of surpassing GANs outright.
Background
The framework begins with DDPM, supplemented by Improved DDPM’s trainable variance and DDIM for fast sampling. Improved DDPM obtains high quality with fewer time steps by changing training; DDIM instead changes sampling through a non-Markovian process with the same marginals. The approaches are therefore distinct. I recommend reading my DDIM post first.
In summary, training uses Improved DDPM’s hybrid loss, while generation with fewer than 50 steps uses DDIM. This relates to an Improved DDPM experiment not discussed above.
The graph shows that DDIM sampling quality becomes better beyond roughly steps.
Sample-quality metrics
GAN research commonly measures sampling quality with IS and FID, but both are imperfect. This is one reason generative-model research can be persuasive through qualitative evaluation yet struggle to persuade through quantitative evaluation. Beyond a certain point, deciding which of two generated images is “better” has little objective meaning. Adversarially trained GANs can also raise classifier-based metrics naturally, because fake samples attack the discriminator through gradients.
Inception Score is defined above. measures whether generated samples cover all classes evenly, while measures each sample’s quality. IS cannot measure diversity within a class. A CIFAR-10 generator could output one excellent sample for each of the ten classes and still receive a satisfying IS; collapse would go undetected. FID addresses this by using features from an Inception network and modeling multivariate Gaussian distributions from their means and covariances.
Another paper proposes precision and recall to separate sample fidelity from diversity. Let the model’s implicit distribution be and the real distribution . The fraction of generated samples lying inside the real distribution measures fidelity, while the fraction of real samples covered by the generated distribution measures diversity.
The proportion of true positives—samples in both and —among true positives plus false positives—samples in but not —corresponds to sample quality.
The proportion of true positives among true positives plus false negatives—samples in but not —corresponds to sampling diversity. This paper uses precision and IS for fidelity and recall for diversity.
Architecture improvements
One limitation of early DDPM-based diffusion research was insufficient exploration of network structure. The authors search for architectures that improve diffusion sampling quality:
- Increase width—channel count—relative to depth while keeping total model size approximately constant.
- Increase the number of attention heads; the baseline U-Net includes attention inside residual blocks.
- Apply attention not only at the feature-map level, but also at and .
- Use BigGAN residual blocks for activation upsampling and downsampling.
- Scale residual connections by .
Experiments use ImageNet images at , batch size , 250 sampling steps, and FID.
In the left table, every architectural proposal except rescaling improves FID. Increasing depth also tends to improve performance, as the lower graph shows, but the authors stop because training time grows excessively.
Attention experiments show that more heads with fewer channels per head produce the best FID. Sixty-four channels offer the best performance-efficiency trade-off in training speed, so the paper adopts that choice. Interestingly, the architectural trend matches the Transformer.
Adaptive group normalization
AdaGN stylizes each residual block with time-step and class embeddings. Given hidden activation and the linear projection of time-step and class embeddings,
This is identical to AdaIN apart from GroupNorm, as readers of StyleGAN may notice.
AdaGN performs well and is used throughout training; the figure shows its ablation. The final architecture is
- two BigGAN residual blocks at each resolution, with width adjusted to resolution;
- 64 channels per attention head, with attention layers at resolutions 32, 16, and 8;
- BigGAN residual blocks for upsampling and downsampling, with AdaGN injecting time-step and class embeddings.
Classifier guidance
Conditional image synthesis has proven useful for high quality on datasets with limited labels. Viewing a GAN as a probability distribution, a discriminator supplying explicit information can guide the generator to produce images of each label more effectively than merely distinguishing real from fake.
AdaGN already provides class embeddings as style information alongside time steps, but this differs from explicitly supplying discriminator information. The authors therefore develop classifier guidance. Suppose a pretrained classifier has learned classification over noised images at every time step. Its log-likelihood gradient can guide diffusion sampling. The paper separately derives conditional guidance for the Markovian DDPM sampler and non-Markovian DDIM sampler.
Conditional reverse noising process
For each noised image, pretrained classifier supplies information entirely external to the diffusion process. Normalizing factor can therefore be treated as constant; see the appendix for details.
Recall the unconditional diffusion reverse process. For predicted at each time,
The curvature of is expected to be small relative to . The reverse-process log likelihood is a quadratic whose curvature is related to . Since is near zero for most diffusion steps, this coefficient is very large. The classifier function can therefore reasonably be assumed to have much smaller curvature.
At , the vertex of the reverse process’s quadratic, classifier guidance can be represented by a first-order Taylor approximation. Sampling is governed mainly by ; the classifier curvature is negligible relative to there.
Here is the classifier log-likelihood gradient at . Substitution gives
Classifier guidance therefore turns the sampling direction by adjusting the drift.
Conditional sampling for DDIM
The method above adjusts drift and assumes a Markov process, so it cannot be used directly for deterministic DDIM sampling.
Deterministic DDIM predicts from , so a classifier gradient over cannot be applied in the same way. Here the paper connecting SDEs with diffusion models becomes useful. Its VP-SDE expresses DDPM sampling as
and rewrites it as an SDE over score estimate :
The score can thus be defined at time independently of ancestral sampling:
Applying this to the score of gives
We can redefine epsilon, changing the gradient just as for DDPM:
Scaling the classifier gradient
Classifier score guidance requires training . Its architecture takes downsampled features from the diffusion U-Net and applies attention pooling for the final output. Because it must classify every noise step, it trains on noised inputs from every time step. Sampling then uses its gradient as described above.
Initial experiments with an unconditional ImageNet model found that unless classifier guidance scale exceeded , the probability of generating the desired class fell by half. Even when such samples were produced, they often did not visually belong to the class.
For “Pembroke Welsh corgi,” scale on the left fails to produce convincing corgis, while scale improves them substantially.
The table notably shows that sufficiently strong classifier guidance on an unconditional model—guidance —achieves FID and IS comparable to a conditional model.
The paper also surpasses BigGAN with a two-stage diffusion process conditioned on a low-resolution image. Sampling speed remains a problem, however, and separate classifier training restricts the method to labeled samples.
Classifier-Free Diffusion Guidance
Low-temperature sampling
By adjusting gradients with a classifier, classifier guidance gains fidelity while sacrificing some diversity. Its focus is sample quality rather than diversity.
This trade-off was already studied in GANs and other generative models under “low-temperature sampling,” terminology derived from the Boltzmann machine, an energy-based model.
View the prior as a set of energy-based states . High-energy states are unstable and occupy a larger set; increasing temperature () corresponds to greater sampling diversity. Low-energy states () are stable and occupy a smaller region. Diversity falls, but denser sampling within this restricted state space produces more plausible samples—higher fidelity.
Thus low-temperature sampling trades diversity for fidelity. Examples include the truncation trick, which samples high-feasibility regions, and rejection of poor samples in autoregressive models such as Glow.
“Diffusion Beats GANs” proposes two analogous methods—reducing Gaussian noise at every process or reducing the predicted score—but neither works well.
Lower temperature should improve fidelity or prediction, but the results show no such trend. The method therefore relies on class-guidance scale to control the trade-off.
Guidance without a classifier?
The situation resembles this:
The paper’s motivation comes from the following pipeline. Classifier guidance complicates diffusion training: alongside the U-Net diffusion model, one must separately train a classifier on downsampled features of noised samples at every time step. A conventional pretrained classifier cannot be used. Even if the number of time steps is minimized, this extra model complicates training.
Classifier-guided sampling can also be interpreted as a gradient-based adversarial attack that fools an image classifier. FID and IS are themselves classifier-based metrics. Generating samples that look meaningful to a classifier therefore becomes a direct objective for improving those metrics. The method may score well not because classifier guidance improves true sampling quality, but because its formulation is particularly suited to improving the metrics. A clever observation. Incidentally, “Diffusion Beats GANs” came from OpenAI, while this paper came from Google Brain—almost a clash for the ages.
Background
The training method is surprisingly simple, though its base setting differs slightly from DDPM. It trains a continuous-time diffusion model. For sample from dataset and latent with hyperparameter , forward process is a variance-preserving Markov process:
Defining this marginal for arbitrary continuous gives the adjacent-latent conditional
can be interpreted like SNR in decibels for and : it reduces the preceding input signal while increasing added noise. Conditioning on , applying Bayes’ rule to obtain a posterior, and deriving the loss against parameterized reverse process are identical to DDPM and are omitted. The network objective is
where and . This is score matching over a continuous function. Uniform yields the familiar variational lower bound, but the authors borrow the cosine schedule from classifier-guidance work. Its more gradual noise decay lets the network train evenly across noise distributions.
Classifier guidance
GANs and flow-based models can trade FID against IS through low-temperature sampling, but bringing the idea to diffusion is difficult because the diffusion process fixes construction of the prior. Classifier guidance approximates this effect by adding a noisy-image classifier gradient to the diffusion score:
Classifier influence is a probability scale factor. It encourages generated data to fall inside the desired label’s category under log likelihood, sacrificing diversity to increase fidelity.
The toy experiment makes this clear. Classifier guidance pushes Gaussian distributions farther apart, improving separability while shrinking the volume occupied by each.
Classifier-free guidance
Classifier guidance produces the expected IS/FID trade-off, but remains imperfect low-temperature sampling and depends on an image classifier. Classifier-free guidance seeks the same effect without changing into auxiliary . Above all, it removes dependence on classifier parameters .
Instead of a classifier, the paper jointly trains unconditional diffusion model and conditional model . Rather than build and train two separate networks, one network parameterizes both probabilities:
- For the unconditional model, insert null token instead of class identifier : .
- With hyperparameter probability , generate null-class samples for unconditional training.
- Combine conditional and unconditional predictions as .
The equation contains no classifier gradient , avoiding approximation issues such as the earlier first-order Taylor expansion. Since it does not directly manipulate sampling gradients, it is not an adversarial attack.
Experimental results
I expected an equal split between unconditional and conditional sampling, but does not appear uniformly best. The paper experiments with three probabilities.
Conclusion
The three papers address problems that form a progression. Improved DDPM first analyzes several reasons conventional DDPM samples poorly and tests modifications to address them.
The first classifier paper, from OpenAI, focuses on using classifier guidance to obtain high-quality sampling like GANs and flow-based models while also optimizing the diffusion architecture.
Finally, classifier-free guidance shows that a single diffusion network can learn both unconditional and conditional through joint optimization with and without class conditions. It then constructs classifier-guidance-like score estimation independently of classifier parameter , without separately training a classifier.