Quiz 2

Denoising Diffusion Implicit Models: Accelerated Sampling

3340 words
17 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Denoising Diffusion Implicit Models: Accelerated Sampling ## 🎯 Learning Objectives - Understand the limitations of DDPM sampling speed and how DDIM addresses them - Derive the non-Markovian forward process that makes DDIM work - Implement accelerated sampling with arbitrary step sizes - Use DDIM for deterministic...

Denoising Diffusion Implicit Models: Accelerated Sampling

🎯 Learning Objectives

  • Understand the limitations of DDPM sampling speed and how DDIM addresses them
  • Derive the non-Markovian forward process that makes DDIM work
  • Implement accelerated sampling with arbitrary step sizes
  • Use DDIM for deterministic encoding (inversion) of real images
  • Compare DDIM's latent space properties with DDPM

📋 Prerequisites

  • Diffusion Models (DDPM) (Week 4): Forward/reverse processes, noise scheduling
  • Probability basics: Conditional distributions, Markov chains
  • Linear algebra: Matrix operations, eigendecomposition

1. 📖 Core Content

1.1 Intuition: Why DDIM?

DDPM generates high-quality images but requires 1000 sequential denoising steps to produce a single sample. Each step runs the full U-Net. This makes sampling:
  • Slow: A single 1024×1024 image can take 10-60 seconds on a high-end GPU
  • Impractical for real-time applications: Chat-based image generation, interactive editing
  • Energy inefficient: 1000 forward passes through a large neural network DDIM asks: Do we really need all 1000 steps? Can we skip most of them? The key insight: DDPM's forward process is Markovian (each step depends only on the previous step). But the reverse process doesn't need to be Markovian too! By designing a non-Markovian forward process that has the same marginal distributions as DDPM, we can use a shortened reverse sampling path — e.g., 50 steps instead of 1000. Even more surprisingly, DDIM makes the reverse process deterministic (no random noise during sampling), which means:
  1. The mapping from noise zz to image x0x_0 is one-to-one (injective)
  2. We can invert the process: encode a real image back into its latent noise vector
  3. Latent space becomes smooth for interpolation

1.2 Review: DDPM's Markovian Forward Process

In DDPM, the forward process adds Gaussian noise step by step:
q(xtxt1)=N(xt;1βtxt1,βtI)q(x_t | x_{t-1}) = \mathcal{N}(x_t; \sqrt{1-\beta_t} x_{t-1}, \beta_t I)
Because it's Markovian, we can also write the marginal distribution at any timestep directly:
q(xtx0)=N(xt;αˉtx0,(1αˉt)I)q(x_t | x_0) = \mathcal{N}(x_t; \sqrt{\bar{\alpha}_t} x_0, (1-\bar{\alpha}_t)I)
where αˉt=i=1t(1βi)\bar{\alpha}_t = \prod_{i=1}^t (1-\beta_i). The reverse process in DDPM is also Markovian:
pθ(xt1xt)=N(xt1;μθ(xt,t),σt2I)p_\theta(x_{t-1} | x_t) = \mathcal{N}(x_{t-1}; \mu_\theta(x_t, t), \sigma_t^2 I)
And sampling requires iterating through every timestep T,T1,...,1T, T-1, ..., 1.

1.3 The DDIM Non-Markovian Forward Process

DDIM defines a different forward process that has the same marginal distributions as DDPM but is no longer Markovian. Key idea: Instead of q(xtxt1)q(x_t | x_{t-1}), define q(xt1xt,x0)q(x_{t-1} | x_t, x_0) directly. From DDPM's joint distribution, we can derive (using Bayes rule) the reverse conditional distribution given x0x_0:
q(xt1xt,x0)=N(xt1;μ~t(xt,x0),β~tI)q(x_{t-1} | x_t, x_0) = \mathcal{N}\left(x_{t-1}; \tilde{\mu}_t(x_t, x_0), \tilde{\beta}_t I\right)
where:
μ~t(xt,x0)=αˉt1βt1αˉtx0+1βt(1αˉt1)1αˉtxt\tilde{\mu}_t(x_t, x_0) = \frac{\sqrt{\bar{\alpha}_{t-1}} \beta_t}{1-\bar{\alpha}_t} x_0 + \frac{\sqrt{1-\beta_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t} x_t β~t=1αˉt11αˉtβt\tilde{\beta}_t = \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t} \beta_t
(These come from the standard DDPM derivation — we derived them in Week 4.) DDIM's innovation: Generalize this distribution by introducing a parameter σ0\sigma \geq 0 that controls the stochasticity of the reverse step:
qσ(xt1xt,x0)=N(xt1;αˉt1x0+1αˉt1σt2xtαˉtx01αˉt,σt2I)q_\sigma(x_{t-1} | x_t, x_0) = \mathcal{N}\left(x_{t-1}; \sqrt{\bar{\alpha}_{t-1}} x_0 + \sqrt{1-\bar{\alpha}_{t-1} - \sigma_t^2} \cdot \frac{x_t - \sqrt{\bar{\alpha}_t} x_0}{\sqrt{1-\bar{\alpha}_t}}, \sigma_t^2 I\right)
When σt2=β~t\sigma_t^2 = \tilde{\beta}_t, this reduces to DDPM. When σt=0\sigma_t = 0, this becomes DDIM — a fully deterministic reverse process.

1.4 The DDIM Sampling Equation

For DDIM (σt=0\sigma_t = 0), the reverse step simplifies to:
xt1=αˉt1(xt1αˉtϵθ(t)(xt)αˉt)predicted x^0+1αˉt1ϵθ(t)(xt)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} \cdot \underbrace{\left(\frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta^{(t)}(x_t)}{\sqrt{\bar{\alpha}_t}}\right)}_{\text{predicted } \hat{x}_0} + \sqrt{1-\bar{\alpha}_{t-1}} \cdot \epsilon_\theta^{(t)}(x_t)
Wait, that's not fully simplified. Let me derive it properly. DDIM reverse step derivation: We have the predicted x0x_0 from the current xtx_t and predicted noise ϵθ\epsilon_\theta:
x^0=xt1αˉtϵθ(xt,t)αˉt\hat{x}_0 = \frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}}
The DDIM sampling equation (Song et al., 2021) is:
xt1=αˉt1x^0+1αˉt1ϵθ(xt,t)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} \hat{x}_0 + \sqrt{1-\bar{\alpha}_{t-1}} \epsilon_\theta(x_t, t)
Or equivalently:
xt1=αˉt1xt1αˉtϵθ(xt,t)αˉt+1αˉt1ϵθ(xt,t)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} \cdot \frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}} + \sqrt{1-\bar{\alpha}_{t-1}} \epsilon_\theta(x_t, t)
Notice: There is NO noise term. The process is deterministic given xtx_t and ϵθ\epsilon_\theta.

1.5 Accelerated Sampling: Skipping Steps

For DDPM, we must sample xT,xT1,...,x1,x0x_T, x_{T-1}, ..., x_1, x_0 — all TT steps. For DDIM, we can sample a subsequence {xτS,xτS1,...,xτ1,x0}\{x_{\tau_S}, x_{\tau_{S-1}}, ..., x_{\tau_1}, x_0\} where STS \ll T and τ\tau is an increasing subsequence of [1,...,T][1, ..., T]. For example, with T=1000T = 1000 and S=50S = 50, we use steps τ=[1,20,40,...,980,1000]\tau = [1, 20, 40, ..., 980, 1000] — only 50 steps. The sampling equation for a subsequence step xτi1x_{\tau_{i-1}} from xτix_{\tau_i}:
xτi1=αˉτi1xτi1αˉτiϵθ(xτi,τi)αˉτi+1αˉτi1ϵθ(xτi,τi)x_{\tau_{i-1}} = \sqrt{\bar{\alpha}_{\tau_{i-1}}} \cdot \frac{x_{\tau_i} - \sqrt{1-\bar{\alpha}_{\tau_i}} \epsilon_\theta(x_{\tau_i}, \tau_i)}{\sqrt{\bar{\alpha}_{\tau_i}}} + \sqrt{1-\bar{\alpha}_{\tau_{i-1}}} \epsilon_\theta(x_{\tau_i}, \tau_i)
The model ϵθ\epsilon_\theta was trained on the original 1000-step schedule, but we can evaluate it at any timestep τi\tau_i because the noise level αˉτi\bar{\alpha}_{\tau_i} is well-defined.

Worked Example 1: DDIM Sampling with 10 Steps

Suppose we have a trained DDPM with T=1000T=1000 and αˉt=cos2(tTπ2)\bar{\alpha}_t = \cos^2\left(\frac{t}{T} \cdot \frac{\pi}{2}\right) (a cosine schedule). We want to sample using only 10 DDIM steps. Step 1: Choose the subsequence. A common choice is uniformly spaced:
τi=iSTfor i=1,...,S\tau_i = \left\lfloor \frac{i}{S} \cdot T \right\rfloor \quad \text{for } i = 1, ..., S
With S=10S=10, T=1000T=1000: τ=[100,200,300,...,1000]\tau = [100, 200, 300, ..., 1000]. Step 2: Start with pure noise x1000N(0,I)x_{1000} \sim \mathcal{N}(0, I). Step 3: For i=10,9,...,1i = 10, 9, ..., 1 (i.e., t=1000,900,...,100t = 1000, 900, ..., 100):
xt100=αˉt100xt1αˉtϵθ(xt,t)αˉt+1αˉt100ϵθ(xt,t)x_{t-100} = \sqrt{\bar{\alpha}_{t-100}} \cdot \frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}} + \sqrt{1-\bar{\alpha}_{t-100}} \epsilon_\theta(x_t, t)
Step 4: After 10 steps, x0x_0 is the generated image.

Worked Example 2: Comparing DDPM (1000 steps) vs DDIM (50 steps) Quality

Let's trace the reconstruction error at each step. For a given x0x_0, the forward process in DDPM gives:
xt=αˉtx0+1αˉtϵ,ϵN(0,I)x_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1-\bar{\alpha}_t} \epsilon, \quad \epsilon \sim \mathcal{N}(0, I)
In DDPM reverse, at step tt we predict ϵθ(xt,t)\epsilon_\theta(x_t, t) and sample:
xt1=1αt(xtβt1αˉtϵθ(xt,t))+σtz,zN(0,I)x_{t-1} = \frac{1}{\sqrt{\alpha_t}} \left(x_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}} \epsilon_\theta(x_t, t)\right) + \sigma_t z, \quad z \sim \mathcal{N}(0, I)
The stochastic term σtz\sigma_t z means even with a perfect noise predictor (ϵθ=ϵ\epsilon_\theta = \epsilon), DDPM's reverse is not purely deterministic — the noise zz accumulates. In DDIM with σt=0\sigma_t = 0, the reverse step has no noise. If ϵθ\epsilon_\theta perfectly predicts the noise, then:
xt1=αˉt1x0+1αˉt1ϵx_{t-1} = \sqrt{\bar{\alpha}_{t-1}} x_0 + \sqrt{1-\bar{\alpha}_{t-1}} \epsilon
which is exactly the forward process equation at timestep t1t-1. This means DDIM perfectly inverts the forward process in a deterministic manner.

1.6 Deterministic Inversion (Encoding)

Because DDIM is deterministic, we can invert the sampling process. Starting from a real image x0x_0, we can find the latent noise vector xTx_T that would generate it. Forward DDIM inversion:
xt+1=αˉt+1xt1αˉtϵθ(xt,t)αˉt+1αˉt+1ϵθ(xt,t)x_{t+1} = \sqrt{\bar{\alpha}_{t+1}} \cdot \frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}} + \sqrt{1-\bar{\alpha}_{t+1}} \epsilon_\theta(x_t, t)
This is the reverse of the sampling equation. We start from x0x_0 and iterate t=0,1,...,T1t = 0, 1, ..., T-1 to obtain xTx_T. Important caveat: This inversion is approximate because ϵθ\epsilon_\theta isn't perfect. However, it works well enough for real applications.

Why Inversion Matters

  1. Image editing: Encode an image, edit the latent, decode back
  2. Style mixing: Combine latents from different images
  3. Interpolation: Smoothly morph between two images by interpolating their latents

1.7 DDIM vs DDPM: Comparison

PropertyDDPMDDIM
Forward processMarkovianNon-Markovian
Reverse processStochasticDeterministic ( σ=0\sigma=0 )
Sampling steps requiredAll TT (e.g., 1000)Any STS \ll T (e.g., 10-100)
Sample quality at few stepsPoorGood
Sample quality at full stepsExcellentComparable (slightly worse)
Deterministic encodingNo (stochastic)Yes (invertible)
Latent space structureNon-smoothSmooth for interpolation
Training changesNone (uses DDPM training)None (uses DDPM training)

1.8 Edge Cases & Gotchas

  • Very few steps (1-5): DDIM quality degrades significantly. At 1 step, it just denoises once but doesn't resolve details well.
  • Optimal step count: Empirically, 20-50 DDIM steps give comparable quality to 1000 DDPM steps for most datasets.
  • Noise scheduling matters: The original schedule (linear, cosine, sigmoid) affects DDIM performance. Cosine schedules generally work better with DDIM.
  • Deterministic inversion accumulates error: Long inversion chains (e.g., 1000 steps) can drift from the true path.
  • CFG (Classifier-Free Guidance) interaction: DDIM's determinism breaks with CFG scaling > 1, but accelerated sampling still works.

1.9 Why This Matters

DDIM is used in virtually every modern diffusion-based system:
  • Stable Diffusion uses DDIM schedulers for fast sampling (typically 20-50 steps)
  • Image-to-image translation relies on DDIM inversion
  • Latent space manipulation (e.g., finding directions for specific attributes) works because DDIM provides a smooth latent space
  • Video generation benefits from DDIM's consistency across frames when using shared noise

2. 📐 Key Formulas / Concepts

ConceptFormulaDescription
DDIM reverse stepxt1=αˉt1x^0+1αˉt1ϵθ(xt,t)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} \hat{x}_0 + \sqrt{1-\bar{\alpha}_{t-1}} \epsilon_\theta(x_t, t)Deterministic denoising
Predicted x0x_0x^0=xt1αˉtϵθ(xt,t)αˉt\hat{x}_0 = \frac{x_t - \sqrt{1-\bar{\alpha}_t} \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}}Denoised estimate from current step
DDIM general$q_\sigma(x_{t-1}\x_t,x_0)withwith\sigma \geq 0$
Accelerated scheduleτ=subsequence of [1,...,T]\tau = \text{subsequence of } [1,...,T]Sample only STS \ll T steps
DDIM inversionxt+1=αˉt+1x^0+1αˉt+1ϵθ(xt,t)x_{t+1} = \sqrt{\bar{\alpha}_{t+1}} \hat{x}_0 + \sqrt{1-\bar{\alpha}_{t+1}} \epsilon_\theta(x_t, t)Encoding real images to latent

3. ⚠️ Common Pitfalls

Pitfall 1: Using DDPM Training but DDIM Sampling Without Adjusting the Noise Schedule

Mistake: Training a model with a specific noise schedule (e.g., linear βt\beta_t) and then using DDIM with a different schedule without re-normalizing. Why: DDIM assumes the noise schedule αˉt\bar{\alpha}_t matches what the model was trained on. Correct approach: DDIM sampling uses the noise predictor ϵθ\epsilon_\theta trained with DDPM's schedule. You don't change the schedule — you just skip intermediate timesteps during sampling. The model was trained on all timesteps, so evaluating it at a subset works.

Pitfall 2: Expecting DDIM to Replace All DDPM Sampling

Mistake: Assuming DDIM is strictly better and should always be used. Why: At full step count (1000 steps), DDPM often produces slightly higher quality samples because the stochasticity helps correct accumulation errors. Correct approach: Use DDIM for speed (10-50 steps), use DDPM when quality is paramount and speed doesn't matter.

Pitfall 3: Assuming DDIM Inversion Is Perfect

Mistake: Encoding an image with DDIM inversion and expecting to reconstruct it exactly. Why: The inversion relies on the model's ϵθ\epsilon_\theta being the optimal denoiser at every step, which it isn't. Small errors accumulate. Correct approach: Use the inverted latent as a starting point, accept minor reconstruction artifacts, and consider regularizing the inversion (e.g., adding noise to improve reconstruction).

4. 📝 Practice Questions

Q1: If DDPM requires 1000 steps and DDIM achieves comparable quality with 50 steps, what's the speedup factor?
The speedup appears to be 1000/50=20×1000/50 = 20\times in terms of neural network evaluations. However, DDIM's per-step computation is identical to DDPM's (both evaluate ϵθ\epsilon_\theta once per step), so the actual speedup is indeed 20×20\times.
In practice, the speedup may be slightly less due to overhead (data transfers between CPU/GPU), but it's approximately 20×20\times faster. Q2: Show that when σt=β~t\sigma_t = \sqrt{\tilde{\beta}_t}, the DDIM general process reduces to DDPM.
The general DDIM reverse distribution is:
qσ(xt1xt,x0)=N(xt1;αˉt1x0+1αˉt1σt2xtαˉtx01αˉt,σt2I)q_\sigma(x_{t-1} | x_t, x_0) = \mathcal{N}\left(x_{t-1}; \sqrt{\bar{\alpha}_{t-1}} x_0 + \sqrt{1-\bar{\alpha}_{t-1} - \sigma_t^2} \cdot \frac{x_t - \sqrt{\bar{\alpha}_t} x_0}{\sqrt{1-\bar{\alpha}_t}}, \sigma_t^2 I\right)
When σt2=β~t=1αˉt11αˉtβt\sigma_t^2 = \tilde{\beta}_t = \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t} \beta_t:
The mean becomes:
μ=αˉt1x0+1αˉt11αˉt11αˉtβtxtαˉtx01αˉt\mu = \sqrt{\bar{\alpha}_{t-1}} x_0 + \sqrt{1-\bar{\alpha}_{t-1} - \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t} \beta_t} \cdot \frac{x_t - \sqrt{\bar{\alpha}_t} x_0}{\sqrt{1-\bar{\alpha}_t}}
Using βt=1αt=1αˉtαˉt1\beta_t = 1 - \alpha_t = 1 - \frac{\bar{\alpha}_t}{\bar{\alpha}_{t-1}}:
After simplification (shown in DDPM derivation), this becomes:
μ~t(xt,x0)=αˉt1βt1αˉtx0+αt(1αˉt1)1αˉtxt\tilde{\mu}_t(x_t, x_0) = \frac{\sqrt{\bar{\alpha}_{t-1}} \beta_t}{1-\bar{\alpha}_t} x_0 + \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t} x_t
which is exactly the DDPM posterior mean. And the variance σt2I=β~tI\sigma_t^2 I = \tilde{\beta}_t I is DDPM's posterior variance. Q3: For DDIM, if you start from the same noise vector xTx_T and run sampling twice, do you get the same image?
Yes — DDIM is deterministic. Given the same xTx_T and the same trained model ϵθ\epsilon_\theta, the sequence of xT1,xT2,...,x0x_{T-1}, x_{T-2}, ..., x_0 is fully determined. There's no stochastic term in the reverse step.
This is fundamentally different from DDPM, where each sample path has random noise injections and would produce different images from the same starting xTx_T.
This determinism is what enables DDIM inversion and interpolation applications. Q4: You want to generate 16 images for a storyboard. You have a batch of 16 noise vectors. With DDPM you need 16 × 1000 = 16000 model evaluations. How many with DDIM using 50 steps?
16 × 50 = 800 model evaluations. That's a 20× reduction.
However, note that modern implementations process the entire batch in parallel (batch size = 16), so it's actually 50 batch evaluations vs 1000 batch evaluations. The wall-clock speedup is still approximately 20×. Q5: Why can't DDPM be used for deterministic image encoding?
DDPM's reverse process includes a stochastic noise term at each step:
xt1=1αt(xtβt1αˉtϵθ(xt,t))+σtzx_{t-1} = \frac{1}{\sqrt{\alpha_t}} \left(x_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}} \epsilon_\theta(x_t, t)\right) + \sigma_t z
Even if we know every ϵθ(xt,t)\epsilon_\theta(x_t, t) exactly, the random zN(0,I)z \sim \mathcal{N}(0, I) at each step means:
  1. Starting from the same x0x_0, the forward process gives a distribution over xTx_T (not a unique xTx_T)
  2. Starting from xTx_T, the reverse gives a distribution over x0x_0
There's no deterministic mapping between x0x_0 and xTx_T in either direction. DDIM removes the stochasticity, creating a bijection. Q6: For DDIM with T=1000T=1000 and S=20S=20, propose a sampling schedule τ\tau and explain why you chose it.
A common choice is:
τi=i2S2Tfor i=1,...,S\tau_i = \left\lfloor \frac{i^2}{S^2} \cdot T \right\rfloor \quad \text{for } i = 1, ..., S
This is a quadratic schedule (compared to uniform). The reasoning:
  • Early steps (high noise, near TT): Larger changes happen, so we want more steps when noise is high
  • Late steps (low noise, near 0): Finer details are adjusted, but changes are smaller, so we can take larger jumps
With S=20S=20, the schedule might be: τ=[1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210,231,253,276,300,325,351,378,406,435,465,496,528,561,595,630,666,703,741,780,820,861,903,946,990,1000]\tau = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990, 1000]
Wait, that's more than 20. Let me adjust: the quadratic spacing places more steps at the end.
Actually, a simpler and commonly used approach is linear spacing:
τi=iST for i=1,...,S\tau_i = \left\lfloor \frac{i}{S} \cdot T \right\rfloor \text{ for } i = 1, ..., S
With S=20S=20, T=1000T=1000: τ=[50,100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000]\tau = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000].
This is simple and works well in practice. Q7: Explain the relationship between DDIM and neural ODEs.
DDIM's deterministic reverse process can be viewed as an Euler discretization of a neural ordinary differential equation (ODE).
In the continuous-time limit (as the number of steps TT \to \infty), DDIM's iterative equation becomes:
dxdt=fθ(x,t)xlogpt(x)\frac{dx}{dt} = f_\theta(x, t) \cdot \nabla_x \log p_t(x)
where fθf_\theta is derived from the noise prediction network.
This connection is important because:
  1. It justifies using ODE solvers (RK45, DOPRI) for even faster sampling
  2. It enables likelihood computation via the probability flow ODE
  3. It connects diffusion models to score-based generative modeling and normalizing flows
The DDIM ODE perspective is explored further in the Score-Based Generative Modeling literature (Song et al., 2021). Q8: A student claims "DDIM is just DDPM with fewer training steps." Is this correct? Why or why not?
Not correct. DDIM and DDPM have different claims:
  • DDPM training: Trains ϵθ\epsilon_\theta on TT timesteps with a Markovian forward process
  • DDIM sampling: Uses the same trained model ϵθ\epsilon_\theta but with a different (non-Markovian) reverse process
DDIM does not change training at all. It's purely a sampling-time modification. The model is still trained with the DDPM objective:
L=Et,x0,ϵ[ϵϵθ(xt,t)2]\mathcal{L} = \mathbb{E}_{t, x_0, \epsilon} \left[ \|\epsilon - \epsilon_\theta(x_t, t)\|^2 \right]
"Fewer training steps" refers to something different (training the model for fewer iterations), which would make the model worse regardless of the sampling method. Q9: You have a real image x0x_0 and you run DDIM inversion to get xTx_T. Then you run DDIM sampling from xTx_T back to x0x_0'. Under what conditions would x0=x0x_0 = x_0'?
Perfect reconstruction (x0=x0x_0 = x_0') would require:
  1. Perfect denoiser: ϵθ(xt,t)=ϵ\epsilon_\theta(x_t, t) = \epsilon for all tt, where ϵ\epsilon is the actual noise added at step tt
  2. Consistent inversion path: The inversion path from x0x_0 to xTx_T must use the same steps as the generation path from xTx_T to x0x_0
  3. No numerical error: Floating-point precision doesn't cause drift
In practice, none of these hold perfectly:
  • ϵθ\epsilon_\theta is an imperfect estimator
  • There's discretization error from the finite step count
  • Floating-point errors accumulate
However, DDIM reconstruction is remarkably good — with 1000 steps, pixel-wise reconstruction error is typically < 5% for natural images, and with 10000 steps it's nearly perfect (for models that can handle the extended schedule). Q10: Design an experiment to verify DDIM's latent space smoothness.
Experiment: Image Interpolation in DDIM Latent Space
Step 1: Take two real images x0(A)x_0^{(A)} and x0(B)x_0^{(B)}.
Step 2: Encode both to latents xT(A)x_T^{(A)} and xT(B)x_T^{(B)} using DDIM inversion.
Step 3: For α\alpha in {0,0.1,0.2,...,1.0}\{0, 0.1, 0.2, ..., 1.0\}, compute interpolated latent:
xT(α)=αxT(A)+(1α)xT(B)x_T^{(\alpha)} = \alpha \cdot x_T^{(A)} + (1-\alpha) \cdot x_T^{(B)}
Step 4: Decode each xT(α)x_T^{(\alpha)} with DDIM sampling to get x0(α)x_0^{(\alpha)}.
Expected result: For α=0\alpha = 0, x0(0)x0(B)x_0^{(0)} \approx x_0^{(B)}. For α=1\alpha = 1, x0(1)x0(A)x_0^{(1)} \approx x_0^{(A)}. For intermediate α\alpha, x0(α)x_0^{(\alpha)} should be a smooth semantic blend — e.g., if AA is a photo of a cat and BB is a photo of a dog, intermediate values morph continuously between cat and dog.
This would not work with DDPM latents because the stochastic reverse process destroys the linear interpolation structure. Q11: With DDIM, explain why using 1 sampling step (S=1S=1) gives a poor result.
With S=1S=1, τ=[1000]\tau = [1000], so we jump directly from t=1000t=1000 to t=0t=0:
x0=αˉ0xT1αˉTϵθ(xT,T)αˉT+1αˉ0ϵθ(xT,T)x_0 = \sqrt{\bar{\alpha}_0} \cdot \frac{x_T - \sqrt{1-\bar{\alpha}_T} \epsilon_\theta(x_T, T)}{\sqrt{\bar{\alpha}_T}} + \sqrt{1-\bar{\alpha}_0} \epsilon_\theta(x_T, T)
Since αˉ0=1\bar{\alpha}_0 = 1 and αˉT0\bar{\alpha}_T \approx 0:
x01xT1ϵθ(xT,T)0+0ϵθ(xT,T)x_0 \approx 1 \cdot \frac{x_T - 1 \cdot \epsilon_\theta(x_T, T)}{0} + 0 \cdot \epsilon_\theta(x_T, T)
This is problematic because αˉT0\sqrt{\bar{\alpha}_T} \approx 0 causes division by near-zero. In practice, implementations clamp αˉt\bar{\alpha}_t to avoid this, but the single-step reconstruction is just x^0=xTαˉT\hat{x}_0 = \frac{x_T}{\sqrt{\bar{\alpha}_T}} \approx a scaled noise vector, which contains no meaningful structure.
A single denoising step can only remove a fixed amount of noise — it can't separate structure from noise in one shot. Multiple steps are needed for the iterative refinement that diffusion models rely on. Q12: Suppose you want to use DDIM for video generation where temporal consistency is crucial. How would DDIM's properties help?
For video generation, we want consecutive frames to be consistent (no flickering). DDIM helps because:
  1. Shared noise structure: Generate a base latent xTx_T for the first frame, then for subsequent frames, use small perturbations of xTx_T. Since DDIM deterministically maps latent → image, small latent changes → small image changes.
  2. Interpolation between frames: Generate latents for keyframes, then linearly interpolate intermediate latents. DDIM's smooth latent space ensures smooth visual transitions.
  3. Consistent inversion: If editing a video, invert each frame independently with DDIM, edit the latents consistently, and decode. The edits will be temporally coherent.
This is why most diffusion-based video models (e.g., Stable Video Diffusion) build on DDIM-like schedulers.

5. 🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.