Paper commentary
GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models
Guided diffusion models produce photorealistic images from text prompts
- Problem Text-to-image models still fail to produce photorealistic images that capture every part of a prompt. Unconditional diffusion models already reach high fidelity, but no one had brought that quality to text-conditional generation.
- Method GLIDE is a 3.5 billion parameter text-conditional diffusion model. Unlike CLIP guidance, it uses classifier-free guidance, which steers samples without a separate classifier.
- Results Human raters preferred GLIDE samples over DALL-E with CLIP reranking 87% of the time for photorealism and 69% for caption similarity at temperature 0.85.
Why text-conditioned images still fall short
Text-conditional image models can place unrelated objects together in semantically plausible ways, but they cannot yet produce photorealistic images that capture every aspect of a prompt. Unconditional diffusion models, by contrast, can reach fidelity high enough that people sometimes cannot separate their samples from real images. Classifier guidance brought that quality to class-conditional generation by steering samples with the gradients of a separately trained classifier.
Classifier-free guidance reaches a similar effect without a separate classifier, by mixing predictions made with and without the label. The study applies guided diffusion to text-conditional synthesis and compares two ways of steering the sampler towards a caption: CLIP guidance and classifier-free guidance.
The authors find, through human and automated evaluations, that classifier-free guidance gives higher-quality images.
Diffusion sampling and the training objective
When the noise added per step is small, the reverse step is close to a diagonal Gaussian, and when the total noise is large, \(x_T\) is close to \(\mathcal{N}(0,I)\). These two properties justify learning a reverse model \(p_\theta(x_{t-1}|x_t)\), which generates a sample by starting from Gaussian noise and removing noise step by step.
Training uses a surrogate objective rather than the variational lower bound, because it gives better results. The surrogate noises a sample to \(x_t\), trains \(\epsilon_\theta\) to predict the added noise, and minimizes the mean-squared error \(L_{simple}\). The mean \(\mu_\theta(x_t)\) is derived from \(\epsilon_\theta(x_t,t)\) while the variance is held constant in the original formulation, and the authors adopt a later method that learns the variance \(\Sigma_\theta\) so that fewer sampling steps give high-quality samples.
Guidance: classifier, classifier-free and CLIP
In classifier guidance, the class-conditional mean is shifted by a scaled gradient of the log-probability that a classifier assigns to the target class, \(\hat\mu_\theta(x_t|y)=\mu_\theta(x_t|y)+s\cdot\Sigma_\theta(x_t|y)\nabla_{x_t}\log p_\phi(y|x_t)\). The guidance scale \(s\) trades diversity for sample quality, since larger values improve quality but reduce diversity.
Classifier-free guidance replaces the label with a null label at a fixed probability during training, so one model provides both conditional and unconditional predictions. At sampling time the output is extrapolated from the unconditional prediction towards the conditional one, giving \(\hat\epsilon_\theta(x_t|c)=\epsilon_\theta(x_t|\varnothing)+s\cdot(\epsilon_\theta(x_t|c)-\epsilon_\theta(x_t|\varnothing))\), with \(s\geq 1\).
This form is motivated by an implicit classifier whose gradient corresponds to the difference between conditional and unconditional true scores. Two consequences follow: one model guides itself, and no separate text classifier must be trained, which matters because text is hard to predict with a classifier.
CLIP guidance replaces the classifier with a CLIP model, perturbing the reverse-process mean by the gradient of the dot product between the image encoding and the caption encoding, \(\hat\mu_\theta(x_t|c)=\mu_\theta(x_t|c)+s\cdot\Sigma_\theta(x_t|c)\nabla_{x_t}(f(x_t)\cdot g(c))\). The CLIP model must be trained on noised images so that the gradient is meaningful at every step, and the authors call these noised CLIP models.
The authors hypothesize that a public CLIP model, which never saw noised images, degrades sample quality because the intermediate images are out of distribution for it.
Text-conditional model and training
Text is encoded into K tokens by a Transformer, and the final token embedding replaces the class embedding of the ADM backbone. The full token sequence is projected to the width of each attention layer and concatenated to that layer's attention context, so the image layers attend to the text at every level.
The base model keeps the ImageNet 64 by 64 architecture with width scaled to 512 channels, giving roughly 2.3 billion visual parameters, and its text encoder has 24 residual blocks of width 2048, roughly 1.2 billion parameters. A 1.5 billion parameter upsampler takes images from 64 by 64 to 256 by 256, uses a text encoder of width 1024, and raises the base channel count to 384.
The base model was trained for 2.5M iterations at batch size 2048 and the upsampler for 1.6M iterations at batch size 512. Training used 16-bit precision with loss scaling, and the total compute is roughly equal to that used for DALL-E.
For classifier-free guidance, the base model is fine-tuned after the initial run, with 20% of text token sequences replaced by the empty sequence. This keeps the text-conditional ability while also allowing unconditional generation.
Inpainting is trained explicitly rather than only applied at sampling time, because sampling-time replacement of known pixels produced edge artifacts in early experiments. During fine-tuning, random regions are erased, and the remaining pixels are fed in with a mask channel; the input gains four channels, a second RGB set and a mask channel.
The new input weights are initialized to zero before fine-tuning, and the upsampler always receives the full low-resolution image with only the unmasked part of the high-resolution image.
Classifier-free guidance against CLIP guidance
On zero-shot MS-COCO generation at 64 by 64, classifier-free guidance is nearly Pareto optimal for the precision-recall and FID-IS trade-offs. CLIP guidance instead raises the CLIP score much more than classifier-free guidance does, which the authors attribute to adversarial examples for the scoring CLIP model rather than better prompt matching.
To check this, human evaluators compared 256 by 256 images on caption match or photorealism, and a tie gave half a win to each model. In Table 1, unguided sampling scored -88.6 on photorealism and -106.2 on caption, CLIP guidance at scale 2.0 scored -73.2 and 29.3, and classifier-free guidance at scale 3.0 scored 82.7 and 110.9. The Elo scores come from 1,000 comparisons for photorealism and 1,000 for caption similarity, with sweeps over scales using 500 comparisons.
Comparison with DALL-E
Removing images similar to the training set reduced the reference batch by 21% and raised FID from 12.24 to 12.89, which the authors partly attribute to the change in FID bias for a smaller reference batch. Table 2 lists other text-conditional models, including XMC-GAN at 9.33 and LAFITE at 8.12, and the authors describe the result as competitive, because the model was never trained on MS-COCO.
In the human comparison with DALL-E, GLIDE wins 91% of photorealism and 83% of caption-similarity comparisons without reranking at temperature 1.0, and 84% and 80% at temperature 0.85. When DALL-E uses CLIP reranking, the win rates are 89% and 71% at temperature 1.0, and 87% and 69% at temperature 0.85. Passing GLIDE samples through the DALL-E discrete VAE, which blurs them, lowers the win rates to 72% and 63% at temperature 1.0, and 66% and 61% at temperature 0.85.
Text-driven inpainting and editing
Inpainting fills erased regions from a text prompt, matching the style and lighting of the surrounding image, including shadows and reflections. The model can also edit paintings and turn sketches into realistic edits through SDEdit, shown with a sketch and a caption. A scene can be built iteratively: a zero-shot living room is refined by inpainting a painting, a coffee table and a vase of flowers, and then moving the wall up to the couch.
Compared with Blended Diffusion, the fine-tuned model sometimes ignores the prompt and produces an image driven mainly by the context. Masking out the whole context makes the model follow the caption more consistently, but the inserted objects sometimes fit the scene less smoothly.
Data filtering and remaining biases
Training images were filtered for people, violent objects and hate symbols before training the released model, which is a 300 million parameter model. The people filter is an SVM over pre-trained CLIP ViT-B/16 features of three crops, tuned to less than a 1% false negative rate, and it produced no false negatives on a separate batch of 1024 samples.
The violent-object classifier was trained with CLIP-guided search and active learning, and the hate-symbol classifier was trained on two hate symbols common in America.
In red teaming with adversarial prompts, no instance of a recognizable human was found in the filtered model, which the authors take as a sign of a low false-negative rate. Classifier-free guidance amplifies these biases, and the inpainting capability, whose misuse potential the authors flag, is retained.
Pairing the filtered model with an unfiltered public CLIP model allowed some recognizable facial expressions or hateful imagery.
Limitations
The model fails on some prompts that describe highly unusual objects or scenarios, such as a cat with eight legs or a car with triangular wheels. For complex prompts the model can have difficulty producing realistic images, which is why editing was added on top of zero-shot generation.
The hate-symbol classifier has a strong American and Western bias, so it may not filter hateful symbols outside the two it was trained on.
Paper info
- Authors
- Alex Nichol, Prafulla Dhariwal, Aditya Ramesh, Pranav Shyam, Pamela Mishkin, Bob McGrew, Ilya Sutskever, Mark Chen
- Venue
- arXiv · Preprint
- First published
- 2021-12-20
- Added
- 2026-11-12
- Updated
- 2022-3-8
- Version
- v3
- arXiv
- 2112.10741
- Category
- cs.CV · cs.GR · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Alex Nichol, Prafulla Dhariwal, Aditya Ramesh, Pranav Shyam, Pamela Mishkin, Bob McGrew, Ilya Sutskever, Mark Chen (2021). GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models. arXiv:2112.10741v3. https://arxiv.org/abs/2112.10741v3
BibTeX
@misc{nichol2021glide,
title = {{GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models}},
author = {Alex Nichol and Prafulla Dhariwal and Aditya Ramesh and Pranav Shyam and Pamela Mishkin and Bob McGrew and Ilya Sutskever and Mark Chen},
year = {2021},
eprint = {2112.10741},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2112.10741v3}
}