liveBook · Manning

DDIM

As explained in Build a Text-to-Image Generator (from Scratch)

A DDIM scheduler is a configuration component that determines the noise levels and time-step transitions for sampling with DDIM.

A Denoising Diffusion Implicit Model (DDIM) is a noise scheduler for diffusion sampling. Unlike DDPM, it uses a non-Markovian process and can follow a deterministic denoising trajectory, producing images in fewer steps. section 7.1 section 7.1.2

DDIM connects its schedule to the diffusion pipeline in several stages:

  • Forward diffusion gradually adds noise to clean images until the final timestep becomes pure random noise. section 7.2.2
  • Reverse diffusion uses the denoising model to move from noisy inputs toward clean images. section 7.1.2
  • The parameter σt controls random noise in each reverse step; setting σt to zero produces deterministic DDIM sampling. section 7.1.2
  • Fewer sampling steps improve efficiency, with reported speedups of 10 to 50 times over DDPM while retaining high-quality samples. section 7.1.2

Scheduling noise for flower images

Create a DDIMScheduler with 1,000 training timesteps, select training images, and call add_noise at successive steps. Visualizing timesteps 0, 200, 400, 600, 800, and 1,000 shows the progression from clean flowers to pure noise. section 7.2.2

Listing 7.2 Applying forward diffusion to flower images
from utils.ddim_util import DDIMScheduler
noise_scheduler=DDIMScheduler(num_train_timesteps=1000)

imgs=next(iter(train_dataloader))["input"]
imgs=imgs.permute(0,2,3,1).reshape(-1,64,3)    #1

allimgs=[imgs]
for step in [200,400,600,800,1000]:    #2
    timesteps=torch.tensor([step-1]).long()
    noisy_image=noise_scheduler.add_noise(imgs,
         torch.randn(imgs.shape), timesteps)
    allimgs.append(noisy_image)
plt.figure(figsize=(10,8),dpi=80)
for i in range(6):    #3
    plt.subplot(1,6,i+1)
    plt.imshow(torch.clip(allimgs[i],0,1))
    plt.axis('off')
    plt.title(f"t={200*i}",fontsize=16)
plt.tight_layout(w_pad=-0.1)
plt.show()

Inspect the PyTorch implementation that constructs DDIMScheduler, adds noise at selected timesteps, and plots the resulting image sequence. section 7.2.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Defines non-Markovian and deterministic sampling, explains σt, and demonstrates forward noise addition, but omits a full scheduler derivation.
Examples
Demonstrates flower images, six progressively noisier timesteps, a DDIMScheduler instance, and a grid-plotting exercise.
What it assumes
Assumes diffusion models, DDPM sampling, and denoising U-Nets, while introducing DDIM mechanics through implementation.
What you can do after
Operate/configure DDIMScheduler to add noise, visualize diffusion, and support faster deterministic image sampling.
How it connects
Contrasts DDPM, supports denoising U-Net sampling, and connects forward diffusion with attention-based high-resolution image generation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.