🌏 中文版
Video status: recordings require sign-in or course authorization. This guide uses public slides and assignments; numerical examples are site-authored, not a lecture transcript.
Copying a noising equation is not enough to implement diffusion correctly. Assignment 2 connects timestep coefficients, image batches, predictions, and reverse sampling. We calculate a broadcasting example and build a diagnostic order, without supplying complete solutions to the official TODOs. Prerequisites are autograd, Lectures 7–8, and CNN tensor shapes.
The official basis is hw2.zip, whose handout asks you to fill TODOs in diffusion.py and unet.py. test_diffusion.py provides partial validation. The assignment explicitly uses L1 loss between actual and predicted noise, whereas the previous guide introduced the DDPM paper's simplified MSE. Do not replace the assignment objective merely because another formulation is familiar.
Validate environment and input data first
Extract the official archive, install its requirements in an isolated environment, and run python test_diffusion.py. Separate import failures, paths, and unimplemented functions from formula errors. Inspect the actual transforms and model image_size rather than assume raw file dimensions reach the U-Net unchanged.
Earlier notes recorded 36×36 source images and a default model image_size of 32. Resizing or cropping is part of the data flow. Inspect one batch's shape, range, channel order, and train/validation source before treating a picture-shaped tensor as a valid model input.
Calculate a two-example batch
Use [B,C,H,W]=[2,1,1,2]. Clean values are A=[2,0] and B=[1,−1]. Their chosen timestep ᾱ values are 0.64 and 0.81. Fixed noise is A=[1,−1] and B=[0,2]. Each example uses one timestep across all its pixels.
A has signal/noise coefficients 0.8 and 0.6, producing [2.2,−0.6]. B has coefficients 0.9 and √0.19≈0.4359, producing [0.9,−0.0282]. Timesteps have shape [2], but coefficients selected from a lookup table must be reshaped to [2,1,1,1] before broadcasting against the image batch.
Leaving them as [2] aligns them with the final width axis. Because W also equals two, execution may succeed while each pixel receives a different example's timestep coefficient. Batch-one tests and conveniently matching dimensions can hide this error.
Targets must use the same noise
Suppose the model predicts zero at all four positions. Mean L1 is (1+1+0+2)/4=1. Mean MSE would be (1+1+0+4)/4=1.5. Their gradients also differ; at zero L1 error, frameworks conventionally use a zero subgradient.
If noising and loss calculation independently draw ε, the input and target refer to different randomness. Inject fixed noise when testing the relation, then use random draws in training. Merely seeing a changing loss does not validate the intended random process.
Test reverse sampling separately
The official sampler estimates x̂₀ from predicted noise, clamps it to the specified range, and uses posterior mean and variance for a reverse step. Clipping changes direct linear conversion, so test both in-range and out-of-range estimates explicitly.
The final step normally adds no new noise. With zero-based program timesteps, define which mathematical step index zero represents. Mixing the mathematical ᾱ₀=1 sentinel with the first stored noised coefficient creates off-by-one errors. Check earliest/latest indices, heterogeneous batch timesteps, and reverse values with fixed z.
U-Net introduces additional spatial constraints. Downsampling, skips, and upsampling must connect tensors at compatible scales. Shapes are only a minimum check; use the same x with two timesteps to verify that time conditioning is not accidentally ignored.
Keep training and evaluation evidence distinct
First complete a small forward/backward pass and verify finite gradients for intended parameters. Then run a short training smoke test, recording steps, seed, subset, loss definition, and generation settings. A few samples can demonstrate a working pipeline without establishing distribution quality.
FID additionally depends on the reference folder and preprocessing. Earlier notes identified a potential mismatch between the PDF description and starter reference-path construction. Inspect the paths actually used in this run. Test success, training completion, FID calculation, and official grading are separate claims.
Variations with answers
For batch three, channels two, height four, width five, and timesteps [3], the coefficient shape should be [3,1,1,1]. Physically duplicating coefficients into [3,2,4,5] is unnecessary; leaving [3] is incorrect for this layout.
Predicting the exact noise in the earlier example makes L1 zero, but incorrect reverse variance or indexing can still break sampling. Validate the target, mean conversion, and reverse loop independently. The next module applies the same explicit objective, shape, and gradient checks to parameter adaptation.
Previous | Next | Series overview
Course Video Sources
The official recording index is on SCS Panopto. The anonymous folder view is unloaded and requests sign-in; this is an access limitation, not evidence that recordings do not exist. Original audio and subtitles require the appropriate course access.
References
- HW2 official archive
- HW2 recitation
- Coursework
- DDPM
- clean-fid
- CMU 10-423/623/723 Generative AI
- HW2 read-only Overleaf template
- HW2 recitation slides
- schedule
- Lecture 10
- pre-uploaded Kaggle dataset
- Weights & Biases
- practice exam
- Nichol & Dhariwal 2021: Improved Denoising Diffusion Probabilistic Models
- Choi et al. 2020: StarGAN v2