Latent Diffusion,
explained.
Diffusion models could already paint stunning images — if you owned a data center. Denoising every pixel, hundreds of times, at high resolution, was brutally expensive; the best generators lived behind closed doors. This paper found the shortcut that broke it open: don't denoise pixels at all. Shrink the image to a tiny latent sketch, do the slow work there, then decode. That single move is why image generation ended up on your laptop — and why it's called Stable Diffusion.
What changes against pixel diffusion: the denoising moves into a small space
Rungs 4 to 6 denoise pixels, which means every one of the sampling steps is a full network pass at the image's full resolution. That is the remaining cost, and it is what kept high-resolution diffusion inside organisations with clusters.
The change rests on an observation about where the compute was going. Most of the bits in an image are perceptually irrelevant high-frequency detail — exact texture, sensor noise, the precise placement of individual leaves — and a diffusion model denoising pixels spends the majority of its capacity and its compute modelling them. But that detail is exactly what an autoencoder reconstructs well and cheaply. So: compress the image with an autoencoder into a much smaller latent, run the entire diffusion process there, and decode once at the end. The diffusion model now spends its capacity on semantics — what is in the picture and where — and the decoder handles texture.
Stated in units, that is an order-of-magnitude reduction in the compute of both training and sampling, which is the difference between a model that a lab runs and one that runs on a consumer graphics card. The second contribution is the conditioning mechanism: text is injected by cross-attention into the denoiser, which is general — anything you can encode as a sequence can steer generation the same way, and that is why the same architecture handles text, layouts, depth maps and image prompts without redesign. Note the ladder closing a loop here: rung 1, which lost as a generator, is the component that makes the winner affordable.
The pixel-space cost problem
Diffusion models generate by starting from pure noise and denoising it step by step until an image emerges. It works beautifully — but the earlier models did this directly on pixels. A 512×512 RGB image is nearly 800,000 numbers, and the model has to process all of them at every one of dozens or hundreds of denoising steps.
The cruel part is that most of those pixels carry redundant, high-frequency detail — texture and noise the eye barely registers. The model burns enormous compute perfecting bits that don't matter perceptually. That inefficiency put high-resolution diffusion out of reach for anyone without a fleet of GPUs, keeping the best image generators locked inside big labs.
The big idea: denoise a sketch, not the pixels
The insight is to split the problem into two jobs done by two networks. First, a compressor learns to squeeze an image into a small latent representation that keeps the meaningful structure and throws away the imperceptible detail. Then the diffusion model does all its slow denoising work in that compact latent space — never touching raw pixels until the very end, when a decoder blows the finished latent back up to full resolution.
It's the difference between planning a painting as a rough thumbnail versus fussing over every brushstroke from the start. Get the composition right on the small sketch, cheaply, then render the detail once. The paper calls this a latent diffusion model — diffusion moved off the pixel grid and onto a tiny latent grid.
512×512×3
64×64×4
512×512×3
The VAE: a perceptual compressor
The compressor is a VAE (variational autoencoder), trained once, separately. Its encoder maps a 512×512 image down to roughly a 64×64 latent grid — about an 8× reduction per side, so tens of times fewer numbers to work with. Its decoder does the reverse, reconstructing a full image from a latent.
Crucially, the VAE is trained with perceptual and adversarial losses so it preserves what looks right rather than matching pixels exactly. It discards precisely the imperceptible high-frequency detail that was wasting the diffusion model's time. After training, the VAE is frozen and its latent space becomes the fixed "canvas" the diffusion model paints on.
Stage one (VAE) handles perceptual compression — remove imperceptible detail. Stage two (diffusion) handles semantic generation — arrange meaningful content. Separating them is the whole efficiency trick.
Denoising in the latent space
Inside the latent space, it's ordinary diffusion. During training, a clean latent is progressively corrupted with noise; a U-Net is taught to predict and remove that noise one step at a time. At generation, you start from a random latent — pure noise — and run the U-Net repeatedly to denoise it into a coherent latent, which the VAE decoder then turns into an image.
The U-Net is the workhorse: an encoder-decoder with skip connections that's well suited to grid-shaped data. Because the grid it operates on is now tiny, each denoising step is cheap — the same number of steps as pixel diffusion, but each one a fraction of the cost. That's where the order-of-magnitude speedup comes from.
And "a fraction" is a precise fraction. A downsample factor f shrinks each side, so the number of spatial positions the U-Net processes drops by f² — and the U-Net's attention layers, being quadratic in positions, drop by f⁴:
Same denoising steps, each on a 64×-smaller canvas — the entire efficiency story, in exponents of one number.
Steering it with text: cross-attention
A generator you can't direct is a curiosity. Latent diffusion adds flexible conditioning through cross-attention. A prompt like "an astronaut riding a horse" is turned into embeddings by a text encoder, and at several layers inside the U-Net, the image latents attend to those text embeddings — asking, at every location, "which words should shape what I generate here?"
This is the same attention mechanism from Transformers, now bridging two modalities: image latents as queries, text tokens as keys and values. The general form means the same machinery can condition on text, another image, a segmentation map, or a layout — text-to-image is just the most famous case. It's how a sentence becomes a specific picture rather than a random one.
The results
Latent diffusion matched or beat pixel-space diffusion on image quality benchmarks while using dramatically less compute for both training and generation. The efficiency was the story: high-resolution, text-conditioned image synthesis that a single consumer GPU could run in seconds.
| Approach | Where diffusion runs | Cost at high-res |
|---|---|---|
| Pixel-space diffusion | full image (e.g. 512²×3) | very high |
| Latent diffusion | compressed latent (64²×4) | ~tens of times lower |
Released publicly as Stable Diffusion, this architecture put a capable text-to-image model in millions of hands, sparked an explosion of tools, fine-tunes, and plugins, and turned "type a sentence, get a picture" into an everyday act rather than a research demo.
The limits
The compression is lossy. Because the VAE throws away detail, latent diffusion can fumble the finest textures and — notoriously — small structured things like text in a sign or the exact count of fingers. It's still an iterative sampler, so generation takes many steps unless sped up by later distillation methods.
And it inherits the ethics of its training data: models trained on huge web scrapes can reproduce biases, memorize and regurgitate copyrighted images, and enable convincing fakes. The very openness that made Stable Diffusion powerful also made these harms widely accessible — a tension the field is still working through.
Why it still matters
Latent diffusion is the architecture that democratized generative imagery. By moving the expensive process into a compressed space, it turned a data-center capability into an open-source download — and the resulting ecosystem (Stable Diffusion, ControlNet, LoRA fine-tunes, and countless apps) reshaped art, design, and content overnight.
The pattern generalized far beyond images: "compress with an autoencoder, then generate in the latent space, conditioned by cross-attention" now underpins state-of-the-art video and audio generators too. When a modern model makes a video from a prompt, it is very likely running diffusion in a latent space — the idea this paper made standard.
Pair this with the diffusion models breakdown (the denoising idea itself) and CLIP (the text encoder that guides many text-to-image systems). Together they're the recipe behind modern image generation.
What the authors admit, and what happened next
The autoencoder is a hard ceiling, and this is the honest cost: anything the encoder discards, the diffusion model cannot generate, because it never sees it and the decoder must invent it. That is precisely why models of this family were for years bad at small text inside images and at fine high-frequency structure — the failure is in the compressor, not the generator, and no amount of diffusion capacity fixes it. The compression ratio is the single most consequential design choice in the system.
Training is also two-stage, so the autoencoder is fitted without knowing what the diffusion model will find difficult, and an adversarial term is used in the decoder to keep reconstructions sharp — which quietly means rung 2 is in the pipeline too.
How it held up: this is the architecture of deployed image generation. Its release as open weights is also the single largest reason a public ecosystem of fine-tunes, adapters and tooling exists for image models at all, which is a social consequence of a compute decision. The general lesson transfers past images: run the expensive iterative process in the smallest representation that preserves what you care about, and let a cheap decoder restore the rest.
Price the latent-space speedup
Latent diffusion's whole argument is a downsample factor and its powers. This computes what Stable Diffusion's f = 8 VAE actually buys: how many fewer numbers the diffusion model touches, how many fewer spatial positions the U-Net processes, and — because self-attention is quadratic in positions — how the attention cost drops by f⁴. Watch a 512×512 image collapse to a 64×64 latent, 64× fewer positions, and a 4,096× cheaper attention step. Change the resolution or the factor.
Write the body of latent_budget. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 7 assertions below — they start red.
- An 8x downsample gives 64x fewer spatial positions
- A 512 image at f=8 becomes a 64x64 latent grid
- Per-position (conv) work drops by f squared
- Attention, quadratic in positions, drops by f to the fourth
- The latent tensor is far smaller than the raw image
- Latent_budget collects the grid, the number count and both savings
- Halving the downsample factor quadruples the numbers to diffuse
5 questions on this paper
Answer each one out loud before you open it. Recalling an answer is what makes it stick; recognising one you have just read is not. Your score is kept on this device.
What is latent diffusion?
Show answer
Latent diffusion is a 2022 method (Rombach et al.) that runs the diffusion generation process in a compressed latent space instead of directly on pixels. A VAE first encodes an image into a much smaller latent representation; the diffusion model learns to denoise in that latent space; then the VAE decoder turns the finished latent back into a full-resolution image. It is the technique behind Stable Diffusion.
Why is latent diffusion so much cheaper than pixel diffusion?
Show answer
Pixel-space diffusion denoises every pixel at every step, which is enormously expensive at high resolution. Latent diffusion first compresses the image roughly 8× per side (about 48× fewer values), so all the heavy denoising happens on a tiny grid. That cut costs enough to train and run high-resolution image generation on consumer GPUs.
How does latent diffusion generate images from text?
Show answer
It conditions the denoising U-Net on a text prompt using cross-attention. The prompt is turned into embeddings by a text encoder, and at multiple layers of the U-Net the image latents attend to those text embeddings — so the words steer what gets denoised into the image. This cross-attention conditioning is how a caption becomes a picture.
What role does the VAE play?
Show answer
The VAE (variational autoencoder) is the compressor. Its encoder maps a high-resolution image into a small latent grid that keeps the perceptually important structure while discarding imperceptible detail; its decoder reconstructs a full image from a latent. Diffusion happens entirely between these two — on latents, never on raw pixels.
How is latent diffusion different from DDPM?
Show answer
DDPM and the original diffusion models denoise directly in pixel space, which is accurate but slow and memory-heavy at high resolution. Latent diffusion keeps the same denoising idea but moves it into a compressed latent space, adding a VAE for compression and cross-attention for flexible conditioning — trading a tiny bit of fidelity for a massive efficiency win.
Generating pixels
Ten papers from the first latent-variable generator to video and real-time 3D. The diffusion half is strictly cumulative — each rung removes a cost the last one paid.
- 1VAE2014
- 2GANs2014
- 3VQ-VAE2017
- 4DDPM2020
- 5DDIM2021
- 6Classifier-Free Guidance2021
- 7Latent Diffusion2022
- 8Sora2024
- 9NeRF2020
- 103D Gaussian Splatting2023
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- Word2VecHow words became math. Dense word vectors learned from the company a word keeps, so king − man + woman lands near queen. Skip-gram, CBOW, the distributional hypothesis, and the origin of every embedding model powering search and RAG.Read →
- ResNetThe skip connection that made deep learning deep. Why stacking layers made networks worse, and how residual learning let them reach 150+ layers and win ImageNet — the identity shortcut every Transformer still uses inside every block.Read →
- Vision Transformer (ViT)When an image became 16×16 words. Cut a picture into patches, treat each patch as a token, and feed them to a plain Transformer — no convolutions. Patch embeddings, the class token, and why data scale lets attention beat the CNNs that ruled computer vision for a decade.Read →
- DDPMThe original denoising diffusion math — the paper that made diffusion work. A fixed forward process adds Gaussian noise over many steps; a U-Net learns the reverse. The masterstroke: train the network to simply predict the added noise with a plain MSE loss. The foundation under every modern image generator.Read →
- GANsThe counterfeiter and the detective. Two networks locked in a game: a generator forging fakes from noise and a discriminator trying to catch them. The minimax objective that taught machines to imagine, its notorious instabilities and mode collapse, and how diffusion later overtook it.Read →