DDIM: shorter paths, deterministic maps and finite-step error
去噪扩散隐式模型
Vary the sampling grid and eta with an exact denoiser; see why a single jump loses variance.
ddimCan a denoiser take a shorter route?
A trained denoiser may recognize many noise levels. That does not force a sampler to visit every level in the order used to define the original forward chain. The useful question is which quantities must remain compatible when we change the route.
Denoising Diffusion Implicit Models, by Jiaming Song, Chenlin Meng and Stefano Ermon, constructs a family of sampling processes compatible with a DDPM-style denoising objective. The work was first submitted in October 2020 and published at ICLR 2021; this article reads the October 2022 revision. We focus on the update rule, its randomness and what happens when steps are skipped. Read DDPM first.
Our example has a deliberately revealing outcome: even an exact conditional denoiser loses almost all output variance when asked to make one large jump. Deterministic computation and accurate denoising do not remove discretization error.
Keep the marginal noise level explicit
Let At be the cumulative retained signal power at time t, with A0=1 and At decreasing as t grows. This is the quantity written αt in the DDIM paper; it corresponds to the cumulative product, not the single-step α in our DDPM article.
Different joint distributions over the noisy states can have these same x0-conditioned marginals. Section 3 constructs non-Markovian forward processes and relates their variational objectives to weighted denoising losses. A model that predicts the noise at each level can therefore be used with more than one reverse update construction.
There is a qualification behind “the same training objective.” The paper’s argument about weights leaving each time’s optimum unchanged explicitly considers parameters not shared across t. Positive weights also leave the unrestricted conditional-mean optimum unchanged. A finite shared network trained for a finite time can behave differently under different weights; the result is not a universal guarantee of identical fitted parameters.
Three terms in a skipped update
Given xt and a predicted noise vector, first estimate the clean observation:
For a jump to an earlier level s, choose η between zero and one and set the new-noise variance to:
The update combines a predicted clean component, a direction based on the predicted noise, and fresh independent Gaussian noise z:
Theorem 1 assumes strictly positive transition variances. The paper treats the zero-variance case as a limiting construction; the theorem does not directly cover η=0. Theorem 1 and the Section 4.1 footnote make this distinction.
At η=0 the new-noise term vanishes. The result is deterministic conditional on the initial latent and all other model inputs. The initial latent can still be random, so repeated generation with different latents still produces a distribution. At s=0, As=1 makes both residual-noise coefficients zero and the update returns the clean estimate.
For η=1, the variance matches the x0-conditioned posterior variance associated with the jump’s effective β. The adjacent-step case is the familiar DDPM construction:
This statement is about a specified variance policy. It does not make the update identical to every implementation called DDPM. The author sampling file has a separate ddpm_steps function that clips the clean prediction and uses a β-based variance; its generalized sampler uses the η rule. Our example implements the generalized formula without clipping.
Why an optimal predictor can still collapse variance
Under squared-error training, εθ estimates E[ε|xt,t], not the hidden noise of each individual example. Substituting that expectation into the clean estimate gives E[x0|xt]. For Gaussian data x0∼N(m0,v0), define vt=At v0+1−At. Then:
The variance of that conditional mean across noisy inputs is smaller than the variance of x0. A single jump from the true terminal distribution to time zero gives:
The missing uncertainty is Var(x0|xT). The law of total variance separates those two contributions. When AT is very small, the noisy terminal state reveals little about x0, so its conditional mean changes little across inputs. Calling the denoiser optimal does not turn that mean into a full conditional sample.
Change η and the time grid separately
Save as ddim.py, using Python 3.12 and NumPy 1.26.4. The synthetic data has mean .7 and variance .36. We use At=exp(−5t) for normalized t between zero and one, and supply the analytic Gaussian denoiser at any requested time. There is no training in this program. In particular, it does not reuse the coefficients from the different, 24-step linear-β schedule in the DDPM example.
step implements one jump; sample follows a descending grid with a fixed initial array and a separately seeded transition-noise generator. moments propagates the exact mean and variance of this affine discrete sampler. This provides an independent target for Monte Carlo checks. true starts at the actual noisy data marginal, while standard deliberately substitutes N(0,1).
For S updates and N scalar samples, generation costs O(SN) time with O(N+S) working storage. The analytic moment experiment costs O(S). A neural denoiser would require S model evaluations at its actual cost; the reduced evaluation count alone does not determine image quality or end-to-end latency. The original update and subsequence construction support the method, while our numeric results describe only this synthetic model.
"""Original DDIM skip/eta experiment using an analytic Gaussian denoiser, no training."""
import json
import numpy as np
MU, VAR = .7, .36
def alpha(time):
t = np.asarray(time, float)
if not np.all(np.isfinite(t)) or np.any((t < 0) | (t > 1)):
raise ValueError('Normalized times must be finite in [0,1].')
return np.exp(-5*t)
def epsilon(x, time):
a = alpha(time); x = np.asarray(x, float)
return np.sqrt(1-a)*(x-np.sqrt(a)*MU)/(a*VAR+1-a)
def step(x, time, earlier, eta=0., noise=0.):
if not np.isfinite(eta) or not 0 <= eta <= 1 or not 0 <= earlier < time <= 1:
raise ValueError('Require0<=earlier<time<=1 and0<=eta<=1.')
x, noise = np.asarray(x, float), np.asarray(noise, float)
if x.ndim > 1 or x.size == 0 or x.size > 65536 or not np.all(np.isfinite(x)) or np.max(abs(x)) > 1e4:
raise ValueError('Finite scalar or bounded nonempty vector required.')
if noise.shape not in [(),x.shape] or not np.all(np.isfinite(noise)) or np.max(abs(noise)) > 1e4:
raise ValueError('Noise must be a finite scalar or match x.')
a, previous = alpha(time), alpha(earlier)
predicted_noise = epsilon(x, time)
clean = (x-np.sqrt(1-a)*predicted_noise)/np.sqrt(a)
sigma2 = eta**2*(1-previous)/(1-a)*(1-a/previous)
direction2 = 1-previous-sigma2
if direction2 < -1e-12: raise ValueError('Invalid DDIM direction variance.')
return np.sqrt(previous)*clean+np.sqrt(max(0.,direction2))*predicted_noise+np.sqrt(sigma2)*noise
def grid(steps):
if type(steps) is not int or not 1 <= steps <= 1024: raise ValueError('steps must be in [1,1024].')
return np.linspace(1.,0.,steps+1)
def moments(steps, eta=0., terminal='true'):
times = grid(steps); a = alpha(1.)
if terminal == 'true': mean,var = np.sqrt(a)*MU,a*VAR+1-a
elif terminal == 'standard': mean,var = 0.,1.
else: raise ValueError('Unknown terminal distribution.')
for t,s in zip(times[:-1],times[1:]):
intercept = float(step(0.,t,s,eta)); slope = float(step(1.,t,s,eta))-intercept
noise_scale = float(step(0.,t,s,eta,1.))-intercept
mean,var = slope*mean+intercept,slope*slope*var+noise_scale*noise_scale
return np.array([mean,var])
def sample(initial, steps, eta=0., seed=1):
x = np.asarray(initial,float).copy(); rng = np.random.default_rng(seed); times = grid(steps)
for t,s in zip(times[:-1],times[1:]):
x = step(x,t,s,eta,rng.normal(size=x.shape))
return x
def demo():
a=alpha(1.);z=np.random.default_rng(21).normal(size=8192)
terminal=np.sqrt(a)*MU+np.sqrt(a*VAR+1-a)*z
result={str(n):{'eta0':moments(n,0).tolist(),'eta1':moments(n,1).tolist()} for n in [1,4,16,64,256]}
one=sample(terminal,16,0,1);two=sample(terminal,16,0,2)
random=sample(terminal,16,1,1)
return dict(target=[MU,VAR],steps=result,deterministic_seed_error=float(np.max(abs(one-two))),
deterministic_output_variance=float(one.var()),stochastic_output_variance=float(random.var()),
standard_prior_16=moments(16,0,'standard').tolist(),
one_jump_variance=float(a*VAR*VAR/(a*VAR+1-a)))
if __name__ == '__main__':print(json.dumps(demo(),indent=2))
Predictable randomness and visible step error
With true terminal initialization, one jump produces variance .000877019891752 instead of .36, exactly matching the conditional-mean calculation. Both η=0 and η=1 give that same final jump because its endpoint variance is zero.
For η=0, using 4, 16, 64 and 256 steps gives variances .0435200968, .1649397438, .2757880477 and .3306348002. The mean stays .7 to numerical precision. Smaller steps improve the variance in this example, but even the 256-step result is not exact. This is evidence about a particular schedule and denoiser, not a universal monotonic-quality theorem.
Fix the 8,192 initial points drawn with seed 21. At η=0, changing the transition-noise seed gives bitwise identical outputs, while output variance remains positive, about .16269436 for 16 steps. At η=1, the 16-step sample variance is about .14938447; the analytic discrete value is .14993142. Separately, replacing the true terminal marginal with a standard Gaussian shifts the deterministic 16-step mean to .67661362. Step error, Monte Carlo error and terminal-prior mismatch are different effects.
Fewer evaluations change an approximation
The reverse update uses a denoising estimate in a new transition rule. A large jump can discard conditional uncertainty, and prediction errors can accumulate along the resulting trajectory. Neither η=0 nor η=1 is a general guarantee of better fidelity. The appropriate grid and stochasticity depend on the model and the quantity being evaluated.
This program does not test image detail, semantic interpolation, guidance, a learned denoiser or an adaptive ODE solver. The DDIM paper’s speed and image-quality claims require its experimental conditions; we do not substitute these scalar results for them. Continuous-time relationships belong with score SDEs, where the differential equation and its numerical solver must also be distinguished.
Which randomness did you remove?
- Notation. In this article, is At one minus the current βt? Answer: No. At is cumulative signal retention. In a discrete DDPM schedule it is the product of the single-step factors 1−β. Mixing these conventions changes every square root in the update.
- Randomness. With η=0, must two runs with different initial latents match? Answer: No. The map is deterministic given its initial latent; changing that input generally changes its output. It is only the fresh noise inserted along the path that vanishes.
- Hand calculation. Put m0=.7, v0=.36 and AT=exp(−5). What variance does one jump produce with the optimal predictor? Answer: AT·.36²/(AT·.36+1−AT)≈.00087702. It is the variance of a conditional mean, not the target variance .36.
- Method choice. Is η=1 enough to reproduce an implementation that also clips x̂0 and uses β variance? Answer: No. Check the time grid, cumulative-noise convention, mean parameterization, variance and clipping separately. η=1 in the generalized formula specifies the posterior-variance version for that jump.
Match the paper’s family to the implementation
Read Section 3’s conditions and Section 4’s update/subsequence discussion, then compare generalized_steps and ddpm_steps in the fixed author code. DDPM supplies the original noise-prediction construction. Our reading does not claim a complete verification of DDIM’s appendix or its later ODE proof, and this program does not reproduce its image experiments.
Make a prediction, then check
With eta zero, do different initial latents necessarily give the same output?
Learning objectives
- Distinguish cumulative noise from single-step noise.
- Calculate a skipped generalized update.
- Identify which randomness eta removes.
- Measure finite-step error with analytic moments.
Prerequisites & connections
Explore related knowledge →References
- Denoising Diffusion Implicit Models (v4): generalized sampling
Jiaming Song; Chenlin Meng; Stefano Ermon · 2022 - DDIM generalized_steps and ddpm_steps ate8df66c
Jiaming Song and DDIM contributors · 2024 - Denoising Diffusion Probabilistic Models (v2): chain, variance and loss
Jonathan Ho; Ajay Jain; Pieter Abbeel · 2020
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-20 · Single AI author checked DDIM v4 selected theorem1 conditions, update/subsequence and fixed author sampler. Eight paired equations/four explained exercises; original analytic Gaussian denoiser, skipped transitions, eta, one-jump conditional-mean variance and finite-step/prior effects. Positive-variance theorem and eta-zero limit separated; no neural training or image reproduction.
- Single AI author checked DDIM v4 selected theorem1 conditions, update/subsequence and fixed author sampler. Eight paired equations/four explained exercises; original analytic Gaussian denoiser, skipped transitions, eta, one-jump conditional-mean variance and finite-step/prior effects. Positive-variance theorem and eta-zero limit separated; no neural training or image reproduction.
- Four computed SVG variants per topic. Fifteen numeric/geometry tests and24 responsive cases passed; eight final Chinese-mobile/English-desktop screenshots actually inspected. Axis and evidence corrections retained. Full article-page acceptance recorded separately.
Source locations checked:
- Denoising Diffusion Implicit Models (v4): generalized sampling · Read Section3 Theorem1 and unshared-time parameter qualification,4.1 Equation12 and4.2 subsequences; inspected PDF page5. First2020-10-06; v4 dated2022-10-05, ICLR2021 work. No full appendix, later ODE proof or image benchmark replication.
- DDIM generalized_steps and ddpm_steps ate8df66c · Read lines1–64: cumulative alpha, -1 endpoint, eta-based generalized update versus clipped x0/beta variance in ddpm_steps. Commit2024-07-26; full root MIT read. Reference only, no copied code or execution.
- Denoising Diffusion Probabilistic Models (v2): chain, variance and loss · Read selected Sections2/3, Equations5–14, Algorithms1–2, decoder and final noiseless display; visually inspected PDF pages3–4. First2020-06-19; v2 dated2020-12-16, NeurIPS2020. No image benchmark or complete appendix review.
Related topics