An extension of the DDPM-CIFAR10 model that adds a Denoising Diffusion Implicit Models (DDIM) sampler for fast, deterministic inference. The underlying U-Net is trained identically to the DDPM variant; only the sampling procedure differs.
DDIM (Song et al., 2020) reformulates the reverse diffusion process as a non-Markovian chain, allowing the model to sample in far fewer steps than standard DDPM while maintaining high image quality. The same noise-predicting U-Net trained with DDPM can be used directly with the DDIM sampler without retraining.
Identical U-Net to Diffusion-CIFAR10: ResBlocks with GroupNorm, self-attention at the bottleneck, sinusoidal time embeddings, strided Conv2d downsampling, nearest-neighbour upsampling.
1import torch
2from model import UNet
3from diffusion import GaussianDiffusionSampler
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7model = UNet(T=1000, ch=128, ch_mult=[1,2,2,2], attn=[1], num_res_blocks=2, dropout=0.1)
8model.load_state_dict(torch.load("Checkpoints/ckpt_199.pth", map_location=device))
9model.eval().to(device)
10
11# DDIM sampler — set T to desired number of inference steps
12sampler = GaussianDiffusionSampler(beta_1=1e-4, beta_t=0.02, model=model, T=200).to(device)
13
14with torch.no_grad():
15 x_T = torch.randn(16, 3, 32, 32, device=device)
16 samples = sampler(x_T)