Diffusion Models: Learning to Denoise
About 40 min
Goal
By the end of this lesson, you can explain diffusion generation as learned iterative denoising and compare its generation loop with autoregressive next-token generation.
Level 6 has followed one modern generative pattern so far:
Autoregressive generation
token → next token → next token → ...
Now consider a different job.
Suppose you have a clean low-resolution pattern:
█ · █ ·
· █ · █
█ · █ ·
· █ · █
Add a little random corruption and the structure is still visible. Add more and more corruption and eventually the original pattern is hard to recognize.
A diffusion model learns the opposite skill: given a noisy state, predict how to remove some of the noise.
Generation then runs that learned repair process repeatedly:
Diffusion generation
noise → less noise → less noise → ... → sample
The important idea comes before any architecture details.
Step 1: start with clean data
Training begins with ordinary examples from the data distribution: images, audio representations, or other continuous data.
Call one clean example x₀.
At this point there is no generation yet. We already have the clean training example.
Step 2: add noise in controlled steps
Imagine corruption levels from 0 to 4:
step 0 clean
step 1 slightly noisy
step 2 noisier
step 3 heavily noisy
step 4 almost entirely noise
The forward noising process is deliberately easy to run. We control how much noise is added at each step.
This process is not the generative direction. It creates training situations where the model can practice recognizing what corruption was added.
Predict
Step 3: train a model to predict what should be removed
For a noisy example, the model receives information such as:
- the corrupted sample;
- how far along the noising process it is;
- optionally, a conditioning signal.
A common training target is the noise that was added.
clean example
↓ add known noise
noisy example
↓ denoiser
predicted noise
↓ compare
actual added noise
If the predicted noise is wrong, the loss is larger. Optimizer updates gradually improve the denoiser.
Only now, after seeing the corruption-and-repair job, do we need a small amount of math. A toy corruption rule can be written as:
corrupted = (1 - noise_level) × clean + noise_level × noise
This linear blend is only a teaching rule for making the corruption visible. It is not the exact forward equation used by DDPMs. Real diffusion systems usually draw random noise from a defined distribution and combine it with the clean example using timestep-dependent coefficients.
A simple training loss can compare predicted noise with the known noise:
loss = mean((predicted_noise - added_noise)²)
Real diffusion systems use more carefully designed noise schedules and parameterizations. You do not need scheduler notation, stochastic differential equations, or a particular neural-network architecture to understand the core training signal.
Step 4: generate by starting from noise
At generation time there is no clean answer to reveal.
Instead:
- start from random noise;
- ask the trained denoiser what noise-like component should be removed;
- move to a slightly cleaner state;
- repeat for several steps.
That is why sampling is iterative.
One denoising step usually does not produce a final image-like sample any more than one next-token decision produces a whole paragraph.
Watch structure emerge across denoising steps
A generated sample can share a pattern with training data without being the same picture. Move through this qualitative trajectory:
Denoising trajectory: structure emerges without restoring one stored picture
Move through one qualitative 4 × 4 trajectory. Repeated updates make an alternating pattern clearer while the final sample remains different from the clean example shown above.
The final 4 × 4 sample deliberately uses the opposite checkerboard phase from the clean example shown at the start of the lesson. The useful idea is shared structure, not recovery of one stored target.
Run a visible corruption-and-generation experiment
The Lab uses four numbers instead of an image so every update remains inspectable.
It contains:
- one clean example used only to demonstrate forward noising;
- two different fixed noise starts,
noise_aandnoise_b; - a small state-dependent denoising rule that favors an alternating family of patterns;
- a learner-controlled
denoise_strength.
The toy rule projects the current state toward an alternating pattern family, not toward one completed vector. The start itself determines the family member's amplitude and phase, so two starts can converge toward different samples even if denoising continues for many more steps. A real diffusion model learns useful denoising structure from data rather than receiving this rule directly.
Loading lab…
Use this sequence:
- Click Run unchanged.
- Read the forward errors from the clean example. They grow as more corruption is added.
- Read
reverse structure errors. They should fall across the reverse steps. - Compare
family member implied by this start,generated toy sample, andclean training example. The generated sample moves toward the alternating family member implied by its own start, not toward the clean example. - Before editing, predict whether a different random start must imply exactly the same family member.
- Change only
start_noise = noise_atostart_noise = noise_b. - Click Run and compare the new family member and final sample with the first run. Explain what stayed structurally similar and what changed.
- Reset. As a second experiment, change only
denoise_strength = 1.0to0.5. Make a prediction before you run, then compare the remaining structure error after the same number of updates.
Notice what the reverse code does not receive: run_reverse takes the chosen noise start and the strength, while predict_correction derives a nearby family member from the current state. The clean training example is not the answer being copied into the reverse loop.
Autoregressive and diffusion generation are different loops
Put the two side by side:
Autoregressive
known prefix
→ predict distribution for one next token
→ select token
→ append token
→ repeat
Diffusion
random noisy state
→ predict a correction/noise component
→ update the whole current state
→ repeat
Autoregressive language generation grows a sequence one token at a time.
Diffusion usually refines a continuous state over multiple denoising steps.
Both are generative because they can produce new samples from learned patterns, but they organize generation differently.
Conditioning steers the denoising process
Unconditional diffusion asks only:
What data-like sample should this noisy state become?
A conditioned diffusion model also receives information about what kind of sample is wanted.
The condition might be:
- a class label such as “cat”;
- a text representation such as “a red bicycle in snow”;
- another image or structural signal.
Conceptually:
noisy state + condition
↓
denoiser
↓
correction consistent with both
the data distribution and the condition
Modern text-to-image systems often use text-derived conditioning, and many operate in a learned latent representation rather than directly denoising full-resolution pixels. Those engineering choices matter, but they are not required to understand the generative loop.
A diffusion model is not searching a database for a matching training image
The generation mechanism described above does not perform:
prompt → search training image database → return closest image
Instead, training adjusts model parameters so the denoiser learns statistical structure useful for removing noise. At generation time, the model repeatedly computes corrections from its current state and condition.
That does not mean memorization is impossible. Any high-capacity model can memorize or reproduce training examples under some conditions, and responsible evaluation should test for that risk.
The important distinction is about the mechanism: diffusion generation is learned iterative denoising, not ordinary nearest-image database lookup.
Place diffusion beside VAEs and GANs
Diffusion is not the only non-autoregressive generative family. Two other families are worth recognizing because they organize learning in very different ways.
| Family | Central learning idea | Generation sketch |
|---|---|---|
| Variational autoencoder (VAE) | Encode an example into a constrained latent distribution, sample a latent point, and decode it while balancing reconstruction with pressure for a usable latent space. | latent sample → decoder → generated example |
| Generative adversarial network (GAN) | Train a generator against a discriminator: the generator tries to produce convincing samples while the discriminator tries to distinguish generated from real data. | random input → generator → sample, with discriminator feedback during training |
| Diffusion | Corrupt data in a controlled way and train a model to predict a reverse correction. | noise → repeated denoising → generated example |
A VAE makes the latent representation central. Instead of memorizing one code per training example, the training objective encourages a smoother latent distribution from which new points can be sampled. That gives a useful way to reason about interpolation and compressed generative representations, although the exact quality tradeoffs depend on the architecture and objective.
A GAN makes the adversarial game central. The discriminator's job creates a learned training signal for the generator. GAN research showed that this setup can produce strong samples, but it also introduced characteristic optimization problems such as unstable training and mode collapse, where the generator covers too little of the data distribution.
These descriptions are historical context and still-useful model ideas, not a ranking. VAEs, GANs, and diffusion are not steps where a newer family automatically makes an older one pointless. Their objectives, failure modes, sampling procedures, compute costs, and useful domains differ. The core curriculum builds the autoregressive path and gives diffusion a concrete denoising Lab; VAE and GAN coverage stays at recognition level so the Level does not become a catalog of separate generative projects.
How this fits Level 6
This lesson adds a second generative pattern to your mental map. The next lesson continues the tiny-language-model workflow with generation failure diagnosis.
Quick Check
Explain it back
Explain diffusion to someone who knows next-token generation but has never seen an image generator.
Use this order:
- clean data;
- controlled noising;
- learn to predict or remove noise;
- start from noise and denoise repeatedly;
- add conditioning if you want to steer the result.
Then compare that loop with autoregressive token generation in two or three sentences.
Check your explanation
A strong answer mentions:
- Start with clean data, corrupt it with controlled noise, and train the model to predict noise or a reverse correction.
- To generate, start from noise and iteratively denoise; conditioning can steer each refinement step.
- Unlike autoregressive generation, which appends one selected token to a prefix at each step, diffusion repeatedly refines a noisy state.
Key Takeaways
- Diffusion is a distinct modern generative paradigm built around controlled noising and learned denoising.
- Training creates corrupted examples and teaches a model to predict a useful reverse correction, often the added noise.
- Generation starts from noise and repeatedly refines the current state.
- Conditioning supplies extra information that can steer the denoising trajectory.
- The mechanism is learned iterative denoising, not ordinary database lookup.
- VAEs and GANs provide distinct latent-variable and adversarial learning ideas that are important to recognize beside autoregressive and diffusion models.
Next Lesson
Next, return to the tiny-language-model spine in L6.11 — Generation Failure Modes and diagnose repetition, collapse, incoherence, and prompt drift with controlled evidence.
References
- Ho, Jain, and Abbeel, Denoising Diffusion Probabilistic Models.
- Rombach et al., High-Resolution Image Synthesis with Latent Diffusion Models.
- Kingma and Welling, Auto-Encoding Variational Bayes.
- Goodfellow et al., Generative Adversarial Nets.
Completion is stored locally on this device.