Diffusion Models
A diffusion model learns one small skill: predicting the noise hiding in a noisy image. Start from pure static and repeat that cleanup, and a brand-new picture appears.
Why Does This Exist?
Type "a cup of coffee on a wooden table at sunrise" into a text-to-image model and you get that exact scene back: steam, warm light, grain in the wood. No photo of that cup exists anywhere, and nobody drew it. The pixels are new.
Earlier generators each paid a price you can see. A generative adversarial network trains a generator against a discriminator, which samples in one pass but trains unstably, and the generator can collapse onto a handful of outputs. A variational autoencoder trains calmly but hedges, so its samples look blurry next to diffusion output. Diffusion chose the opposite trade: stable supervised training and sharp images, paid for with slow sampling, because generation needs many repeated network passes instead of one.
This page covers that trade at the level you need first: the fixed forward noising, the learned reverse cleanup, and sampling from static. The schedule math lives in forward and reverse processes, the speed fix in diffusion samplers, the compressed-space version in latent diffusion, and prompt steering in classifier-free guidance. The one idea you need first: Gaussian noise, the static this whole method adds and removes. Every pixel is independent randomness with mean zero, and the full picture is in normal distribution.
Think of It Like This
A restorer who never saw the original photo
You inherit a print buried under TV static, with ghosts of shapes underneath. A restorer doesn't repaint the scene in one guess. They study the grainy print, make it a touch cleaner, look again at the clearer result, and repeat. Each pass is small and safe, because the current print is always there to correct against. After many passes, faces and streets reappear out of what looked like pure snow.
A diffusion model is that restorer, with one twist that breaks the analogy if you push it. A human restorer starts from a real buried photo. A diffusion model starts from static that never had a photo under it, and a text prompt tells each cleanup pass which scene to lean toward. Same skill, no original.
How It Actually Works
Diffusion has two directions and only one of them learns. The forward process destroys an image with fixed math. The reverse process learns to undo a single step of that destruction. Generation runs the learned undo from pure noise.
The forward pass is fixed arithmetic
Write for the clean image and for its noisy version after steps, where counts upward to , the total step count. At each step you mix in fresh Gaussian noise , which is independent static with mean zero and variance one, resampled every step. How much noise enters at step comes from a fixed plan called the noise schedule: is the noise variance at step , a small positive number chosen before training and never learned.
Set , the signal kept at step , and , the product of through , which is the fraction of the original image still alive at step . Then any noisy version follows in one jump:
The left term is surviving image, the right term is accumulated static. Push all the way to and the first term dies out, so is pure static. No network touches this direction. That's the point: destroying information on a fixed plan needs no learning.
The network learns one reverse step
The trained object is a denoiser : a neural network with weights that takes a noisy image plus its step number and guesses the noise hiding inside. Training is plain supervised regression with free labels. Take a real photo, pick a random , sample an , build with the formula above, and the correct answer is the you just added. The loss is the squared miss:
Here means the average over photos, steps, and noise draws, and is the squared length of the miss.
Sampling runs the skill backward. Draw from pure static, ask the network for its noise guess, subtract a scaled version of that guess to get , one notch cleaner, and repeat down to . The prompt steers every subtraction, which is its own mechanism in classifier-free guidance. Each step moves only a little, so coherence belongs to the whole chain, never to one pass. That's also why sampling is slow, the price named above. When one pass must do, that job belongs to a single-forward generator or to a sampler built for few steps, covered in diffusion samplers.
This rests on one assumption: the schedule must destroy signal gradually enough that each reverse step has structure to grip. A plan tuned for small thumbnails can shred a large detailed photo too fast, and samples come back blurry or broken. Schedules get tuned per dataset and resolution, as forward and reverse processes shows.
Worked example: one noisy pixel
Shrink the image to a single pixel with value . Suppose at step the surviving fraction is . Then keeps the signal, and , rounded to two decimals, mixes the noise. Draw :
The pixel drifted from to on of added static. Say the network predicts . This example's loss is:
A small loss, and note what it measures: noise error, not photo quality. The diagram above carries these same numbers, and the snippet below recomputes them.
Code
The whole forward jump plus the loss, on the worked numbers. No training loop, no library model, only the two formulas above.
import math
def forward_closed_form(x0: float, abar: float, eps: float) -> float: """One jump to step t: surviving signal plus accumulated noise.""" return math.sqrt(abar) * x0 + math.sqrt(1.0 - abar) * eps
def noise_loss(eps: float, eps_pred: float) -> float: """Squared miss between the true noise and the network guess.""" return (eps - eps_pred) ** 2
x0 = 0.80abar = 0.81eps = 0.50xt = forward_closed_form(x0, abar, eps)print(round(xt, 2)) # -> 0.94print(round(noise_loss(eps, 0.45), 4)) # -> 0.0025Watch Out For
Cutting steps with the same sampler and blaming the model
You get diffusion working, then try a few steps instead of the full chain to save time. Samples come back mottled or washed out, and it looks like training failed. It didn't. The network learned one small cleanup per step, so large jumps land off the path it trained on.
Keep the full chain, or switch to a sampler built for few steps. That choice, with its own quality cost, is the subject of diffusion samplers. Never judge a trained denoiser by a step count its sampler was not built for.
Reading the noise loss as photo quality
A loss of feels like victory, then the samples disappoint. The loss averages noise-guess error at random steps, so it can fall while composition, prompt fit, or fine detail stay broken. It never saw a finished photo.
Judge generation with finished samples and the metrics built for them, such as those in generative media evaluation. Use the training loss to debug training, not to score pictures.
The Quick Version
- A diffusion model trains one skill: guessing the noise inside a noisy image at a known step.
- The forward pass is fixed arithmetic with no learned weights, and scheduled noise buries the image until only static remains.
- Training labels are free, because each example's correct answer is the noise the forward pass just added.
- Generation starts from pure static and applies the learned cleanup step by step, with the prompt steering each pass.
- Few-step sampling needs its own sampler, and the noise loss measures denoising error rather than picture quality.