Topic 4 of 5 · 5 min read
How diffusion models generate images
Goal: Describe the denoising loop of a diffusion model and say what guidance strength and step count change in the output.
A diffusion model generates an image by starting from pure noise and removing a little of it at each step, guided by a text prompt, until a clean image remains. It never draws from nothing; it repeatedly corrects noise toward something that looks real.
Check yourself · 1 of 3
What does a diffusion model learn to do during training?
Why it matters
Diffusion powers Stable Diffusion, Midjourney-style tools, and many video generators. Knowing the loop explains the settings you tune: steps, guidance scale and seed.
Training and sampling
Training. Take real images, add noise of a random strength, and train a network to predict the noise that was added. The original DDPM paper formalised this. After training, the network can look at a noisy image and estimate what in it is noise.
Sampling. Start with random noise, the seed. Repeat for N steps: predict the noise, subtract a portion of it, and move to a slightly cleaner image. Early steps decide layout and colour. Later steps add fine detail.
Text conditioning. The prompt is turned into embeddings by a text encoder and fed into the denoising network, usually through cross-attention. Each step is then pulled toward images that match the text.
Guidance. Classifier-free guidance runs the network twice per step, with and without the prompt, and pushes the result away from the unconditioned one. The guidance scale sets how hard. Low values give varied, loose images. High values follow the prompt more literally, but too high gives oversaturated, artefact-heavy results and less variety.
Latent diffusion. Running the loop on full pixels is costly. Latent diffusion compresses the image with an autoencoder, denoises in that small latent space and decodes at the end. This is what made high-resolution generation practical on one GPU.
Current variants. Many recent image models, such as Stable Diffusion 3 and FLUX, swap the U-Net denoiser for a transformer and train with flow matching, a close relative of the noise-prediction objective. The loop and the settings below work the same way.
Settings in practice
- Steps: more steps usually mean cleaner detail with diminishing returns. Fast samplers reach good quality in far fewer steps than the original method.
- Seed: the same seed, prompt and settings reproduce the same image, which makes comparisons fair.
- Guidance scale: raise it when the model ignores the prompt, lower it when images look burnt or samey.
Before and after
Weak: the output ignores "a red bicycle", so you retype the prompt ten times with different seeds.
Better: keep the seed, raise guidance a little, then change one setting at a time. If the prompt names several objects, a single prompt may still bind attributes wrongly, which no setting fully fixes.
What goes wrong
- Pushing guidance very high and getting harsh, distorted images.
- Cutting steps too far and getting blurry results.
- Assuming the model understands the prompt like a person: it matches patterns learned from image-text pairs.
Examples
Tuning a product-photo generator
A team gets blurry mugs at 10 steps and burnt colours at guidance 20. They move to 30 steps and guidance 7 with a fixed seed, and compare outputs side by side. Changing one setting at a time shows which one caused each fault.
Why latent space is cheaper
A 512x512 RGB image has 786,432 values. If the autoencoder compresses it to a 64x64x4 latent, the denoiser works on 16,384 values per step, which is 48 times fewer.
Key points
- A diffusion model is trained to predict the noise added to real images, then run backwards from random noise to generate.
- Early denoising steps set layout and colour; later steps refine detail.
- Guidance scale controls how strongly each step follows the text prompt, trading prompt fidelity for variety and naturalness.
- More steps help with diminishing returns, and fast samplers give good results in fewer steps.
- Latent diffusion denoises in a compressed space, which is why high-resolution generation is affordable.
Common mistakes
- Raising guidance without limit in the hope of a perfect match, which causes saturated, distorted results.
- Changing the seed and several settings at once, so the cause of a change cannot be known.
- Treating step count as free quality; beyond a point extra steps cost time and add little.
- Believing diffusion edits real photos safely by default: generated detail is invented, not recovered.
Check yourself · 2 of 3
Images look oversaturated and distorted, and variety has dropped. Which setting is the likely cause?
Check yourself · 3 of 3
Why does latent diffusion make high-resolution generation cheaper?
Practice items, not counted towards your mastery.
Start here
- Stanford CS231n: Deep Learning for Computer Vision (opens in a new tab)CourseFree
Course notes on convolution layers, output-size arithmetic, pooling and transfer learning.
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale (opens in a new tab)PaperFree
The vision transformer paper: images as patch sequences, and when ViT needs large pretraining data.
- Denoising Diffusion Probabilistic Models (opens in a new tab)PaperFree
The paper that made step-by-step denoising a practical way to generate images.
More for this topic
- High-Resolution Image Synthesis with Latent Diffusion Models (opens in a new tab)PaperFree
Explains running diffusion in a compressed latent space, the basis of Stable Diffusion.
- Classifier-Free Diffusion Guidance (opens in a new tab)PaperFree
Defines the guidance scale that trades prompt fidelity against diversity.