High-Resolution Image Synthesis with Latent Diffusion Models (Stable Diffusion)

Latent Diffusion banner Kaggle

Summary

Diffusion models make an image by starting from pure noise and removing a little noise at a time. They give excellent pictures, but they work on every pixel at every step, so they are slow and expensive. Training the strongest ones took 150 to 1,000 V100 GPU-days, and making 50,000 samples took about 5 days on one A100 GPU (Section 1).

Latent Diffusion Models (LDMs) split the job into two parts. First an autoencoder learns to squeeze an image into a much smaller “latent” picture and to turn it back into the image. Then the diffusion model learns to make these small latent pictures instead of full images. At the end, the autoencoder’s decoder turns the latent into a full image in one pass (Sections 3.1 and 3.2).

The paper also adds cross-attention layers to the diffusion U-Net, so the model can follow text, class labels or layouts (Section 3.3). This design became the basis of Stable Diffusion.

What Problem Does It Solve

Think of drawing a large mural. Painting every brick of the wall from the start is slow. It is faster to first draw a small sketch with the main shapes and then let a skilled helper turn the sketch into the full mural.

A normal diffusion model paints the whole wall at every step, including tiny details that people hardly notice. An LDM lets the diffusion model work only on the small sketch (the latent), where the important shapes are, and leaves the fine details to the autoencoder’s decoder. This makes training and sampling much cheaper, so strong image generators can be trained with far less computing power.

Core Idea

  • Two kinds of compression: the paper notes that a model first learns to drop fine details nobody notices (perceptual compression), and only then learns what the image means (semantic compression). LDMs give the first job to an autoencoder and the second to the diffusion model (Section 1, Figure 2).
  • Autoencoder: the encoder turns an H×W×3 image into an h×w×c latent that is f times smaller in height and width, with f = 2, 4, 8, 16 or 32. It is trained with a perceptual loss and a patch-based adversarial loss, and a light KL penalty or a vector-quantisation layer keeps the latent well behaved (Section 3.1).
  • Diffusion on the latent: a time-conditional U-Net learns to predict the noise added to the latent, with the same simple loss as normal diffusion models (Section 3.2, Eq. 2).
  • Mild compression is enough: because the U-Net keeps the 2D structure of the latent, f = 4 already gives a large saving and still keeps detail. The f = 4 autoencoder reconstructs images with PSNR 27.4 and reconstruction FID 0.58 (Figure 1, Table 8).
  • Cross-attention for conditioning: a separate encoder turns the condition (for example a text prompt) into a sequence of vectors, and cross-attention layers inside the U-Net look at it (Section 3.3).

Key Method Details

  • Choosing f: with the same compute, f = 1 and 2 train slowly and f = 32 stops improving early. f = 4 to 16 strike a good balance, with an FID gap of 38 between pixel diffusion (f = 1) and f = 8 after 2M training steps, and f = 4 and 8 give the best results overall (Section 4.1).
  • Fewer positions: f = 4 means 16× fewer positions and f = 8 means 64× fewer, so the U-Net works on a far smaller grid.
  • Train the autoencoder once: the autoencoder is trained first and then frozen, and the same one can be reused for many diffusion models and tasks (Section 1).
  • Latent scale: for the KL-regularised latent, the paper rescales the latent by its component-wise standard deviation so it has unit standard deviation; this changes the signal-to-noise ratio and matters for large images (Section 4.3.2, Appendix D.1).
  • Results: a new best FID of 5.11 on CelebA-HQ (Section 4.2); FID 3.60 on class-conditional ImageNet with classifier-free guidance (Table 3); for inpainting, at least a 2.7× speed-up over pixel diffusion with FID at least 1.6× better (Section 4.5).
  • Text to image: a 1.45B-parameter KL-regularised LDM trained on LAION-400M, with a BERT tokenizer and a transformer as the text encoder (Section 4.3.1).
  • Limitations: sampling is still slower than GANs, and the autoencoder can limit tasks that need exact pixel accuracy (Section 5).

Simplifications in This Notebook

  • Tiny images: 8,000 grayscale 32×32 FashionMNIST images, instead of 256×256 colour images and larger.
  • Simple autoencoder: a small VAE (335,241 parameters) trained only with mean-squared error and a light KL penalty, without the paper’s perceptual and adversarial losses. It turns a 32×32×1 image into an 8×8×4 latent (f = 4).
  • No latent rescaling and no conditioning: the latent is not rescaled by its standard deviation, both models use the same plain linear noise schedule, and there is no cross-attention or text.
  • Very short training: 5 epochs for each model, T = 200 steps, DDPM sampling, and no FID; sample quality is only judged by eye. After 5 epochs, samples from both models are blurry and mostly not recognisable as clothing; the latent-model samples (top row) look worse, mostly broken-up blobs, while the pixel-model samples are mostly grey square shapes.

What the Notebook Result Shows

  • Smaller input: the latent has 16× fewer positions than the image (64 vs 1,024) but only 4× fewer values (256 vs 1,024).
  • Faster training: with the same U-Net size (2,353,348 vs 2,351,617 parameters), 5 epochs of latent diffusion took 12.5 s against 49.8 s for pixel diffusion, 4.00× faster. Adding the VAE’s 13.0 s of training, it was still 1.95× faster (25.5 s vs 49.8 s). Times change a little from run to run.
  • No faster sampling: making 16 samples took 2.08 s for the latent model and 2.03 s for the pixel model (ratio 0.98×). A likely reason, not tested, is that 16 tiny images are too little work to keep the GPU busy.
  • Losses are not comparable: the final latent loss (0.3976) is higher than the pixel loss (0.0912), but they are measured on different data. The VAE’s reconstruction error fell from 0.0916 to 0.0098.

Influence

OpenAlex lists about 38,800 citations (38,783 when checked on 3 December 2026). The paper’s code and models are in CompVis/latent-diffusion. Stable Diffusion v1 is a latent diffusion model that uses a frozen CLIP ViT-L/14 text encoder instead of the paper’s BERT-based one (CompVis/stable-diffusion). Stability AI says the CompVis group at LMU Munich led the original Stable Diffusion V1 release, building on their Latent Diffusion work, and that Stable Diffusion 2.0 switched to a new OpenCLIP text encoder (Stable Diffusion 2.0 Release). So Stable Diffusion 1.x and 2.x both follow this paper’s design.


Resources

File Description
README.md This overview — a 5-minute read covering the paper’s summary, core idea, key method details, influence, and a plain-English explanation of the problem it solves
solution.ipynb From-scratch PyTorch implementation of a tiny latent diffusion model (VAE + U-Net) on FashionMNIST, compared with the same U-Net trained directly on pixels
CODE_ARCHITECTURE.md Section-by-section breakdown of the notebook — what each cell does, data flow, tensor shapes, and key design decisions
TALK.md Press coverage, Q&A (answers from the paper), citations, and common misconceptions about the paper

Table of contents