6.7 Guidance and conditioning
1. Learn
Section titled “1. Learn”- MIT 6.S184 lecture notes: Flow Matching and Diffusion Modelsthe section on conditional generation and classifier-free guidance
- Ho and Salimans, Classifier-Free Diffusion Guidancesections 2–3 (classifier and classifier-free guidance) and 4.1 (the fidelity–diversity trade-off)
- Dhariwal and Nichol, Diffusion Models Beat GANs on Image Synthesissection 4: classifier guidance
2. Bridge
Section titled “2. Bridge”Conditioning. To generate a chosen digit, or an image matching a caption, give the network the condition y as one more input and train exactly as in 6.6, with each data point’s own label. The learned v(x, t, y) is then the marginal velocity of the data with that label, p(x | y) (Holderrieth and Erives 2025, the section on conditional generation).
Why plain conditioning is not enough. In practice samples of p(x | y) can look only loosely like their class. The fix is to exaggerate the condition. Classifier guidance did this with a separately trained classifier on noisy inputs, adding w ∇log pt(y | x) to the score (Dhariwal and Nichol 2021, section 4).
Classifier-free guidance. Ho and Salimans removed the classifier (2022, sections 2–3). Replace the label with a null token ∅ about 10% of the time during training, so one network also learns the unconditional field v(x, t, ∅). At sampling time use v(x, t, ∅) + w (v(x, t, y) − v(x, t, ∅)). By Bayes’ rule the difference of the two is, up to a factor, the gradient of log pt(y | x): the classifier was inside the network all along. w = 0 ignores the label and w = 1 is plain conditional sampling. With w > 1, samples become more recognisably their class and less varied, and they are no longer distributed as p(x | y). Their paper writes the same rule with w + 1 in place of w.
The cost. Each sampling step now calls the network twice, once with the label and once with ∅.
3. Explore
Section titled “3. Explore”Guidance and conditioning: edit exercises/stubs/m6_7_guidance.py on your own machine. This task needs PyTorch, which the in-page runner does not have.
pip install torch # CPU build is enough for the tests
mlc check 6.7Then run the lab. Open notebooks/6.7-guidance.ipynb (a GPU helps; a CPU finishes in about 20 minutes) and paste in your 6.7 file. It checks your network against the exact guided flow in 2D, then trains a label-conditioned U-Net on MNIST and generates every digit at w = 0, 1 and 3, measuring how often the samples are the requested digit and how varied they are.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.