Photorealistic Text-to-Image Diffusion Models with Deep Language Understanding

Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Burcu Karagol Ayan, S. Sara Mahdavi, Rapha Gontijo Lopes, Tim Salimans, Jonathan Ho, David J Fleet, Mohammad Norouzi

Introduction

Multimodal learning has come into prominence recently, with text-to-image synthesis and image-text contrastive learning at the forefront. These models have transformed the research community and captured widespread public attention with creative image generation and editing applications . To pursue this research direction further, we introduce Imagen, a text-to-image diffusion model that combines the power of transformer language models (LMs) with high-fidelity diffusion models to deliver an unprecedented degree of photorealism and a deep level of language understanding in text-to-image synthesis. In contrast to prior work that uses only image-text data for model training [e.g., 53, 41], the key finding behind Imagen is that text embeddings from large LMs , pretrained on text-only corpora, are remarkably effective for text-to-image synthesis. See Fig. 1 for select samples.

Imagen comprises a frozen T5-XXL encoder to map input text into a sequence of embeddings and a 64 ⁣× ⁣6464\!\times\!64 image diffusion model, followed by two super-resolution diffusion models for generating 256 ⁣× ⁣256256\!\times\!256 and 1024 ⁣× ⁣10241024\!\times\!1024 images (see Fig. A.4). All diffusion models are conditioned on the text embedding sequence and use classifier-free guidance . Imagen relies on new sampling techniques to allow usage of large guidance weights without sample quality degradation observed in prior work, resulting in images with higher fidelity and better image-text alignment than previously possible.

While conceptually simple and easy to train, Imagen yields surprisingly strong results. Imagen outperforms other methods on COCO with zero-shot FID-30K of 7.27, significantly outperforming prior work such as GLIDE (at 12.4) and the concurrent work of DALL-E 2 (at 10.4). Our zero-shot FID score is also better than state-of-the-art models trained on COCO, e.g., Make-A-Scene (at 7.6). Additionally, human raters indicate that generated samples from Imagen are on-par in image-text alignment to the reference images on COCO captions.

We introduce DrawBench, a new structured suite of text prompts for text-to-image evaluation. DrawBench enables deeper insights through a multi-dimensional evaluation of text-to-image models, with text prompts designed to probe different semantic properties of models. These include compositionality, cardinality, spatial relations, the ability to handle complex text prompts or prompts with rare words, and they include creative prompts that push the limits of models’ ability to generate highly implausible scenes well beyond the scope of the training data. With DrawBench, extensive human evaluation shows that Imagen outperforms other recent methods by a significant margin. We further demonstrate some of the clear advantages of the use of large pre-trained language models over multi-modal embeddings such as CLIP as a text encoder for Imagen.

We discover that large frozen language models trained only on text data are surprisingly very effective text encoders for text-to-image generation, and that scaling the size of frozen text encoder improves sample quality significantly more than scaling the size of image diffusion model.

We introduce dynamic thresholding, a new diffusion sampling technique to leverage high guidance weights and generating more photorealistic and detailed images than previously possible.

We highlight several important diffusion architecture design choices and propose Efficient U-Net, a new architecture variant which is simpler, converges faster and is more memory efficient.

We achieve a new state-of-the-art COCO FID of 7.27. Human raters find Imagen to be on-par with the reference images in terms of image-text alignment.

We introduce DrawBench, a new comprehensive and challenging evaluation benchmark for the text-to-image task. On DrawBench human evaluation, we find Imagen to outperform all other work, including the concurrent work of DALL-E 2 .

Imagen

Imagen consists of a text encoder that maps text to a sequence of embeddings and a cascade of conditional diffusion models that map these embeddings to images of increasing resolutions (see Fig. A.4). In the following subsections, we describe each of these components in detail.

Text-to-image models need powerful semantic text encoders to capture the complexity and compositionality of arbitrary natural language text inputs. Text encoders trained on paired image-text data are standard in current text-to-image models; they can be trained from scratch or pretrained on image-text data (e.g., CLIP ). The image-text training objectives suggest that these text encoders may encode visually semantic and meaningful representations especially relevant for the text-to-image generation task. Large language models can be another models of choice to encode text for text-to-image generation. Recent progress in large language models (e.g., BERT , GPT , T5 ) have led to leaps in textual understanding and generative capabilities. Language models are trained on text only corpus significantly larger than paired image-text data, thus being exposed to a very rich and wide distribution of text. These models are also generally much larger than text encoders in current image-text models (e.g. PaLM has 540B parameters, while CoCa has a ≈\approx 1B parameter text encoder).

It thus becomes natural to explore both families of text encoders for the text-to-image task. Imagen explores pretrained text encoders: BERT , T5 and CLIP . For simplicity, we freeze the weights of these text encoders. Freezing has several advantages such as offline computation of embeddings, resulting in negligible computation or memory footprint during training of the text-to-image model. In our work, we find that there is a clear conviction that scaling the text encoder size improves the quality of text-to-image generation. We also find that while T5-XXL and CLIP text encoders perform similarly on simple benchmarks such as MS-COCO, human evaluators prefer T5-XXL encoders over CLIP text encoders in both image-text alignment and image fidelity on DrawBench, a set of challenging and compositional prompts. We refer the reader to Section 4.4 for summary of our findings, and Appendix D.1 for detailed ablations.

2 Diffusion models and classifier-free guidance

Here we give a brief introduction to diffusion models; a precise description is in Appendix A. Diffusion models are a class of generative models that convert Gaussian noise into samples from a learned data distribution via an iterative denoising process. These models can be conditional, for example on class labels, text, or low-resolution images [e.g. 16, 29, 59, 58, 75, 41, 54]. A diffusion model x^θ\hat{\mathbf{x}}_{\theta} is trained on a denoising objective of the form

where (x,c)(\mathbf{x},\mathbf{c}) are data-conditioning pairs, t∼U()t\sim\mathcal{U}(), ϵ∼N(0,I){\boldsymbol{\epsilon}}\sim\mathcal{N}(\mathbf{0},\mathbf{I}), and αt,σt,wt\alpha_{t},\sigma_{t},w_{t} are functions of tt that influence sample quality. Intuitively, x^θ\hat{\mathbf{x}}_{\theta} is trained to denoise zt≔αtx+σtϵ\mathbf{z}_{t}\coloneqq\alpha_{t}\mathbf{x}+\sigma_{t}{\boldsymbol{\epsilon}} into x\mathbf{x} using a squared error loss, weighted to emphasize certain values of tt. Sampling such as the ancestral sampler and DDIM start from pure noise z1∼N(0,I)\mathbf{z}_{1}\sim\mathcal{N}(\mathbf{0},\mathbf{I}) and iteratively generate points zt1,…,ztT\mathbf{z}_{t_{1}},\dotsc,\mathbf{z}_{t_{T}}, where 1=t1>⋯>tT=01=t_{1}>\cdots>t_{T}=0, that gradually decrease in noise content. These points are functions of the x\mathbf{x}-predictions x^0t≔x^θ(zt,c)\hat{\mathbf{x}}^{t}_{0}\coloneqq\hat{\mathbf{x}}_{\theta}(\mathbf{z}_{t},\mathbf{c}).

Here, ϵθ(zt,c){\boldsymbol{\epsilon}}_{\theta}(\mathbf{z}_{t},\mathbf{c}) and ϵθ(zt){\boldsymbol{\epsilon}}_{\theta}(\mathbf{z}_{t}) are conditional and unconditional ϵ{\boldsymbol{\epsilon}}-predictions, given by ϵθ≔(zt−αtx^θ)/σt{\boldsymbol{\epsilon}}_{\theta}\coloneqq(\mathbf{z}_{t}-\alpha_{t}\hat{\mathbf{x}}_{\theta})/\sigma_{t}, and ww is the guidance weight. Setting w=1w=1 disables classifier-free guidance, while increasing w>1w>1 strengthens the effect of guidance. Imagen depends critically on classifier-free guidance for effective text conditioning.

3 Large guidance weight samplers

We corroborate the results of recent text-guided diffusion work and find that increasing the classifier-free guidance weight improves image-text alignment, but damages image fidelity producing highly saturated and unnatural images . We find that this is due to a train-test mismatch arising from high guidance weights. At each sampling step tt, the x\mathbf{x}-prediction x^0t\hat{\mathbf{x}}^{t}_{0} must be within the same bounds as training data x\mathbf{x}, i.e. within $,butwefindempiricallythathighguidanceweightscause, but we find empirically that high guidance weights cause\mathbf{x}$-predictions to exceed these bounds. This is a train-test mismatch, and since the diffusion model is iteratively applied on its own output throughout sampling, the sampling process produces unnatural images and sometimes even diverges. To counter this problem, we investigate static thresholding and dynamic thresholding. See Appendix Fig. A.31 for reference implementation of the techniques and Appendix Fig. A.9 for visualizations of their effects.

Static thresholding: We refer to elementwise clipping the x\mathbf{x}-prediction to $$ as static thresholding. This method was in fact used but not emphasized in previous work , and to our knowledge its importance has not been investigated in the context of guided sampling. We discover that static thresholding is essential to sampling with large guidance weights and prevents generation of blank images. Nonetheless, static thresholding still results in over-saturated and less detailed images as the guidance weight further increases.

Dynamic thresholding: We introduce a new dynamic thresholding method: at each sampling step we set ss to a certain percentile absolute pixel value in x^0t\hat{\mathbf{x}}^{t}_{0}, and if s>1s>1, then we threshold x^0t\hat{\mathbf{x}}^{t}_{0} to the range [−s,s][-s,s] and then divide by ss. Dynamic thresholding pushes saturated pixels (those near -1 and 1) inwards, thereby actively preventing pixels from saturation at each step. We find that dynamic thresholding results in significantly better photorealism as well as better image-text alignment, especially when using very large guidance weights.

4 Robust cascaded diffusion models

Imagen utilizes a pipeline of a base 64×6464\times 64 model, and two text-conditional super-resolution diffusion models to upsample a 64×6464\times 64 generated image into a 256×256256\times 256 image, and then to 1024×10241024\times 1024 image. Cascaded diffusion models with noise conditioning augmentation have been extremely effective in progressively generating high-fidelity images. Furthermore, making the super-resolution models aware of the amount of noise added, via noise level conditioning, significantly improves the sample quality and helps improving the robustness of the super-resolution models to handle artifacts generated by lower resolution models . Imagen uses noise conditioning augmentation for both the super-resolution models. We find this to be a critical for generating high fidelity images.

5 Neural network architecture

Base model: We adapt the U-Net architecture from for our base 64×6464\times 64 text-to-image diffusion model. The network is conditioned on text embeddings via a pooled embedding vector, added to the diffusion timestep embedding similar to the class embedding conditioning method used in . We further condition on the entire sequence of text embeddings by adding cross attention over the text embeddings at multiple resolutions. We study various methods of text conditioning in Section D.3.1. Furthermore, we found Layer Normalization for text embeddings in the attention and pooling layers to help considerably improve performance.

Super-resolution models: For 64×64→256×25664\times 64\rightarrow 256\times 256 super-resolution, we use the U-Net model adapted from . We make several modifications to this U-Net model for improving memory efficiency, inference time and convergence speed (our variant is 2-3x faster in steps/second over the U-Net used in ). We call this variant Efficient U-Net (See Appendix B.1 for more details and comparisons). Our 256×256→1024×1024256\times 256\rightarrow 1024\times 1024 super-resolution model trains on 64×64→256×25664\times 64\rightarrow 256\times 256 crops of the 1024×10241024\times 1024 image. To facilitate this, we remove the self-attention layers, however we keep the text cross-attention layers which we found to be critical. During inference, the model receives the full 256×256256\times 256 low-resolution images as inputs, and returns upsampled 1024×10241024\times 1024 images as outputs. Note that we use text cross attention for both our super-resolution models.

Evaluating Text-to-Image Models

The COCO validation set is the standard benchmark for evaluating text-to-image models for both the supervised and the zero-shot setting . The key automated performance metrics used are FID to measure image fidelity, and CLIP score to measure image-text alignment. Consistent with previous works, we report zero-shot FID-30K, for which 30K prompts are drawn randomly from the validation set, and the model samples generated on these prompts are compared with reference images from the full validation set. Since guidance weight is an important ingredient to control image quality and text alignment, we report most of our ablation results using trade-off (or pareto) curves between CLIP and FID scores across a range of guidance weights.

Both FID and CLIP scores have limitations, for example FID is not fully aligned with perceptual quality , and CLIP is ineffective at counting . Due to these limitations, we use human evaluation to assess image quality and caption similarity, with ground truth reference caption-image pairs as a baseline. We use two experimental paradigms:

To probe image quality, the rater is asked to select between the model generation and reference image using the question: “Which image is more photorealistic (looks more real)?”. We report the percentage of times raters choose model generations over reference images (the preference rate).

To probe alignment, human raters are shown an image and a prompt and asked “Does the caption accurately describe the above image?”. They must respond with “yes”, “somewhat”, or “no”. These responses are scored as 100, 50, and 0, respectively. These ratings are obtained independently for model samples and reference images, and both are reported.

For both cases we use 200 randomly chosen image-caption pairs from the COCO validation set. Subjects were shown batches of 50 images. We also used interleaved “control" trials, and only include rater data from those who correctly answered at least 80% of the control questions. This netted 73 and 51 ratings per image for image quality and image-text alignment evaluations, respectively.

DrawBench: While COCO is a valuable benchmark, it is increasingly clear that it has a limited spectrum of prompts that do not readily provide insight into differences between models (e.g., see Sec. 4.2). Recent work by proposed a new evaluation set called PaintSkills to systematically evaluate visual reasoning skills and social biases beyond COCO. With similar motivation, we introduce DrawBench, a comprehensive and challenging set of prompts that support the evaluation and comparison of text-to-image models. DrawBench contains 11 categories of prompts, testing different capabilities of models such as the ability to faithfully render different colors, numbers of objects, spatial relations, text in the scene, and unusual interactions between objects. Categories also include complex prompts, including long, intricate textual descriptions, rare words, and also misspelled prompts. We also include sets of prompts collected from DALL-E , Gary Marcus et al. and Reddit. Across these 11 categories, DrawBench comprises 200 prompts in total, striking a good balance between the desire for a large, comprehensive dataset, and small enough that human evaluation remains feasible. (Appendix C provides a more detailed description of DrawBench. Fig. 2 shows example prompts from DrawBench with Imagen samples.)

We use DrawBench to directly compare different models. To this end, human raters are presented with two sets of images, one from Model A and one from Model B, each of which has 8 samples. Human raters are asked to compare Model A and Model B on sample fidelity and image-text alignment. They respond with one of three choices: Prefer Model A; Indifferent; or Prefer Model B.

Experiments

Section 4.1 describes training details, Sections 4.2 and 4.3 analyze results on MS-COCO and DrawBench, and Section 4.4 summarizes our ablation studies and key findings. For all experiments below, the images are fair random samples from Imagen with no post-processing or re-ranking.

Unless specified, we train a 2B parameter model for the 64×6464\times 64 text-to-image synthesis, and 600M and 400M parameter models for 64×64→256×25664\times 64\rightarrow 256\times 256 and 256×256→1024×1024256\times 256\rightarrow 1024\times 1024 for super-resolution respectively. We use a batch size of 2048 and 2.5M training steps for all models. We use 256 TPU-v4 chips for our base 64×6464\times 64 model, and 128 TPU-v4 chips for both super-resolution models. We do not find over-fitting to be an issue, and we believe further training might improve overall performance. We use Adafactor for our base 64×6464\times 64 model, because initial comparisons with Adam suggested similar performance with much smaller memory footprint for Adafactor. For super-resolution models, we use Adam as we found Adafactor to hurt model quality in our initial ablations. For classifier-free guidance, we joint-train unconditionally via zeroing out the text embeddings with 10% probability for all three models. We train on a combination of internal datasets, with ≈\approx 460M image-text pairs, and the publicly available Laion dataset , with ≈\approx 400M image-text pairs. There are limitations in our training data, and we refer the reader to Section 6 for details. See Appendix F for more implementation details.

2 Results on COCO

We evaluate Imagen on the COCO validation set using FID score, similar to . Table 2 displays the results. Imagen achieves state of the art zero-shot FID on COCO at 7.27, outperforming the concurrent work of DALL-E 2 and even models trained on COCO. Table 2 reports the human evaluation to test image quality and alignment on the COCO validation set. We report results on the original COCO validation set, as well as a filtered version in which all reference data with people have been removed. For photorealism, Imagen achieves 39.2% preference rate indicating high image quality generation. On the set with no people, there is a boost in preference rate of Imagen to 43.6%, indicating Imagen’s limited ability to generate photorealistic people. On caption similarity, Imagen’s score is on-par with the original reference images, suggesting Imagen’s ability to generate images that align well with COCO captions.

3 Results on DrawBench

Diffusion models have seen wide success in image generation , outperforming GANs in fidelity and diversity, without training instability and mode collapse issues . Autoregressive models , GANs , VQ-VAE Transformer-based methods , and diffusion models have seen remarkable progress in text-to-image , including the concurrent DALL-E 2 , which uses a diffusion prior on CLIP text latents and cascaded diffusion models to generate high resolution 1024×10241024\times 1024 images; we believe Imagen is much simpler, as Imagen does not need to learn a latent prior, yet achieves better results in both MS-COCO FID and human evaluation on DrawBench. GLIDE also uses cascaded diffusion models for text-to-image, but we use large pretrained frozen language models, which we found to be instrumental to both image fidelity and image-text alignment. XMC-GAN also uses BERT as a text encoder, but we scale to much larger text encoders and demonstrate the effectiveness thereof. The use of cascaded models is also popular throughout the literature and has been used with success in diffusion models to generate high resolution images .

Imagen showcases the effectiveness of frozen large pretrained language models as text encoders for the text-to-image generation using diffusion models. Our observation that scaling the size of these language models have significantly more impact than scaling the U-Net size on overall performance encourages future research directions on exploring even bigger language models as text encoders. Furthermore, through Imagen we re-emphasize the importance of classifier-free guidance, and we introduce dynamic thresholding, which allows usage of much higher guidance weights than seen in previous works. With these novel components, Imagen produces 1024×10241024\times 1024 samples with unprecedented photorealism and alignment with text.

Our primary aim with Imagen is to advance research on generative methods, using text-to-image synthesis as a test bed. While end-user applications of generative methods remain largely out of scope, we recognize the potential downstream applications of this research are varied and may impact society in complex ways. On the one hand, generative models have a great potential to complement, extend, and augment human creativity . Text-to-image generation models, in particular, have the potential to extend image-editing capabilities and lead to the development of new tools for creative practitioners. On the other hand, generative methods can be leveraged for malicious purposes, including harassment and misinformation spread , and raise many concerns regarding social and cultural exclusion and bias . These considerations inform our decision to not to release code or a public demo. In future work we will explore a framework for responsible externalization that balances the value of external auditing with the risks of unrestricted open-access.

Another ethical challenge relates to the large scale data requirements of text-to-image models, which have have led researchers to rely heavily on large, mostly uncurated, web-scraped datasets. While this approach has enabled rapid algorithmic advances in recent years, datasets of this nature have been critiqued and contested along various ethical dimensions. For example, public and academic discourse regarding appropriate use of public data has raised concerns regarding data subject awareness and consent . Dataset audits have revealed these datasets tend to reflect social stereotypes, oppressive viewpoints, and derogatory, or otherwise harmful, associations to marginalized identity groups . Training text-to-image models on this data risks reproducing these associations and causing significant representational harm that would disproportionately impact individuals and communities already experiencing marginalization, discrimination and exclusion within society. As such, there are a multitude of data challenges that must be addressed before text-to-image models like Imagen can be safely integrated into user-facing applications. While we do not directly address these challenges in this work, an awareness of the limitations of our training data guide our decision not to release Imagen for public use. We strongly caution against the use text-to-image generation methods for any user-facing tools without close care and attention to the contents of the training dataset.

Imagen’s training data was drawn from several pre-existing datasets of image and English alt-text pairs. A subset of this data was filtered to removed noise and undesirable content, such as pornographic imagery and toxic language. However, a recent audit of one of our data sources, LAION-400M , uncovered a wide range of inappropriate content including pornographic imagery, racist slurs, and harmful social stereotypes . This finding informs our assessment that Imagen is not suitable for public use at this time and also demonstrates the value of rigorous dataset audits and comprehensive dataset documentation (e.g. ) in informing consequent decisions about the model’s appropriate and safe use. Imagen also relies on text encoders trained on uncurated web-scale data, and thus inherits the social biases and limitations of large language models .

While we leave an in-depth empirical analysis of social and cultural biases encoded by Imagen to future work, our small scale internal assessments reveal several limitations that guide our decision not to release Imagen at this time. First, all generative models, including Imagen, Imagen, may run into danger of dropping modes of the data distribution, which may further compound the social consequence of dataset bias. Second, Imagen exhibits serious limitations when generating images depicting people. Our human evaluations found Imagen obtains significantly higher preference rates when evaluated on images that do not portray people, indicating a degradation in image fidelity. Finally, our preliminary assessment also suggests Imagen encodes several social biases and stereotypes, including an overall bias towards generating images of people with lighter skin tones and a tendency for images portraying different professions to align with Western gender stereotypes. Even when we focus generations away from people, our preliminary analysis indicates Imagen encodes a range of social and cultural biases when generating images of activities, events, and objects.

While there has been extensive work auditing image-to-text and image labeling models for forms of social bias (e.g. ), there has been comparatively less work on social bias evaluation methods for text-to-image models, with the recent exception of . We believe this is a critical avenue for future research and we intend to explore benchmark evaluations for social and cultural bias in future work—for example, exploring whether it is possible to generalize the normalized pointwise mutual information metric to the measurement of biases in image generation models. There is also a great need to develop a conceptual vocabulary around potential harms of text-to-image models that could guide the development of evaluation metrics and inform responsible model release. We aim to address these challenges in future work.

We give thanks to Ben Poole for reviewing our manuscript, early discussions, and providing many helpful comments and suggestions throughout the project. Special thanks to Kathy Meier-Hellstern, Austin Tarango, and Sarah Laszlo for helping us incorporate important responsible AI practices around this project. We appreciate valuable feedback and support from Elizabeth Adkison, Zoubin Ghahramani, Jeff Dean, Yonghui Wu, and Eli Collins. We are grateful to Tom Small for designing the Imagen watermark. We thank Jason Baldridge, Han Zhang, and Kevin Murphy for initial discussions and feedback. We acknowledge hard work and support from Fred Alcober, Hibaq Ali, Marian Croak, Aaron Donsbach, Tulsee Doshi, Toju Duke, Douglas Eck, Jason Freidenfelds, Brian Gabriel, Molly FitzMorris, David Ha, Philip Parham, Laura Pearce, Evan Rapoport, Lauren Skelly, Johnny Soraker, Negar Rostamzadeh, Vijay Vasudevan, Tris Warkentin, Jeremy Weinstein, and Hugh Williams for giving us advice along the project and assisting us with the publication process. We thank Victor Gomes and Erica Moreira for their consistent and critical help with TPU resource allocation. We also give thanks to Shekoofeh Azizi, Harris Chan, Chris A. Lee, and Nick Ma for volunteering a considerable amount of their time for testing out DrawBench. We thank Aditya Ramesh, Prafulla Dhariwal, and Alex Nichol for allowing us to use DALL-E 2 samples and providing us with GLIDE samples. We are thankful to Matthew Johnson and Roy Frostig for starting the JAX project and to the whole JAX team for building such a fantastic system for high-performance machine learning research. Special thanks to Durk Kingma, Jascha Sohl-Dickstein, Lucas Theis and the Toronto Brain team for helpful discussions and spending time Imagening!

Appendix A Background

Diffusion models are latent variable models with latents z={zt ∣ t∈}\mathbf{z}=\{\mathbf{z}_{t}\,|\,t\in\} that obey a forward process q(z∣x)q(\mathbf{z}|\mathbf{x}) starting at data x∼p(x)\mathbf{x}\sim p(\mathbf{x}). This forward process is a Gaussian process that satisfies the Markovian structure:

where 0≤s<t≤10\leq s<t\leq 1, σt∣s2=(1−eλt−λs)σt2\sigma^{2}_{t|s}=(1-e^{\lambda_{t}-\lambda_{s}})\sigma_{t}^{2}, and αt,σt\alpha_{t},\sigma_{t} specify a differentiable noise schedule whose log signal-to-noise-ratio, i.e., λt=log⁡[αt2/σt2]\lambda_{t}=\log[\alpha_{t}^{2}/\sigma_{t}^{2}], decreases with tt until q(z1)≈N(0,I)q(\mathbf{z}_{1})\approx\mathcal{N}(\mathbf{0},\mathbf{I}). For generation, the diffusion model is learned to reverse this forward process.

Learning to reverse the forward process can be reduced to learning to denoise zt∼q(zt∣x)\mathbf{z}_{t}\sim q(\mathbf{z}_{t}|\mathbf{x}) into an estimate x^θ(zt,λt,c)≈x\hat{\mathbf{x}}_{\theta}(\mathbf{z}_{t},\lambda_{t},\mathbf{c})\approx\mathbf{x} for all tt, where c\mathbf{c} is an optional conditioning signal (such as text embeddings or a low resolution image) drawn from the dataset jointly with x\mathbf{x}. This is accomplished training x^θ\hat{\mathbf{x}}_{\theta} using a weighted squared error loss

where t∼U()t\sim\mathcal{U}(), ϵ∼N(0,I){\boldsymbol{\epsilon}}\sim\mathcal{N}(\mathbf{0},\mathbf{I}), and zt=αtx+σtϵ\mathbf{z}_{t}=\alpha_{t}\mathbf{x}+\sigma_{t}{\boldsymbol{\epsilon}}. This reduction of generation to denoising is justified as optimizing a weighted variational lower bound on the data log likelihood under the diffusion model, or as a form of denoising score matching . We use the ϵ{\boldsymbol{\epsilon}}-prediction parameterization, defined as x^θ(zt,λt,c)=(zt−σtϵθ(zt,λt,c))/αt\hat{\mathbf{x}}_{\theta}(\mathbf{z}_{t},\lambda_{t},\mathbf{c})=(\mathbf{z}_{t}-\sigma_{t}{\boldsymbol{\epsilon}}_{\theta}(\mathbf{z}_{t},\lambda_{t},\mathbf{c}))/\alpha_{t}, and we impose a squared error loss on ϵθ{\boldsymbol{\epsilon}}_{\theta} in ϵ{\boldsymbol{\epsilon}} space with tt sampled according to a cosine schedule . This corresponds to a particular weighting w(λt)w(\lambda_{t}) and leads to a scaled score estimate ϵθ(zt,λt,c)≈−σt∇ztlog⁡p(zt∣c){\boldsymbol{\epsilon}}_{\theta}(\mathbf{z}_{t},\lambda_{t},\mathbf{c})\approx-\sigma_{t}\nabla_{\mathbf{z}_{t}}\log p(\mathbf{z}_{t}|\mathbf{c}), where p(zt∣c)p(\mathbf{z}_{t}|\mathbf{c}) is the true density of zt\mathbf{z}_{t} given c\mathbf{c} under the forward process starting at x∼p(x)\mathbf{x}\sim p(\mathbf{x}) . Related model designs include the work of .

To sample from the diffusion model, we start at z1∼N(0,I)\mathbf{z}_{1}\sim\mathcal{N}(\mathbf{0},\mathbf{I}) and use the discrete time ancestral sampler and DDIM for certain models. DDIM follows the deterministic update rule

where ϵ∼N(0,I){\boldsymbol{\epsilon}}\sim\mathcal{N}(\mathbf{0},\mathbf{I}), and γ\gamma controls the stochasticity of the sampler .

Appendix B Architecture Details

We introduce a new architectural variant, which we term Efficient U-Net, for our super-resolution models. We find our Efficient U-Net to be simpler, converges faster, and is more memory efficient compared to some prior implementations , especially for high resolutions. We make several key modifications to the U-Net architecture, such as shifting of model parameters from high resolution blocks to low resolution, scaling the skip connections by \nicefrac12\nicefrac{{1}}{{\sqrt{2}}} similar to and reversing the order of downsampling/upsampling operations in order to improve the speed of the forward pass. Efficient U-Net makes several key modifications to the typical U-Net model used in :

We shift the model parameters from the high resolution blocks to the low resolution blocks, via adding more residual blocks for the lower resolutions. Since lower resolution blocks typically have many more channels, this allows us to increase the model capacity through more model parameters, without egregious memory and computation costs.

When using large number of residual blocks at lower-resolution (e.g. we use 8 residual blocks at lower-resolutions compared to typical 2-3 residual blocks used in standard U-Net architectures ) we find that scaling the skip connections by \nicefrac12\nicefrac{{1}}{{\sqrt{2}}} similar to significantly improves convergence speed.

In a typical U-Net’s downsampling block, the downsampling operation happens after the convolutions, and in an upsampling block, the upsampling operation happens prior the convolution. We reverse this order for both downsampling and upsampling blocks in order to significantly improve the speed of the forward pass of the U-Net, and find no performance degradation.

With these key simple modifications, Efficient U-Net is simpler, converges faster, and is more memory efficient compared to some prior U-Net implementations. Fig. A.30 shows the full architecture of Efficient U-Net, while Figures A.28 and A.29 show detailed description of the Downsampling and Upsampling blocks of Efficient U-Net respectively. See Section D.3.2 for results.

Appendix C DrawBench

In this section, we describe our new benchmark for fine-grained analysis of text-to-image models, namely, DrawBench. DrawBench consists of 11 categories with approximately 200 text prompts. This is large enough to test the model well, while small enough to easily perform trials with human raters. Table A.1 enumerates these categories along with description and few examples. We release the full set of samples here.

For evaluation on this benchmark, we conduct an independent human evaluation run for each category. For each prompt, the rater is shown two sets of images - one from Model A, and second from Model B. Each set contains 8 random (non-cherry picked) generations from the corresponding model. The rater is asked two questions -

Which set of images is of higher quality?

Which set of images better represents the text caption : {Text Caption}?

where the questions are designed to measure: 1) image fidelity, and 2) image-text alignment. For each question, the rater is asked to select from three choices:

We aggregate scores from 25 raters for each category (totalling to 25×11=27525\times 11=275 raters). We do not perform any post filtering of the data to identify unreliable raters, both for expedience and because the task was straightforward to explain and execute.

Appendix D Imagen Detailed Abalations and Analysis

In this section, we perform ablations and provide a detailed analysis of Imagen.

We explore several families of pre-trained text encoders: BERT , T5 , and CLIP . There are several key differences between these encoders. BERT is trained on a smaller text-only corpus (approximately 20 GB, Wikipedia and BooksCorpus ) with a masking objective, and has relatively small model variants (upto 340M parameters). T5 is trained on a much larger C4 text-only corpus (approximately 800 GB) with a denoising objective, and has larger model variants (up to 11B parameters). The CLIP modelhttps://github.com/openai/CLIP/blob/main/model-card.md is trained on an image-text corpus with an image-text contrastive objective. For T5 we use the encoder part for the contextual embeddings. For CLIP, we use the penultimate layer of the text encoder to get contextual embeddings. Note that we freeze the weights of these text encoders (i.e., we use off the shelf text encoders, without any fine-tuning on the text-to-image generation task). We explore a variety of model sizes for these text encoders.

We train a 64×6464\times 64, 300M parameter diffusion model, conditioned on the text embeddings generated from BERT (base, and large), T5 (small, base, large, XL, and XXL), and CLIP (ViT-L/14). We observe that scaling the size of the language model text encoders generally results in better image-text alignment as captured by the CLIP score as a function of number of training steps (see Fig. A.6). One can see that the best CLIP scores are obtained with the T5-XXL text encoder.

Since guidance weights are used to control image quality and text alignment, we also report ablation results using curves that show the trade-off between CLIP and FID scores as a function of the guidance weights (see Fig. 5(a)). We observe that larger variants of T5 encoder results in both better image-text alignment, and image fidelity. This emphasizes the effectiveness of large frozen text encoders for text-to-image models. Interestingly, we also observe that the T5-XXL encoder is on-par with the CLIP encoder when measured with CLIP and FID-10K on MS-COCO.

T5-XXL vs CLIP on DrawBench: We further compare T5-XXL and CLIP on DrawBench to perform a more comprehensive comparison of the abilities of these two text encoders. In our initial evaluations we observed that the 300M parameter models significantly underperformed on DrawBench. We believe this is primarily because DrawBench prompts are considerably more difficult than MS-COCO prompts.

In order to perform a meaningful comparison, we train 64×\times64 1B parameter diffusion models with T5-XXL and CLIP text encoders for this evaluation. Fig. 5(b) shows the results. We find that raters are considerably more likely to prefer the generations from the model trained with the T5-XXL encoder over the CLIP text encoder, especially for image-text alignment. This indicates that language models are better than text encoders trained on image-text contrastive objectives in encoding complex and compositional text prompts. Fig. A.7 shows the category specific comparison between the two models. We observe that human raters prefer T5-XXL samples over CLIP samples in all 11 categories for image-text alignment demonstrating the effectiveness of large language models as text encoders for text to image generation.

D.2 Classifier-free Guidance and the Alignment-Fidelity Trade-off

We observe that classifier-free guidance is a key contributor to generating samples with strong image-text alignment, this is also consistent with the observations of . There is typically a trade-off between image fidelity and image-text alignment, as we iterate over the guidance weight. While previous work has typically used relatively small guidance weights, Imagen uses relatively large guidance weights for all three diffusion models. We found this to yield a good balance of sample quality and alignment. However, naive use of large guidance weights often produces relatively poor results. To enable the effective use of larger guidance we introduce several innovations, as described below.

Thresholding Techniques: First, we compare various thresholding methods used with classifier-free guidance. Fig. A.8 compares the CLIP vs. FID-10K score pareto frontiers for various thresholding methods of the base text-to-image 64×6464\times 64 model. We observe that our dynamic thresholding technique results in significantly better CLIP scores, and comparable or better FID scores than the static thresholding technique for a wide range of guidance weights. Fig. A.9 shows qualitative samples for thresholding techniques.

Impact of Conditioning Augmentation: Fig. 11(b) shows the impact of training super-resolution models with noise conditioning augmentation. Training with no noise augmentation generally results in worse CLIP and FID scores, suggesting noise conditioning augmentation is critical to attaining best sample quality similar to prior work . Interestingly, the model trained without noise augmentation has much less variations in CLIP and FID scores across different guidance weights compared to the model trained with conditioning augmentation. We hypothesize that this is primarily because strong noise augmented training reduces the low-resolution image conditioning signal considerably, encouraging higher degree of dependence on conditioned text for the model.

D.3 Impact of Model Size

Fig. 13(b) plots the CLIP-FID score trade-off curves for various model sizes of the 64×6464\times 64 text-to-image U-Net model. We train each of the models with a batch size of 2048, and 400K training steps. As we scale from 300M parameters to 2B parameters for the U-Net model, we obtain better trade-off curves with increasing model capacity. Interestingly, scaling the frozen text encoder model size yields more improvement in model quality over scaling the U-Net model size. Scaling with a frozen text encoder is also easier since the text embeddings can be computed and stored offline during training.

We ablate various schemas for conditioning the frozen text embeddings in the base 64×6464\times 64 text-to-image diffusion model. Fig. 13(a) compares the CLIP-FID pareto curves for mean pooling, attention pooling, and cross attention. We find using any pooled embedding configuration (mean or attention pooling) performs noticeably worse compared to attending over the sequence of contextual embeddings in the attention layers. We implement the cross attention by concatenating the text embedding sequence to the key-value pairs of each self-attention layer in the base 64×6464\times 64 and 64×64→256×25664\times 64\rightarrow 256\times 256 models. For our 256×256→1024×1024256\times 256\rightarrow 1024\times 1024 model, since we have no self-attention layers, we simply added explicit cross-attention layers to attend over the text embeddings. We found this to improve both fidelity and image-text alignment with minimal computational costs.

D.3.2 Comparison of U-Net vs Efficient U-Net

We compare the performance of U-Net with our new Efficient U-Net on the task of 64×64→256×25664\times 64\rightarrow 256\times 256 super-resolution task. Fig. A.14 compares the training convergence of the two architectures. We observe that Efficient U-Net converges significantly faster than U-Net, and obtains better performance overall. Our Efficient U-Net is also ×2−3\times 2-3 faster at sampling.

Appendix E Comparison to GLIDE and DALL-E 2

Fig. A.15 shows category wise comparison between Imagen and DALL-E 2 on DrawBench. We observe that human raters clearly prefer Imagen over DALL-E 2 in 7 out of 11 categories for text alignment. For sample fidelity, they prefer Imagen over DALL-E 2 in all 11 categories. Figures A.17, A.18, A.19, A.20 and A.21 show few qualitative comparisons between Imagen and DALL-E 2 samples used for this human evaluation study. Some of the categories where Imagen has a considerably larger preference over DALL-E 2 include Colors, Positional, Text, DALL-E and Descriptions. The authors in identify some of these limitations of DALL-E 2, specifically they observe that DALLE-E 2 is worse than GLIDE in binding attributes to objects such as colors, and producing coherent text from the input prompt (cf. the discussion of limitations in ). To this end, we also perform quantitative and qualitative comparison with GLIDE on DrawBench. See Fig. A.16 for category wise human evaluation comparison between Imagen and GLIDE. See Figures A.22, A.23, A.24, A.25 and A.26 for qualitative comparisons. Imagen outperforms GLIDE on 8 out of 11 categories on image-text alignment, and 10 out of 11 categories on image fidelity. We observe that GLIDE is considerably better than DALL-E 2 in binding attributes to objects corroborating the observation by .

Appendix F Implementation Details

Architecture: We adapt the architecture used in . We use larger embed_dim for scaling up the architecture size. For conditioning on text, we use text cross attention at resolutions $$ as well as attention pooled text embedding.

Optimizer: We use the Adafactor optimizer for training the base model. We use the default optax.adafactor parameters. We use a learning rate of 1e-4 with 10000 linear warmup steps.

Diffusion: We use the cosine noise schedule similar to . We train using continuous time steps t∼U(0,1)t\sim\mathcal{U}(0,1).

# 64 X 64 model. architecture = { "attn_resolutions": , "channel_mult": , "dropout": 0, "embed_dim": 512, "num_res_blocks": 3, "per_head_channels": 64, "res_block_type": "biggan", "text_cross_attn_res": , "feature_pooling_type": "attention", "use_scale_shift_norm": True, } learning_rate = optax.warmup_cosine_decay_schedule( init_value=0.0, peak_value=1e-4, warmup_steps=10000, decay_steps=2500000, end_value=2500000) optimizer = optax.adafactor(lrs=learning_rate, weight_decay=0) diffusion_params = { "continuous_time": True, "schedule": { "name": "cosine", } }

F.2 64×64→256×256→646425625664\times 64\rightarrow 256\times 256

Architecture: Below is the architecture specification for our 64×64→256×25664\times 64\rightarrow 256\times 256 super-resolution model. We use an Efficient U-Net architecture for this model.

Optimizer: We use the standard Adam optimizer with 1e-4 learning rate, and 10000 warmup steps.

Diffusion: We use the same cosine noise schedule as the base 64×6464\times 64 model. We train using continuous time steps t∼U(0,1)t\sim\mathcal{U}(0,1).

architecture = { "dropout": 0.0, "feature_pooling_type": "attention", "use_scale_shift_norm": True, "blocks": [ { "channels": 128, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 2, }, { "channels": 256, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 4, }, { "channels": 512, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 8, }, { "channels": 1024, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 8, "self_attention": True, "text_cross_attention": True, "num_attention_heads": 8 } ] } learning_rate = optax.warmup_cosine_decay_schedule( init_value=0.0, peak_value=1e-4, warmup_steps=10000, decay_steps=2500000, end_value=2500000) optimizer = optax.adam( lrs=learning_rate, b1=0.9, b2=0.999, eps=1e-8, weight_decay=0) diffusion_params = { "continuous_time": True, "schedule": { "name": "cosine", } }

F.3 256×256→1024×1024→25625610241024256\times 256\rightarrow 1024\times 1024

Architecture: Below is the architecture specification for our 256×256→1024×1024256\times 256\rightarrow 1024\times 1024 super-resolution model. We use the same configuration as the 64×64→256×25664\times 64\rightarrow 256\times 256 super-resolution model, except we do not use self-attention layers but rather have cross-attention layers (to the text embeddings).

Optimizer: We use the standard Adam optimizer with 1e-4 learning rate, and 10000 linear warmup steps.

Diffusion: We use the 1000 step linear noise schedule with start and end set to 1e-4 and 0.02 respectively. We train using continuous time steps t∼U(0,1)t\sim\mathcal{U}(0,1).

"dropout": 0.0, "feature_pooling_type": "attention", "use_scale_shift_norm": true, "blocks"=[ { "channels": 128, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 2, }, { "channels": 256, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 4, }, { "channels": 512, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 8, }, { "channels": 1024, "strides": (2, 2), "kernel_size": (3, 3), "num_res_blocks": 8, "text_cross_attention": True, "num_attention_heads": 8 } ]