
Key points
- Training adds noise to real images and teaches a network to predict the noise that was added.
- Generation runs the process in reverse: from random noise to a clean image over many small steps.
- Latent diffusion denoises a compressed representation instead of raw pixels, which makes it far cheaper.
- A text encoder conditions every step, and classifier-free guidance controls how strictly the prompt is followed.
- Sampling is slower than a single forward pass, so much research aims at fewer steps.
What a diffusion model is
A diffusion model is a generative model: after training on many examples, it can produce new samples that look like they come from the same distribution. Its defining feature is how it gets there. Instead of producing an image in one shot, it begins with an array of random Gaussian noise the size of the image and refines it through a sequence of denoising steps, each of which makes the array slightly less noisy and slightly more like a plausible picture.
The idea was introduced by Sohl-Dickstein and colleagues in 2015, inspired by non-equilibrium thermodynamics, where a structured system slowly diffuses into disorder. It became practical for high-quality images with Denoising Diffusion Probabilistic Models (DDPM) by Ho, Jain and Abbeel in 2020, explained in detail in our article on the DDPM paper. In parallel, Song and Ermon developed score-based models that estimate the gradient of the data distribution, and Song et al. (2020) showed that both views can be described as stochastic differential equations. Since about 2021–2022, diffusion has largely replaced generative adversarial networks as the main approach for image generation.
How it works
The forward process: destroying images on purpose
Training starts with a fixed, simple procedure called the forward process. Take a real image and add a small amount of Gaussian noise. Do it again, and again, following a schedule that says how much noise to add at each step. After enough steps (the DDPM paper used 1,000) the result is indistinguishable from pure noise. A useful mathematical property is that you can jump directly to any step: the noisy image at step t is just the original scaled down plus noise scaled up by known amounts, so no loop is needed during training.
Training: learn to predict the noise
The network, historically a U-Net and more recently often a transformer, receives a noisy image and the step number t. Its job is to predict the noise that was mixed in. Training repeats one simple loop: pick a real image, pick a random step, add the corresponding noise, ask the network to predict it, and adjust the weights to shrink the squared error between the predicted and actual noise. Ho et al. found that this simple noise-prediction objective worked better in practice than the more elaborate variational bound it is derived from.
Sampling: run it backwards
To generate, start from fresh random noise at the final step. Ask the network what noise it sees, subtract a scaled portion of it, optionally add back a little fresh noise, and move one step closer to zero. Repeat until step zero. Each step makes only a small correction, which is why the process is stable, but it also means many network evaluations per image. Later samplers such as DDIM (Song, Meng and Ermon, 2020) showed that good images can be produced with far fewer steps by taking larger, deterministic jumps.
Latent diffusion: working in a compressed space
Running hundreds of steps on full-resolution pixels is expensive. Latent diffusion (Rombach et al., published at CVPR 2022) first trains an autoencoder that compresses an image into a much smaller latent array and can decode it back with little visible loss. Diffusion then happens in that latent space. In the original Stable Diffusion models, built on this work, a 512×512 RGB image corresponds to a 64×64 latent with 4 channels, roughly 48 times fewer values. The final latent is decoded into pixels once, at the end.
Conditioning on text and guidance
To follow a prompt, the denoising network also receives a representation of the text, usually from a pretrained text encoder such as the one in CLIP or a large language-model encoder. In U-Net designs the image features attend to the text embeddings through cross-attention layers, so every step is nudged toward images that match the words.
Classifier-free guidance (Ho and Salimans, 2022) makes the nudge stronger. During training the text is sometimes dropped, so the same network learns both a conditional and an unconditional prediction. At sampling time both are computed and the difference between them is amplified by a guidance scale. Higher guidance gives images that match the prompt more literally but with less variety and, if pushed too far, oversaturated colours and artefacts.
A concrete example. Prompt: a red bicycle leaning against a blue door. The text encoder turns the prompt into a sequence of vectors. The sampler starts from a 64×64×4 array of random numbers. In early steps the network can only commit to coarse structure, so a vague vertical blue region and a darker shape emerge. Middle steps settle composition and colour. Late steps add fine texture: spokes, wood grain, shadows. Finally the decoder turns the latent into a 512×512 image. Run the same prompt with a different random seed and you get a different bicycle and door, because the starting noise was different.
Comparing generative approaches
| Approach | How it generates | Strengths | Weaknesses |
|---|---|---|---|
| GAN | Generator maps noise to an image in one pass, trained against a discriminator | Very fast sampling, sharp images | Unstable training, mode collapse, harder to condition on long text |
| Autoregressive | Predicts image tokens one after another | Same machinery as language models | Slow for high resolution, many tokens |
| Diffusion | Iteratively denoises random noise | Stable training, high diversity and quality, flexible conditioning | Many network evaluations per sample |
Why it matters
Diffusion models underlie most widely used image generators released since 2022, and the same principle extends to other data. Text-to-video models denoise stacks of frames; audio and music generators denoise spectrograms or audio latents; scientific models generate molecules and protein structures. Because each step is a small, local correction, diffusion is also naturally suited to editing: you can add partial noise to an existing image and denoise it under a new prompt (image-to-image), or regenerate only a masked region (inpainting) while keeping the rest.
The approach also changed how researchers think about generation. Instead of one model having to produce a perfect sample in one pass, the problem is decomposed into many easier denoising problems, each at a different noise level. That decomposition is one reason diffusion training tends to be more stable than adversarial training.
Limits and common misconceptions
- It does not paste together stored images. The model learns a statistical denoiser, not a library of pictures. However, research has shown that diffusion models can sometimes reproduce near-copies of images that appear many times in their training data, so memorization is a real, measurable risk.
- Text and counting are hard. Early models often rendered garbled lettering and wrong numbers of objects or fingers. Newer models with stronger text encoders and transformers have improved markedly, but exact text, counts and spatial relations remain common failure points.
- Sampling cost. Even with fast samplers, generation usually needs several to dozens of network evaluations, compared with one for a GAN. Distillation methods and consistency models reduce this to a few steps, often with some trade-off in quality or diversity.
- Guidance is not free. Turning guidance up improves prompt adherence but reduces diversity and can degrade realism.
- Bias follows data. Generators reflect the image-caption pairs they were trained on, including stereotypes and gaps in representation; see bias and fairness in AI.
- Provenance and rights. Realistic synthetic images raise questions of misuse and copyright that the technique itself does not resolve; see deepfakes and content provenance and AI and copyright.
Where it is going
Three trends stand out. First, the denoising network is increasingly a transformer: Peebles and Xie (2022) showed with Diffusion Transformers (DiT) that such models improve predictably as they scale, and transformer backbones now appear in many image and video systems. Second, closely related formulations such as flow matching and rectified flow learn a direct path from noise to data, which can simplify training and allow fewer sampling steps. Third, generators are being merged with language models, so that one system can follow long, detailed instructions, keep a character consistent across images and edit through conversation. The core idea, learning to reverse a gradual corruption process, has remained the same throughout.
You can try several current image models with the same prompt in Cosvexa's AI Image Studio and compare how each one interprets it.
Frequently asked questions
How do diffusion models work in simple terms?
They are trained by adding noise to real images and learning to predict that noise. To make a new image they start from pure noise and repeatedly remove the noise the network predicts, until a clean image remains. A text prompt guides each step.
What is latent diffusion?
Latent diffusion runs the denoising process on a compressed representation of the image made by an autoencoder, rather than on raw pixels. This makes generation much cheaper, and the result is decoded into a full image at the end. Stable Diffusion is the best-known example.
What does the guidance scale (CFG) do?
Classifier-free guidance compares the model's prediction with and without the prompt and amplifies the difference. A higher scale follows the prompt more closely but gives less variety, and very high values cause oversaturated or distorted images.
Why does the same prompt give different images?
Each generation starts from a different random noise pattern, set by the seed. Different starting noise leads the denoising process to different, equally plausible images. Fixing the seed and settings usually reproduces the same image on the same model.
Are diffusion models better than GANs?
For general text-to-image generation diffusion models have largely replaced GANs because they train more stably and produce more diverse, controllable results. GANs remain much faster at sampling and are still used where speed matters, sometimes combined with diffusion.
References
- Sohl-Dickstein, Weiss, Maheswaranathan and Ganguli (2015). Deep Unsupervised Learning using Nonequilibrium Thermodynamics
- Ho, Jain and Abbeel (2020). Denoising Diffusion Probabilistic Models
- Song et al. (2020). Score-Based Generative Modeling through Stochastic Differential Equations
- Rombach, Blattmann, Lorenz, Esser and Ommer (2021). High-Resolution Image Synthesis with Latent Diffusion Models
- Ho and Salimans (2022). Classifier-Free Diffusion Guidance
- Peebles and Xie (2022). Scalable Diffusion Models with Transformers