Diffusion models generate images by learning to reverse a process of gradual destruction. You take a real image, slowly corrupt it into pure static, and train a neural network to undo each tiny step of that corruption. Once the network is good at undoing noise, you can hand it a canvas of random noise and let it denoise its way to a brand-new image that never existed before. Every modern image generator, Stable Diffusion, Midjourney, DALL·E-style systems, is built on this single idea.
The forward process: destroying structure on purpose
The forward process is fixed, involves no learning, and simply adds Gaussian noise to a clean sample x0 over T steps until nothing recognizable remains. A closed-form shortcut lets you jump straight to any step t:
Ask the tutor
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
xt=αˉtx0+1−αˉtϵ,ϵ∼N(0,I)
Here αˉt comes from the noise schedule, a predetermined sequence that controls how fast signal is replaced by noise. Early steps barely perturb the image; late steps leave almost pure static. Because the schedule is known and fixed, we always know exactly how much noise was added at each step, which gives us a perfect training target.
The reverse process: a network that predicts noise
Generation runs that process backward. A neural network, usually a U-Net, or in newer systems a diffusion transformer, looks at a noisy sample xt and the step index t, and predicts the noise ϵ that was mixed in. We subtract a scaled portion of that prediction to recover a slightly cleaner sample, then repeat. Starting from pure noise and iterating down turns random static into a coherent image.
1Start from noiseSample a latent of pure Gaussian static, this is the starting canvas.
2Predict the noiseThe network estimates which part of the current latent is noise.
3Take one denoising stepSubtract a scaled fraction of that predicted noise to get a slightly cleaner latent.
4RepeatLoop for the chosen number of sampler steps, moving from high noise toward low noise.
5DecodeIn latent diffusion, a VAE decoder turns the final latent into a full-resolution image.
The training objective
Training is remarkably simple. Take a clean image, pick a random step t, sample noise ϵ, build xt with the forward formula, and ask the network to predict that noise. The loss is plain mean-squared error between the true and predicted noise:
L=Ex0,ϵ,t[∥ϵ−ϵθ(xt,t)∥2]
There is no adversarial game and no discriminator, just regression against a known target, which is why diffusion training is far more stable than GAN training.
Classifier-free guidance
To follow a text prompt, the network is trained to predict noise both with a caption and without one (the caption randomly dropped). At sampling time we combine the two predictions and extrapolate away from the unconditional one:
ϵ^=ϵθ(xt,t,∅)+s(ϵθ(xt,t,c)−ϵθ(xt,t,∅))
The guidance scales controls prompt adherence. At s=1 you get the plain conditional prediction; larger s pushes the sample harder toward the text.
One denoising step, by the numbers
Take a 2D latent for illustration. Suppose the current noisy latent is xt=[1.60,−0.80] and the network predicts noise ϵθ=[0.50,−0.30]. With an illustrative step coefficient c=0.2 (the real DDPM update also rescales by schedule terms, but the essence is: subtract predicted noise):
The latent moved a little closer to a clean sample. Now add text guidance. Say the unconditional prediction is [0.50,−0.30] and the conditional, prompt-aware prediction is [0.20,−0.60]. With s=3:
Subtracting this guided estimate instead of the raw one pulls the latent much more decisively in the direction the prompt implies, which is exactly why higher guidance yields more prompt-faithful but potentially over-saturated images.
Latent diffusion and samplers
Running diffusion directly on megapixel images is expensive. Latent diffusion first uses a VAE encoder to compress the image into a small latent grid, runs the entire noising and denoising process there, then decodes back to pixels. This compression is why Stable Diffusion is fast enough for consumer GPUs. The sampler (DDPM, DDIM, DPM-Solver, and others) decides how many steps to take: fewer steps are faster but coarser, more steps refine detail with diminishing returns.
Why removing noise creates new images
Intuition
For a curious beginner
Picture a sculptor who can glance at a rough block and see which chip to
remove next. The network learns, for any noisy picture, which speckles do
not belong. Point it at random static and it keeps chipping away noise that
was never organized in the first place, and because each starting canvas
differs, the image it uncovers is new every time.
Engineering
How it is actually used
The model is just a denoiser trained on (noisy input, noise target) pairs
across every noise level. At inference you feed it pure noise, then its own
partially cleaned outputs, step after step. Nothing memorizes a specific
image; the network only ever emits a noise estimate, and the sampler
integrates those estimates into a trajectory that lands on a plausible
sample from the data distribution.
Mathematical
The underlying mechanism
Noise prediction implicitly learns the score, the gradient of the log data
density ∇xlogp(x). Repeatedly subtracting predicted noise is a
discretized walk along that gradient (a Langevin-style or probability-flow
ODE step), transporting a Gaussian sample toward a high-density region of
the learned distribution. Fresh samples arise because the initial noise and
the stochastic steps differ on each run.
For a curious beginner
Picture a sculptor who can glance at a rough block and see which chip to
remove next. The network learns, for any noisy picture, which speckles do
not belong. Point it at random static and it keeps chipping away noise that
was never organized in the first place, and because each starting canvas
differs, the image it uncovers is new every time.
How it is actually used
The model is just a denoiser trained on (noisy input, noise target) pairs
across every noise level. At inference you feed it pure noise, then its own
partially cleaned outputs, step after step. Nothing memorizes a specific
image; the network only ever emits a noise estimate, and the sampler
integrates those estimates into a trajectory that lands on a plausible
sample from the data distribution.
The underlying mechanism
Noise prediction implicitly learns the score, the gradient of the log data
density ∇xlogp(x). Repeatedly subtracting predicted noise is a
discretized walk along that gradient (a Langevin-style or probability-flow
ODE step), transporting a Gaussian sample toward a high-density region of
the learned distribution. Fresh samples arise because the initial noise and
the stochastic steps differ on each run.
Common mistakes
Confusing sampler steps with network depth. The number of denoising steps (say 20 to 50) is how many times you call the network at inference; it is unrelated to how many layers the U-Net or transformer contains.
Cranking the guidance scale too high. A large s over-emphasizes the prompt and produces over-saturated, high-contrast, or artifact-ridden images. Useful values usually sit in the single digits.
Forgetting the VAE. In latent diffusion the denoiser outputs a latent, not an image, you must run the VAE decoder to get pixels. Skip it, or mismatch the VAE, and you get garbled color.
Assuming more steps always help. Past a sampler's sweet spot, extra steps mainly cost time; quality plateaus and can even degrade with some schedules.