TL;DR
GLIDE is a text-to-image system from OpenAI, described in a 2021 paper by Alex Nichol and colleagues. It is a diffusion model, which makes an image by removing noise in many small steps, and the caption is the condition that steers those steps. The paper compares two ways to push the sampler toward the caption, CLIP guidance and classifier-free guidance, and human raters prefer the second for both photorealism and caption match. The same model, after a short fine-tune, can also fill in a masked part of a photo from a text prompt, so it edits as well as generates.
Builds on: Diffusion Model, Denoising Diffusion Probabilistic Models (DDPM), Classifier-Free Guidance, Learning Transferable Visual Models From Natural Language Supervision (CLIP), Transformer · Leads to: High-Resolution Image Synthesis with Latent Diffusion Models
Why it mattered
Text-to-image generation became a mainstream product category after 2021, and the guidance recipe GLIDE tested at scale is part of its core. Later text-to-image systems, such as those built on latent diffusion, steer their samples with the same classifier-free guidance idea. The paper also gave a direct comparison with the earlier DALL-E system: in its human study, GLIDE samples were preferred to DALL-E samples, and GLIDE is a 3.5 billion parameter model, far smaller than DALL-E's 12 billion.
The editing result changed how people thought about these models. Before GLIDE, diffusion models were used for inpainting by a trick: sample as usual and paste back the known pixels after every step. That trick lets the model see only a noised version of the context. GLIDE showed that a model trained explicitly for inpainting, with a text prompt, produces edits whose lighting and shadows match the surrounding photo. The authors released a smaller filtered model and its weights, so the work could be reproduced and studied outside the lab.
The problem
Before GLIDE, text-to-image models did not yet produce photorealistic images across the range of prompts people use. Systems such as AttnGAN used generative adversarial networks, and DALL-E used an autoregressive model over discrete image codes. Diffusion models already produced very good images without a condition. Dhariwal and Nichol (2021) had shown that a classifier could steer a class-conditional diffusion model toward a label, which gave strong photorealism on ImageNet classes. The open question was how to steer a diffusion model toward free-form text.
Two routes were open. The first was classifier guidance, which needs a classifier that can read noisy images and predict the caption. Training such a classifier for free-form language is hard, and it would be a second network to maintain. The second was CLIP guidance: use CLIP, a model that scores how well an image matches a caption, as the steering signal. Online artists had done this with public CLIP models, but those models were never trained on noisy images, so the steering was unreliable and needed many tricks. GLIDE asks which route gives better images, and it tests both at scale.
How it works
Take one request: the caption is "a red bowl on a table", and the output is a 256 by 256 image. The system has a base model that works at 64 by 64 and an upsampler that raises the resolution.
- The caption goes into a text Transformer, which turns it into a sequence of token features. The base model reads these features in two ways: a summary vector built from the caption, and all the token vectors, which the attention layers can look at. Check: the caption becomes a set of vectors, not a single label.
- The base model starts from pure random noise at 64 by 64. At each step it predicts the noise that is present in the current image. Check: the image is pure noise at the start, and each step should remove a little of it.
- The guided prediction is built from two model runs at the same step. One run is conditioned on the caption. The other run uses an empty caption, which the model was trained to accept. Take a single pixel where the empty-caption prediction is 0.2 and the caption prediction is 0.5. With guidance scale 3, the guided value is 0.2 + 3 × (0.5 − 0.2) = 1.1. Check: scale 1 gives 0.5, the plain caption prediction, and scale 0 gives 0.2, the empty-caption prediction.
- The sampler uses the guided prediction to take one denoising step, producing a slightly cleaner image. This repeats for many steps until the base image is formed.
- The 64 by 64 image goes into the upsampler, which is also conditioned on the caption, and produces the 256 by 256 image.
- The output is the final image.
The alternative in step 3 is CLIP guidance. It does not run a second caption-free prediction. Instead, it moves the image a little in the direction that increases the CLIP score of the image against the caption. Both methods have one number, the guidance scale, that trades diversity for how strongly the output follows the caption.
- guided value at one pixel
flowchart LR A[Caption] --> B[Text transformer: token features] B --> C[Base model at 64 by 64: guided denoising steps] C --> D[Text-conditioned upsampler] D --> E[Image at 256 by 256]
The math
The denoising model (step 2 in symbols)
Let be the image at step , and let be the caption. The model predicts the noise in given the caption. Training minimises the mean squared error between the noise that was added and the noise the network predicts, as in . The caption is replaced by an empty sequence for a fraction of training examples, so the same network also learns .
Classifier-free guidance (step 3 in symbols)
The guided prediction is
where is the guidance scale. Rearranging gives . The two weights add up to 1, so at the result is the plain conditional prediction, and at the result lies beyond it, on the far side from the empty caption.
The reason for this form is an implicit classifier. The gradient of the log of is proportional to , so the difference of the two predictions acts like a classifier gradient without a classifier.
CLIP guidance (step 3, the alternative)
CLIP guidance perturbs the mean of the reverse step instead:
Here is the image encoder and the caption encoder of CLIP, is the model's variance, and the gradient is the direction that raises the image-caption dot product. The paper uses a noised CLIP model, , so that the gradient is meaningful on noisy images.
Inpainting input (step 5 in symbols)
For editing, the base model takes 7 input channels instead of 3. The three RGB channels of the partly erased image are joined by three more RGB channels of the known region and one mask channel. The new input weights start at zero, so at the start of fine-tuning the model behaves exactly as the pretrained one.
Results
Human preference. The paper compares samples in pairwise human evaluations. Classifier-free guidance is preferred over CLIP guidance for both photorealism and caption match, and GLIDE samples are preferred over DALL-E samples. The paper reports these comparisons as rating scores; this lesson does not repeat the exact figures.
Automatic metrics. The paper also reports FID on zero-shot MS-COCO. Lower FID is better, and GLIDE was not trained on MS-COCO. The paper shows that CLIP guidance can raise the CLIP score more than classifier-free guidance can, while classifier-free guidance does better on the distribution-matching metrics. The paper reads this as CLIP guidance exploiting the evaluation model rather than matching the prompt better.
Limits. Sampling with many diffusion steps is much slower than a GAN, which produces an image in one forward pass. GLIDE sometimes fails on unusual objects or scenarios. The filtered release still reproduces dataset biases, and classifier-free guidance can amplify them. The human evaluations are at 256 by 256 and do not measure every use.
Reading guide
- §1 Introduction: the goal, the two guidance strategies and the headline human results. Needs Diffusion Model and Classifier-Free Guidance as background.
- §2.1 Diffusion models: the forward noising chain and the learned reverse step. Needs Diffusion Model, Denoising Diffusion Probabilistic Models (DDPM), Markov Chain and Gaussian (Normal) Distribution.
- §2.2–2.3 Guided diffusion and classifier-free guidance: the implicit classifier and the guided formula. Needs Classifier Guidance, Classifier-Free Guidance and Score Function.
- §2.4 CLIP guidance: the image-caption score and its gradient. Needs Learning Transferable Visual Models From Natural Language Supervision (CLIP), Contrastive Learning and Dot Product.
- §3 Related work: skim; it names the GAN, autoregressive and inpainting lines covered above.
- §4.1 Architecture and training: the U-Net-style network with a text transformer. Needs U-Net, Transformer and Attention Mechanism.
- §4.2–4.4: classifier-free fine-tuning, inpainting channels and noised CLIP. Needs Classifier-Free Guidance and Vision Transformer (ViT) for the ViT-L CLIP encoder.
- §5 Results: FID, precision and recall, and human preference scores. Needs Fréchet Inception Distance and Precision and Recall.
- §6–7 Safety and limitations: no new technical prerequisites; read for context on filtering and deployment.
Check yourself
QuestionAt one pixel the empty-caption prediction is and the caption prediction is . What is the classifier-free guided value at scale ?Show answer
The difference is . Multiply by the scale: . Add the empty-caption prediction: . The answer is . Check: at the answer would be , and at it would be , so lies beyond the caption prediction as expected.
QuestionWhy does GLIDE set the new input weights of the inpainting model to zero before fine-tuning?Show answer
A zero weight makes the new channels contribute nothing at the start, so the first forward pass gives exactly the output of the pretrained model. The network keeps its text-conditional behaviour, and training then learns how to use the mask and the known pixels gradually, without damaging what it already knows.
QuestionWhy does the paper say that classifier-free guidance does not need a separate classifier, and what does it use in its place?Show answer
Classifier-free guidance uses the same network twice: once with the caption and once with the empty caption, which the model learns during training by dropping the caption for some examples. The difference between the two predictions plays the role of the classifier gradient in classifier guidance. No second network has to read noisy images and predict the caption.
QuestionA team wants to cut the base model's sampling cost by using half as many denoising steps as the paper's sampler. What should they do before adopting it?Show answer
The steps are the main cost, so fewer steps is faster, but the quality effect has to be measured, not assumed. The team should compare FID and human preference at the reduced step count against the paper's setting, and check the failure modes the paper lists, such as unusual objects and biased outputs, before using the cheaper sampler.
Sources
- Nichol et al., GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models, arXiv:2112.10741 (2021). https://arxiv.org/abs/2112.10741
- Ho and Salimans, Classifier-Free Diffusion Guidance, arXiv:2207.12598 (2021). https://arxiv.org/abs/2207.12598
- Radford et al., Learning Transferable Visual Models From Natural Language Supervision, arXiv:2103.00020 (2021). https://arxiv.org/abs/2103.00020
- Code and weights released with GLIDE: https://github.com/openai/glide-text2im