4.5.15 · D5Generative Models

Question bank — Latent diffusion (Stable Diffusion)

1,642 words7 min readBack to topic

This page is a stress-test for your mental model of Latent diffusion (Stable Diffusion). Each item is a Question ::: Answer reveal. Read the question, commit to an answer out loud, then reveal. The answer side always gives a reason, never a bare yes/no — because the point is to repair the why, not just the what.

Before we start, three words we lean on constantly, in plain language:


True or false — justify

State true/false, then give the reason.

The VAE and the diffusion U-Net are trained together, end-to-end, in one loss.
False. The VAE is trained first and frozen; diffusion training then runs entirely on the frozen latents, so the U-Net never backprops into the encoder or decoder.
The 4 channels of a Stable Diffusion latent are red, green, blue, and alpha.
False. The 4 channels are learned abstract features, not colour channels — the VAE decides what each channel means during training. RGB only exists again after the decoder .
Denoising happens in pixel space and the VAE is just a final polish step.
False. The whole reverse loop runs in latent space; the decoder is called once at the very end to turn into pixels. This is the entire point of "latent" diffusion.
A plain (non-variational) autoencoder would work just as well for the latent space.
False. Without the KL term the latent space develops "holes" that decode to garbage; a denoising trajectory passing through one breaks the image. The smoothness is a requirement, not a nicety.
The forward noising schedule is different from DDPM's.
False. The math of noising is identical to DDPM; the only change is that it acts on latents instead of pixels . Latent diffusion is DDPM in a compressed room.
Text conditioning enters through cross-attention where the image supplies and the text supplies .
True. Each spatial patch of the latent forms a query and "looks up" which text tokens to attend to; the text embedding provides keys and values . That is how "sunglasses" reaches the right region.
Latent diffusion is inherently lower quality than pixel diffusion because it compresses.
False. The VAE is lossy but perceptually near-lossless — it throws away redundancy, not semantics. The saved compute buys more training, so latent diffusion matches or beats pixel diffusion in practice.
The classifier-free guidance scale changes what the VAE decoder does.
False. Classifier-Free Guidance reshapes the noise prediction inside the loop; the decoder is untouched and runs identically regardless of guidance strength.
Switching from DDPM sampling to DDIM Sampling requires retraining the U-Net.
False. Both samplers use the same trained ; DDIM just changes the update rule that turns a noise prediction into the next latent, so you can swap samplers at inference freely.

Spot the error

Each line contains a wrong statement. Reveal fixes it.

"The U-Net predicts the clean latent directly."
It predicts the noise that was added, i.e. ; (or ) is then computed from that prediction via the sampling formula.
"Because the latent is , the U-Net's self-attention cost drops by exactly ."
Self-attention scales as where , so cutting by cuts attention cost by about ; only the convolutional work drops linearly ().
"We compute to start generation."
We sample directly; the encoder is only used to make training latents from real images, never at generation start.
"The 512×512 → 64×64 downsampling uses factor ."
The factor is (); would give .
"CLIP's embedding is a single 768-vector for the whole prompt."
It is a matrix — one 768-vector per token slot — which is precisely what lets different regions attend to different words.
"The KL term in the VAE makes the reconstruction pixel-perfect."
KL does the opposite of that — it regularizes the latent toward a smooth Gaussian-like shape (aiding diffusion); reconstruction fidelity comes from the L2 pixel loss, and it is deliberately not pixel-perfect.
"Attention cost scaling as means doubling the image side doubles the attention cost."
Doubling the side quadruples (area), and then rises — the quadratic blow-up in area is exactly why pixel-space attention was the bottleneck.
"Since the VAE is frozen, its choice doesn't affect final image quality."
A frozen VAE still sets a hard ceiling: diffusion can never recover detail the decoder cannot render, so a weak VAE caps quality no matter how good the U-Net is.

Why questions

Answer the why, not just the fact.

Why use a variational autoencoder instead of a plain one for the latent space?
The KL term forces a continuous, smooth latent space where nearby latents decode to similar images; diffusion moves gradually through latent space and needs this continuity to avoid landing in decode-to-garbage holes.
Why denoise latents instead of pixels at all?
Natural images are hugely redundant (neighbouring pixels correlate); working in the -smaller latent removes that redundancy, so compute focuses on semantics instead of fighting dimensionality — dramatically cheaper attention.
Why does the U-Net predict noise rather than the clean signal?
Predicting gives a well-scaled, roughly unit-variance target at every timestep, which trains stably; the clean latent can then be algebraically recovered from and when needed.
Why is cross-attention (not just concatenation) used to inject text?
Attention lets each spatial patch independently choose which text tokens matter to it, so "spacesuit" influences the body region and "corgi" the face — a fixed concatenation could not route information region-by-region.
Why can we freeze the VAE and still train diffusion successfully?
The VAE defines a fixed, stable target manifold of "valid latents"; diffusion only needs to learn to navigate that fixed space, so re-training the VAE mid-way would just move the goalposts and destabilize learning.
Why does the reverse step multiply the bracket by ?
After subtracting the predicted noise the remaining signal is shrunk (because forward noising scaled down); the factor rescales it back to the correct magnitude for the next step.
Why add fresh noise during DDPM sampling if we're trying to remove noise?
A little re-injected randomness restores diversity and matches the true reverse distribution's variance; sampling with (as DDIM Sampling can) is deterministic but yields less variety per seed.

Edge cases

Boundary and degenerate scenarios.

What is at (the last forward step) and what does that mean for ?
, so — the latent is essentially pure Gaussian noise, which is exactly why generation can start from random noise.
What happens at in the forward process?
, giving with negligible noise — the clean encoded latent, the endpoint the reverse loop is trying to reach.
If you set the classifier-free guidance scale to , what conditioning behaviour do you get?
Guidance scale means no amplification — you get the plain conditional prediction, so prompts are followed weakly; higher scales exaggerate the difference between conditional and unconditional predictions.
What if the input image contains fine text or a barcode — does the VAE handle it?
Poorly; those are exactly the high-frequency, non-redundant details the compression struggles to preserve, which is why generated small text is often garbled — a genuine limitation of the latent bottleneck.
What if you feed the U-Net an empty prompt (embedding of ""), what does it produce?
The unconditional prediction — a plausible but unguided image; this same empty-prompt path is precisely what Classifier-Free Guidance uses as its "unconditional" branch.
If the noise schedule made for all , what breaks?
Then for every , so no noise is ever added, , and there is nothing to denoise — the model can learn no reverse process and generation is impossible.
At extremely high sampling steps ( very large), what is the trade-off?
Quality gains flatten while compute grows linearly with steps; beyond a point (often ~50 with DDIM) extra steps mostly waste time, which is why few-step samplers exist.
Can the same trained U-Net denoise a latent of a different spatial size (e.g. )?
Partly — convolutions and attention are size-agnostic in principle, but the model was trained at one resolution, so off-size latents often show repetition or artifacts; it works but degrades outside the training regime.

Recall Quick self-test

Fresh-noise-during-denoising purpose ::: restores diversity / matches reverse-process variance; makes it deterministic. What the 4 latent channels are ::: learned abstract features, not RGB. Why VAE not plain AE ::: KL keeps latent smooth/continuous so diffusion never hits decode-to-garbage holes. Attention cost scaling in ::: quadratic, — the reason pixel-space was the bottleneck.