# Zero-Shot Text-to-Image Generation

Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford and 2 more · arXiv · 2021-2-24

- **Problem** Text-to-image models have mostly relied on specialized architectures and training losses, and they have been evaluated on small datasets such as MS-COCO and CUB-200.
- **Method** Trains a 12-billion parameter sparse transformer that models caption tokens and image tokens as one sequence, with the image tokens produced by a discrete VAE trained first.
- **Results** Reached a 90% majority-vote preference for realism against DF-GAN on MS-COCO captions, and an FID within 2 points of the best prior approach without training on the captions.

![Figure 10: Illustration of the embedding scheme for a hypothetical version of our transformer with a maximum text length of 6 tokens. Each box denotes a vector…](https://refivu.com/papers/ec261d9b-e98a-4dcc-8961-c79073db25e2/figures/figure-36c714559ca530136a7235fb1f39b4fb.png?thumb=512)

**Figure 10** . Illustration of the embedding scheme for a hypothetical version of our transformer with a maximum text length of 6 tokens. Each box denotes a vector of sizedmodel = 3968. In this illustration, the caption has a length of 4 tokens, so 2 padding tokens are used (as described in Section 2.2). Each image vocabulary embedding is summed with a row and column embedding.

[Original paper](https://arxiv.org/abs/2102.12092v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, Ilya Sutskever · Zero-Shot Text-to-Image Generation · Original paper figure · Extracted the figure area from page 13 of the original PDF.

## Why scale might matter for text-to-image generation

Text-to-image generation started when a recurrent generative model was conditioned on captions, and adversarial training later improved image fidelity. Most later progress came from better generator architectures, attention and auxiliary losses, and extra conditioning signals beyond text. Evaluation has mostly used small datasets such as MS-COCO and CUB-200, so it is unclear whether dataset size and model size are the limiting factors.

Even the best of these systems produce samples with object distortion, illogical object placement, and unnatural blending of foreground and background. Autoregressive transformers have worked well for text, images and audio when compute, model size and data are scaled together, which suggests the same recipe could help here. The study trains a 12-billion parameter autoregressive transformer on 250 million image-text pairs and evaluates it zero-shot.

## One token stream for captions and images

Feeding raw pixels to a transformer would need too much memory at high resolution, and a likelihood objective on pixels spends most of its capacity on short-range, high-frequency detail rather than on the coarse structure that makes objects recognizable. The approach therefore first compresses each image into discrete tokens, and then models caption tokens and image tokens together as one sequence with a transformer.

The training objective is an evidence lower bound on the joint likelihood of images x, captions y and image tokens z, written with the factorization \\(p\_{\\theta,\\psi}(x,y,z)=p\_\\theta(x\\mid y,z)\\,p\_\\psi(y,z)\\). The bound holds exactly only when the KL weight \\(\\beta\\) equals 1, but larger values are used in practice. Training runs in two stages: the first fits the discrete autoencoder on images alone, and the second holds it fixed and fits the transformer prior over text and image tokens.

## Compressing images into a 32×32 token grid

The discrete VAE maps each 256×256 RGB image to a 32×32 grid of tokens, and each grid position chooses one of 8192 codebook values.

Because the encoder produces categorical distributions over the codebook, the bound contains a discrete expectation that gradients cannot pass through directly. The authors replace it with the gumbel-softmax relaxation, which becomes tight as the temperature tends to zero, and maximize the relaxed bound with Adam and exponentially weighted iterate averaging.

Several choices mattered for stable training: annealing the temperature to 1/16, using 1×1 convolutions at the encoder end and decoder start, scaling resblock activations by a small constant, and raising the KL weight to 6.6. The KL weight rises from 0 to 6.6 over the first 5000 updates on a cosine schedule. Reconstruction uses a logit-Laplace likelihood, which is the Laplace distribution after a sigmoid, so that its mass stays inside the bounded pixel range.

## Training the sparse transformer prior

Each caption is lowercased and BPE-encoded into at most 256 tokens from a vocabulary of 16,384 entries. Each image gives 1024 tokens from the 8192-entry vocabulary, taken as the argmax of the encoder logits without Gumbel noise.

The prior is a decoder-only sparse transformer with 64 self-attention layers, in which each image token can attend to every text token. Text-to-text attention is causal, and image-to-image attention uses row, column or convolutional masks. Instead of masking the padding positions after the caption, the model learns a separate padding token for each of the 256 text positions.

The text and image cross-entropy losses are normalized by their token counts and weighted by 1/8 and 7/8, which puts most of the weight on image modeling. Captions use 10% BPE dropout, and the training images use random square crops without horizontal flips, because images may contain text. The model was trained on 1024 16 GB NVIDIA V100 GPUs for 430,000 updates, with about 606,000 images reserved for validation.

## Keeping 16-bit training of a 12-billion parameter model stable

Most parameters, Adam moments and activations are stored in 16-bit precision with activation checkpointing, and underflow in the 16-bit gradients is identified as the root cause of the instability past one billion parameters. Standard loss scaling works only when the spread of activation gradients fits the 16-bit exponent range, and with five exponent bits that range was too small for this model.

Per-resblock gradient scaling gives each of the 128 resblocks its own gradient scale. Incoming gradients are scaled, outgoing gradients are unscaled before they join the sum from later resblocks, and non-finite values are filtered from the activation gradient. The activation gradient norms fall from the earlier resblocks to the later ones, so later resblocks are the ones that underflow.

A 12-billion parameter model takes about 24 GB in 16-bit precision, which exceeds a 16 GB V100 GPU. Parameter sharding splits each parameter array across the eight GPUs of a machine and gathers the shards for the next resblock while the current one is computed.

Inter-machine bandwidth is much lower than the bandwidth within a machine, so averaging gradients across machines becomes the main bottleneck. PowerSGD replaces the gradient all-reduce with two smaller all-reduces on low-rank factors, and the error between the true and compressed gradient is kept in an error buffer.

## Reranking samples with a contrastive model

Candidate images are drawn from the transformer and scored by a pretrained contrastive model for how well each matches the caption, and the top-ranked candidates are kept. The main results use N = 512 samples without temperature reduction, so t = 1.

This acts as a language-guided search and is similar to an auxiliary text-image matching loss.

## Zero-shot results on MS-COCO

The model is compared with AttnGAN, DM-GAN and DF-GAN, and DF-GAN reports the best Inception Score and FID among those baselines. The baselines are trained on MS-COCO, whereas this model was never trained on its captions.

In a human evaluation against DF-GAN, workers compared two images in a best-of-five vote, and the model's sample won 93% of the time for matching the caption. The same comparison gave 90% for the more realistic image, and the model is preferred over the prior work trained on the dataset 90% of the time.

On MS-COCO the FID is within 2 points of the best prior approach.

## Blur and reranking-size checks

The gap to other models widens as the blur radius grows, which the authors connect to the compressed tokens being unable to produce high-frequency detail. The same blur sweep was run on CUB, and FID and IS curves were computed against validation sets with and without overlapping images.

Duplicates were identified with a contrastive model trained for that task, and images were removed at a threshold chosen by hand to keep false negatives low.

FID and IS improve as the reranking sample size grows, and the gains continue up to 32 samples before they diminish.

## Qualitative behaviour: composition, text and translation

The authors read this as a rudimentary ability to compose unusual concepts.

With the top 15×32 token rows taken from a cat photo and a caption asking for a sketch below, the model draws a similar cat at the bottom. The same setup works with color changes, grayscale, upside-down flips and style transfer, with varying reliability, and these translations were not targeted by any change to training.

## Limits of the zero-shot evidence

On CUB the model's FID trails the leading prior approach by a nearly 40-point gap. The authors suspect that zero-shot training is less suited to specialized distributions such as CUB, and they leave fine-tuning, which they consider promising, to future work.

About 12% of the CUB images overlap with the training data, and removing them did not change the results significantly.

Variable binding prompts are handled inconsistently, so the model cannot be relied on for binding attributes to the right objects. Composition, text rendering and image-to-image translation are reported through examples, and the text gives no scores for them.

## Paper info

- **Authors**: Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, Ilya Sutskever
- **Venue**: arXiv · Preprint
- **First published**: 2021-2-24
- **Added**: 2026-10-20
- **Updated**: 2021-2-26
- **Version**: v2
- **arXiv**: 2102.12092
- **Category**: cs.CV · cs.LG
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2102.12092v2) · [PDF ↗](https://arxiv.org/pdf/2102.12092v2)

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.

## Abstract

Text-to-image generation has traditionally focused on finding better modeling assumptions for training on a fixed dataset. These assumptions might involve complex architectures, auxiliary losses, or side information such as object part labels or segmentation masks supplied during training. We describe a simple approach for this task based on a transformer that autoregressively models the text and image tokens as a single stream of data. With sufficient data and scale, our approach is competitive with previous domain-specific models when evaluated in a zero-shot fashion.

## Quote from the paper

Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, Ilya Sutskever (2021). Zero-Shot Text-to-Image Generation. arXiv:2102.12092v2. https://arxiv.org/abs/2102.12092v2

**BibTeX**

```
@misc{ramesh2021zero,
  title = {{Zero-Shot Text-to-Image Generation}},
  author = {Aditya Ramesh and Mikhail Pavlov and Gabriel Goh and Scott Gray and Chelsea Voss and Alec Radford and Mark Chen and Ilya Sutskever},
  year = {2021},
  eprint = {2102.12092},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2102.12092v2}
}
```

## Other paper commentary

- [Score-Based Generative Modeling through Stochastic Differential Equations](https://refivu.com/en/papers/11d114a6-a425-47ea-9133-db43e9c355d2-score-based-generative-modeling-through-stochastic.md)
- [Denoising Diffusion Probabilistic Models](https://refivu.com/en/papers/3a1faf88-ed3a-4c3a-bf1e-1afc6e7184fa-denoising-diffusion-probabilistic-models.md)
- [High-Resolution Image Synthesis with Latent Diffusion Models](https://refivu.com/en/papers/33bd1500-c829-47e5-9545-ad078523241e-high-resolution-image-synthesis-with-latent-diffusion-models.md)
- [Generative Adversarial Networks](https://refivu.com/en/papers/b0edf89c-f6c4-4cce-9c25-eccaea8dcfc9-generative-adversarial-networks.md)
- [Auto-Encoding Variational Bayes](https://refivu.com/en/papers/90411040-94ff-4aca-9d04-a1a99cad3eb4-auto-encoding-variational-bayes.md)
- [Absorbing Quantization Error by Deformable Noise Scheduler for Diffusion Models](https://refivu.com/en/papers/10a7b7b0-1927-4b83-a47b-a8a00da5f0c5-absorbing-quantization-error-by-deformable-noise-scheduler.md)
- [Deep reinforcement learning from human preferences](https://refivu.com/en/papers/46d079bb-6a3c-401d-94a4-5ceb66ab32a1-deep-reinforcement-learning-from-human-preferences.md)
- [Training language models to follow instructions with human feedback](https://refivu.com/en/papers/9a0e4c9e-5f65-4b6a-b559-76f0a9c35e07-training-language-models-to-follow-instructions-with-human.md)
- [Chain-of-Thought Prompting Elicits Reasoning in Large Language Models](https://refivu.com/en/papers/453dc85c-e794-4846-bb89-b8b678635169-chain-of-thought-prompting-elicits-reasoning-in-large.md)
- [Llama 2: Open Foundation and Fine-Tuned Chat Models](https://refivu.com/en/papers/5c1523c3-cd1c-48ba-8289-86de02d688dd-llama-2-open-foundation-and-fine-tuned-chat.md)
- [Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model](https://refivu.com/en/papers/b99bbef4-e405-4227-881f-01ef69bed080-mastering-atari-go-chess-and-shogi-by-planning.md)
- [Mixtral of Experts](https://refivu.com/en/papers/5e1d3fc2-10c6-4121-ba03-4ef4430aadca-mixtral-of-experts.md)

## Terms in this paper

- [ADAM](https://refivu.com/en/terms/0e9ad0199e08-adam)
- [FID](https://refivu.com/en/terms/e110afe65f86-fid)
- [inception score](https://refivu.com/en/terms/25dbfbd4fd96-inception-score)
- [MS-COCO](https://refivu.com/en/terms/3c7d75a4a2eb-ms-coco)
- [Human evaluation](https://refivu.com/en/terms/b64307b0a4d2-human-evaluation)
- [CUB](https://refivu.com/en/terms/1db8c8020177-cub)
- [image-to-image translation](https://refivu.com/en/terms/7343a28bca2c-image-to-image-translation)
- [BPE](https://refivu.com/en/terms/8f51fddd26a4-bpe)
- [evidence lower bound](https://refivu.com/en/terms/ab8bf35324c3-evidence-lower-bound)
- [Gumbel-Softmax](https://refivu.com/en/terms/e169554398b3-gumbel-softmax)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/ec261d9b-e98a-4dcc-8961-c79073db25e2-zero-shot-text-to-image-generation)
