Latent Diffusion: Denoise Where the Information Is
Published:
Where the compute goes
A diffusion model on raw pixels has to learn everything at once: which objects exist, how they are arranged, and also the exact grain of a wall’s plaster. Rate–distortion analysis of natural images says the last of these dominates the bit budget while carrying very little perceptual weight. Rombach et al. call the two regimes semantic compression and perceptual compression, and the point of latent diffusion is that only the first needs a generative model with a thousand sequential forward passes. The second is a job for a single-pass autoencoder.
Squeezing this out matters because the cost is not linear in the pixel count. The U-Net’s attention blocks are quadratic in the number of spatial tokens, so halving each side cuts attention cost sixteenfold, and the cost is paid again at every one of the sampling steps.
Stage one: the autoencoder
Train an encoder \(\mathcal{E}\) and decoder \(\mathcal{D}\) on images so that \(\mathcal{D}(\mathcal{E}(\mathbf{x})) \approx \mathbf{x}\), with a downsampling factor \(f\): an \(H\times W\times 3\) image maps to \(\tfrac{H}{f}\times\tfrac{W}{f}\times c\). The reconstruction objective is not plain L2 — that produces blur — but a combination of a perceptual (LPIPS) loss and a patch discriminator, which is what keeps texture crisp at high compression.
The latent also needs a regulariser, or its scale drifts and the diffusion model’s noise schedule stops making sense. Two choices are used: a very weak KL penalty towards a standard Gaussian (the “KL-f8” autoencoder in Stable Diffusion) or a vector-quantisation layer. In practice the KL variant is also rescaled by a fixed constant so the latents have roughly unit variance before diffusion sees them.
| Pixel space | Latent space, \(f = 8\) | |
|---|---|---|
| Tensor shape | \(512\times512\times3\) | \(64\times64\times4\) |
| Dimensions | 786,432 | 16,384 |
| Ratio | — | 48× fewer |
| Spatial tokens for attention | 262,144 | 4,096 |
| Cost of one full self-attention | — | 4096× cheaper (\(64^2\)) |
Rombach et al. swept \(f\) and found the useful window to be roughly 4 to 8. Below that, too little is compressed and diffusion still wastes capacity on texture; above it, the autoencoder starts discarding structure the diffusion model would have needed, and sample quality falls no matter how long you train.
Stage two: diffusion on latents
Nothing about the diffusion maths changes. Freeze the autoencoder, encode the dataset once, and run the ordinary training objective with \(\mathbf{z}_0 = \mathcal{E}(\mathbf{x})\) in place of the image:
with \(y\) the conditioning input (a caption, a layout, a class) and \(\tau_\theta\) a domain-specific encoder — for text, a frozen CLIP or T5 text encoder. Sampling runs the reverse chain in latent space and decodes once at the end: one call to \(\mathcal{D}\) per image, not per step.
Cross-attention as the conditioning interface
The mechanism that makes one architecture serve text, layouts and segmentation maps is cross-attention inserted into the U-Net’s intermediate blocks. Flatten the spatial feature map \(\varphi_i(\mathbf{z}_t)\) into tokens and attend from those to the conditioning tokens:
Queries come from the image, keys and values from the condition. Changing modality means changing only \(\tau_\theta\); the U-Net is untouched. This is also why per-token attention maps are inspectable, and why so much downstream editing work — attention re-weighting, prompt-to-prompt edits, region control — hooks into exactly this layer.
What the autoencoder costs you
The reconstruction is a ceiling. Whatever \(\mathcal{D}(\mathcal{E}(\mathbf{x}))\) loses is unreachable by any amount of sampling, because the diffusion model has never seen it. At \(f = 8\) this shows up in the well-known failure modes: small faces, fine lettering, regular high-frequency patterns that pick up moiré or smearing. Encode a photograph of printed text and decode it, with no diffusion involved at all, and you will see the limit directly.
There are second-order costs too. Errors in latent space do not map uniformly to pixel error, so the L2 loss on \(\mathbf{z}\) implies a strange, decoder-dependent metric on images. Compounding is real: autoencoder artefacts and diffusion artefacts interact rather than adding. And the frozen decoder is a fixed component of every model built on it, so improving it means retraining downstream — which is why later releases ship refreshed VAEs with more latent channels rather than sticking with the original.
The design is what makes the rest practical: with an 8× smaller field to integrate, fast samplers and step distillation push generation into the low-single-digit step range, and classifier-free guidance’s doubled forward pass stops being prohibitive.
References
- Rombach, R., Blattmann, A., Lorenz, D., Esser, P., & Ommer, B. High-Resolution Image Synthesis with Latent Diffusion Models. CVPR 2022.
- Esser, P., Rombach, R., & Ommer, B. Taming Transformers for High-Resolution Image Synthesis. CVPR 2021.
- Zhang, R., Isola, P., Efros, A. A., Shechtman, E., & Wang, O. The Unreasonable Effectiveness of Deep Features as a Perceptual Metric. CVPR 2018.
- Podell, D., English, Z., Lacey, K., et al. SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis. ICLR 2024.
