Code at: https://github.com/yashwantherukulla/DDPM-From-Scratch
The notes cover the following:
-
Linear Noise Scheduler — A schedule that linearly interpolates the noise variance β from a small value at timestep 1 to a larger value at timestep T, controlling how much Gaussian noise is added at each step of the forward process.
-
Forward Process — The fixed Markov chain that gradually corrupts a clean image by adding small amounts of Gaussian noise over T timesteps, with the key insight that the noisy image at any arbitrary timestep can be sampled in closed form using the cumulative product ᾱ.
-
Reverse Process — A learned Markov chain that runs backwards in time, with a neural network predicting the parameters of the denoising distribution at each step so that starting from pure Gaussian noise, a clean image can be recovered.
-
Time Embedding Block — A module that encodes the current timestep t as a sinusoidal positional embedding (similar to transformers) and projects it through a small MLP, injecting time-awareness into every residual block of the U-Net.
-
U-Net Model — The backbone denoiser architecture comprising an encoder path of downsampling residual blocks and a decoder path of upsampling residual blocks with skip connections, augmented with self-attention layers and time embeddings to predict the noise ε at each timestep.
-
Loss Derivation — Starting from the variational lower bound on the log-likelihood, the ELBO is decomposed into KL-divergence terms between Gaussians; after simplification, the training objective reduces to a simple mean-squared error between the true noise $ε$ and the model’s prediction $ε_θ$.
-
Training — At each iteration, a random image and a random timestep are sampled, noise is drawn and added via the closed-form forward process, and the U-Net is trained to predict that noise by minimising the simplified MSE loss.
-
Sampling / Inference — Starting from $x_T \sim N(0, I)$, the model iteratively denoises by predicting $ε_θ$ at each step and computing $x_{t-1}$ using the reverse process mean, optionally adding a small amount of noise (except at the final step) until a clean image $x_0$ is obtained.