# High-Resolution Image Synthesis with Latent Diffusion Models

Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer · arXiv · 2021-12-20

- **Problem** Pixel-space diffusion models need hundreds of GPU days to train and many sequential network passes to sample, so their cost grows with image resolution.
- **Method** Trains diffusion models in the latent space of a pretrained perceptual autoencoder and adds cross-attention conditioning to the UNet backbone.
- **Results** Reached FID 5.11 on CelebA-HQ at 256×256 with LDM-4 and 500-s sampling, and FID 3.60 for LDM-4-G with classifier-free guidance at s = 1.5 on class-conditional ImageNet.

## Why pixel-space diffusion is expensive

Diffusion models (DMs) produce strong image synthesis, but training and sampling them directly in pixel space is expensive. The work cited as \[15\] needed between 150 - 1000 V100 days of training, and about 5 days on a single A100 to produce 50k samples. Sampling is also slow because the same network runs sequentially for many steps, 25 - 1000 steps in \[15\].

Training at this scale is open only to a small part of the field and carries a large carbon footprint. Each gradient and each evaluation in pixel space touches every pixel of a high-dimensional RGB image, so the cost follows the image resolution. The goal is therefore to lower the compute for both training and sampling without losing sample quality.

## Separating compression from generative learning

Looking at a trained pixel-space model, the authors see learning fall into two stages. The first is perceptual compression, which removes high-frequency detail while learning little semantic variation; the second is semantic compression, where the generative model learns the composition of the data. The plan follows from this split: find a space that is perceptually equivalent to the image space but cheaper to model, and train the diffusion model there.

Training therefore has two phases: an autoencoder first yields a lower-dimensional latent space that is perceptually equivalent to the data, and then the diffusion model is trained on that latent space. Because the diffusion model runs on the latent space, the autoencoder does not need heavy spatial downsampling, since the latent space scales better with spatial dimensionality.

The autoencoder is trained once and can be reused for several diffusion trainings and for other tasks. Once the diffusion model is trained, a sample is generated in latent space and then decoded to an image in a single network pass.

## The perceptual compression autoencoder

The autoencoder follows earlier work and combines a perceptual loss with a patch-based adversarial objective. The adversarial term keeps reconstructions on the image manifold, because pixel-only L2 or L1 objectives produce blur. For an RGB image x, the encoder gives a latent z and the decoder maps it back, as in \\\[ z = E(x), \\qquad \\tilde{x} = D(z) = D(E(x)), \\qquad z \\in \\mathbb{R}^{h \\times w \\times c}.

\\\] The downsampling factor is \\( f = H/h = W/w \\), and the authors study factors \\( f = 2^m \\) with m in N.

Two regularizers keep the latent from becoming arbitrarily high-variance. KL-reg. adds a slight KL penalty that pulls the learned latent toward a standard normal, similar to a VAE, while VQ-reg. places a vector quantization layer inside the decoder. The VQ-reg. variant can be read as a VQGAN in which the quantization layer is absorbed by the decoder.

Since the diffusion model works on the two-dimensional latent, moderate compression still gives good reconstructions; earlier work instead flattened the latent into a 1D order for an autoregressive prior.

## Training the diffusion model on latents

Diffusion models are trained as a sequence of denoising autoencoders, each predicting a denoised version of its noisy input. The simplified objective is the expected squared error between the Gaussian noise and the network's noise prediction, with t drawn uniformly from {1,...,T}: \\\[ \\mathbb{E}\_{x,\\epsilon\\sim\\mathcal{N}(0,1),t}\\left\[\\lVert \\epsilon-\\epsilon\_\\theta(x\_t,t)\\rVert\_2^2\\right\].

\\\] In latent space the same objective uses z = E(x) in place of x, with the reweighted bound written as \\\[ \\mathbb{E}\_{\\mathcal{E}(x),\\epsilon\\sim\\mathcal{N}(0,1),t}\\left\[\\lVert \\epsilon-\\epsilon\_\\theta(z\_t,t)\\rVert\_2^2\\right\]. \\\]

The backbone epsilon\_theta is a time-conditional UNet built mainly from 2D convolutional layers, so the objective focuses on the perceptually relevant parts of the data. Since the forward process is fixed, z\_t can be obtained from the encoder during training, and no further encoding is needed in the denoising loss.

## Cross-attention conditioning

Diffusion models can in principle model conditional distributions p(z\|y), so the denoiser can take an input y that steers synthesis. Concatenation is one route, feeding spatially aligned conditioning into the UNet input, and it is used for semantic synthesis and super-resolution. Cross-attention is the more general route, and Figure 3 contrasts the two.

A domain-specific encoder tau\_theta maps the conditioning input y, such as a language prompt, to an intermediate representation tau\_theta(y) in R^{M x d\_tau}. The UNet's intermediate features act as queries, while the encoded condition supplies keys and values, through learned projections. The layer computes \\\[ \\mathrm{Attention}(Q,K,V)=\\mathrm{softmax}\\left(\\frac{QK^{T}}{\\sqrt{d}}\\right)\\cdot V, \\qquad Q=W\_Q^{(i)}\\,\\phi\_i(z\_t),\\quad K=W\_K^{(i)}\\,\\tau\_\\theta(y),\\quad V=W\_V^{(i)}\\,\\tau\_\\theta(y).

\\\] Here phi\_i(z\_t) is a flattened intermediate representation of the UNet, and the W matrices are learnable projections.

The conditional objective is \\\[ \\mathbb{E}\_{\\mathcal{E}(x),y,\\epsilon\\sim\\mathcal{N}(0,1),t}\\left\[\\lVert \\epsilon-\\epsilon\_\\theta(z\_t,t,\\tau\_\\theta(y))\\rVert\_2^2\\right\], \\\] and tau\_theta and epsilon\_theta are optimized jointly under it. The encoder can be domain-specific, for example a transformer when y is a text prompt. Each conditional model is trained for one conditioning type, since the authors train class-conditional, text-to-image and layout-to-image models.

## Choosing the downsampling factor

The authors compare LDM-f for f in {1, 2, 4, 8, 16, 32}, where LDM-1 is the pixel-based diffusion model. All models use a single NVIDIA A100, the same number of steps and the same number of parameters, so the factor is the only change.

Small factors such as LDM-1 and LDM-2 train slowly, while very large factors stagnate early, with LDM-32 limiting overall sample quality.

The authors attribute the slow progress of small factors to leaving most of the perceptual compression to the diffusion model, and the plateau of large factors to information loss in the first stage. LDM-4 to LDM-16 balance efficiency against faithful results, and the FID gap between pixel-based LDM-1 and LDM-8 is 38 after 2M training steps.

Figure 7 plots FID against the number of DDIM steps, from 10 to 200, on CelebA-HQ and ImageNet. Models with LDM-4 and LDM-8 give the lowest FID at each sampling budget, and FID is computed on 5000 samples after 500k steps on CelebA-HQ or 2M steps on ImageNet. The authors conclude that ImageNet needs reduced compression to avoid losing quality, and that LDM-4 and -8 offer the best conditions for high-quality synthesis.

## Unconditional generation results

Figure 4 shows samples from the LDMs on CelebA-HQ, FFHQ, LSUN-Churches, LSUN-Bedrooms and ImageNet.

On CelebA-HQ, LDM-4 with 500-s sampling reached FID 5.11, against 7.22 for LSGM and 7.16 for UDM in the same table. The authors describe this as a new state of the art on CelebA-HQ, and they note that LSGM trains its latent model jointly with the first stage, whereas the LDM is trained in a fixed space.

On LSUN-Bedrooms, LDM-4 with 200 steps reached FID 2.95, against 1.90 for ADM. This is the one dataset where the authors do not outperform prior diffusion approaches; they note that their score is close to ADM despite using half its parameters and requiring 4-times less training resources.

## Class-conditional ImageNet synthesis

Table 3 compares LDM-4 and LDM-4-G with ADM and ADM-G, and with BigGAN-deep, on ImageNet.

The authors report these numbers as outperforming the ADM diffusion model while reducing computational requirements and parameter count.

## Text-to-image and layout conditioning

LDM-KL-8 has 1.45B parameters, uses a transformer text encoder with a BERT tokenizer, and is trained on LAION-400M. Figure 5 shows samples from it for user-defined prompts, generated with 200 DDIM steps and eta = 1.0, with unconditional guidance at s = 10.0.

The authors describe the guided model as on par with recent autoregressive and diffusion models for text-to-image synthesis while using far fewer parameters. The same cross-attention route is also used for layout-to-image synthesis, trained on OpenImages and fine-tuned on COCO.

## Super-resolution with concatenated conditioning

The setup follows SR3 with bicubic ×4 downsampling on ImageNet, and LDM-SR uses the f = 4 VQ-reg. autoencoder pretrained on OpenImages. The low-resolution input is concatenated with the UNet input, so the conditioning encoder tau\_theta is the identity.

Table 5 reports LDM-4 with 100 steps at FID 2.8, IS 166.3, PSNR 24.4 and SSIM 0.69, against SR3 at FID 5.2, IS 180.1, PSNR 26.4 and SSIM 0.762. The FID for LDM-4 uses features from the validation split, and the authors note that LDM-SR outperforms SR3 in FID while SR3 has the better IS.

Plain image regression reaches the highest PSNR and SSIM, and the authors argue that these metrics favor blurriness and do not align well with human perception. In a user study, subjects preferred LDM-4 over the pixel baseline in 70.6% of comparisons against 29.4% for the pixel baseline, and the authors use this as their main perceptual check.

## Inpainting efficiency and comparison with LaMa

The efficiency study compares LDM-1 with LDM-4 under KL and VQ regularization, with and without attention, at a fixed parameter count. Table 6 shows training throughput, sampling throughput, hours per epoch and FID after six epochs. LDM-4 (KL, w/ attn) took 7.66 hours per epoch against 20.66 for LDM-1, and its FID after six epochs was 15.21 against 24.74 for LDM-1.

On all samples, LDM-4 (big, w/ ft) reached FID 1.50 and LPIPS 0.137, against 2.21 and 0.14 for LaMa. On the 40-50% masked subset, the same model reached FID 9.39 against 12.0 for LaMa, and Table 7 lists the comparison on 30k crops of size 512×512 from Places test images.

The authors note that LPIPS between unmasked images and their samples is slightly higher than for LaMa, which they attribute to LaMa producing a single result that tends toward an average image.

## Limitations

The authors assume their super-resolution models are already somewhat limited in this respect.

## Paper info

- **Authors**: Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer
- **Venue**: arXiv · Preprint
- **First published**: 2021-12-20
- **Added**: 2026-10-20
- **Updated**: 2022-4-13
- **Version**: v2
- **arXiv**: 2112.10752
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

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

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

Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer (2021). High-Resolution Image Synthesis with Latent Diffusion Models. arXiv:2112.10752v2. https://arxiv.org/abs/2112.10752v2

**BibTeX**

```
@misc{rombach2021high,
  title = {{High-Resolution Image Synthesis with Latent Diffusion Models}},
  author = {Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer},
  year = {2021},
  eprint = {2112.10752},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.10752v2}
}
```

## Other paper commentary

- [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)
- [Adversarial Vulnerability from Interference Between Features in Superposition](https://refivu.com/en/papers/cd94add6-68c0-4643-bc21-5a8a999fe6db-adversarial-vulnerability-from-interference-between-features.md)
- [Scalable Beckmann Maps Improve One-step Generation](https://refivu.com/en/papers/ba5444d1-474d-40f0-8026-1a34654b061f-scalable-beckmann-maps-improve-one-step-generation.md)
- [Single-Transformer Latent Diffusion](https://refivu.com/en/papers/59e9ca2d-5bae-4c22-8f79-65dd9e241471-single-transformer-latent-diffusion.md)
- [Scaling Laws for Neural Language Models](https://refivu.com/en/papers/0b00379f-9c4e-4d81-be48-4963190a673b-scaling-laws-for-neural-language-models.md)
- [Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer](https://refivu.com/en/papers/d6599844-fea7-4829-8f9f-c8bdc6543855-exploring-the-limits-of-transfer-learning-with-a.md)
- [Language Models are Few-Shot Learners](https://refivu.com/en/papers/82602214-e941-40a1-bc42-5b92c1268a53-language-models-are-few-shot-learners.md)
- [Trust Region Policy Optimization](https://refivu.com/en/papers/30e842a2-bb44-47ff-9ad7-d25925260b2c-trust-region-policy-optimization.md)
- [Learning Transferable Visual Models From Natural Language Supervision](https://refivu.com/en/papers/c2ad57ff-fd96-4ad1-af27-4195a16c557d-learning-transferable-visual-models-from-natural-language.md)
- [Efficient Estimation of Word Representations in Vector Space](https://refivu.com/en/papers/d295cb4b-dace-4ef1-9199-b860d9b1f123-efficient-estimation-of-word-representations-in-vector-space.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [PSNR](https://refivu.com/en/terms/fcbb9b8276a7-psnr)
- [FID](https://refivu.com/en/terms/e110afe65f86-fid)
- [diffusion models](https://refivu.com/en/terms/39b044617fcd-diffusion-models)
- [MS-COCO](https://refivu.com/en/terms/3c7d75a4a2eb-ms-coco)
- [UNet](https://refivu.com/en/terms/0da000173b9b-unet)
- [LAMA](https://refivu.com/en/terms/acf6ed8e0c14-lama)
- [Super-resolution](https://refivu.com/en/terms/6dc5e5f4e268-super-resolution)
- [Inpainting](https://refivu.com/en/terms/dc2386251bc9-inpainting)
- [LAION-400M](https://refivu.com/en/terms/a3bc64a57785-laion-400m)
- [Latent Diffusion Models](https://refivu.com/en/terms/5d65023babcd-latent-diffusion-models)
- [SR3](https://refivu.com/en/terms/88be23f19536-sr3)
- [DDIM sampler](https://refivu.com/en/terms/cc966719de70-ddim-sampler)
- [PLACES](https://refivu.com/en/terms/f1989482056f-places)
- [ADM](https://refivu.com/en/terms/608fe8241379-adm)
- [cross-attention mechanism](https://refivu.com/en/terms/958dddc88dce-cross-attention-mechanism)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/33bd1500-c829-47e5-9545-ad078523241e-high-resolution-image-synthesis-with-latent-diffusion-models)
