alanjiach@gmail.com

← all writing

Sampling, conditioning, and evaluation

study notesdiffusion

Part of the generative visual computing notes.

Sampling cost

The denoising network usually accounts for much of the generation cost. Count network evaluations as well as integration steps. A method that uses two evaluations per step may be more expensive than another method with more steps.

DDIM starts from an estimate of the clean sample:

x^0=xt−1−αˉtϵθ(xt,t)αˉt.\hat x_0=\frac{x_t-\sqrt{1-\bar\alpha_t}\epsilon_\theta(x_t,t)}{\sqrt{\bar\alpha_t}}.

For a deterministic update to an earlier time ss, one form is

xs=αˉsx^0+1−αˉsϵθ(xt,t).x_s=\sqrt{\bar\alpha_s}\hat x_0+\sqrt{1-\bar\alpha_s}\epsilon_\theta(x_t,t).

The same denoiser can be used with different time grids. Fewer evaluations reduce cost but can increase numerical error. Deterministic sampling still produces varied outputs when starting seeds vary.

In high dimensions, averaging Gaussian seeds changes their distribution. If two independent standard-normal vectors are averaged, the covariance becomes I/2I/2. Their average lies closer to the origin on average and is not another standard-normal draw.

Flow matching

Use τ=0\tau=0 for noise and τ=1\tau=1 for data. A straight conditional path is

xτ=(1−τ)z+τx,u=x−z.x_\tau=(1-\tau)z+\tau x,\qquad u=x-z.

Flow matching regresses a velocity field on the known conditional velocity. Squared error selects v∗(y,τ)=E[u∣xτ=y]v^*(y,\tau)=\mathbb E[u\mid x_\tau=y]. Individual paths can be straight while the learned marginal field produces curved trajectories. The pairing of noise and data affects the conditional training problem.

Distillation takes a different approach to reducing cost. It trains a student to approximate a longer teacher computation. It requires training work rather than merely changing the inference-time grid.

Conditioning and guidance

Conditional training supplies a label, text description, or other observation to the denoiser. Classifier guidance uses

∇xlog⁡pt(x∣c)=∇xlog⁡pt(x)+∇xlog⁡pt(c∣x).\nabla_x\log p_t(x\mid c)=\nabla_x\log p_t(x)+\nabla_x\log p_t(c\mid x).

The classifier must be meaningful at the current noise level. A clean-image classifier is not automatically suitable for highly corrupted inputs.

Classifier-free guidance trains conditional and null-condition predictions, then combines them. Using a convention where w=1w=1 is the ordinary conditional prediction,

ϵguided=ϵnull+w(ϵc−ϵnull).\epsilon_{\mathrm{guided}}=\epsilon_{\mathrm{null}}+w(\epsilon_c-\epsilon_{\mathrm{null}}).

For w>1w>1, the null prediction has a negative coefficient. This is extrapolation, not a convex average. Stronger guidance can change both prompt agreement and sample diversity.

Architecture

Latent diffusion performs denoising in a compressed representation. This saves computation, but the decoder limits what can be reconstructed. If fine text is already lost in an autoencoder reconstruction, improving the denoiser alone will not restore that missing representation capacity.

Transformer denoisers turn spatial regions into tokens. With a latent grid of height HH, width WW, and square patch size pp, the token count is HW/p2HW/p^2 when the dimensions divide evenly. Changing patch size therefore changes attention cost as well as spatial detail.

Text describes content, while spatial conditions such as depth or pose constrain layout. Showing that a model responds to a condition is weaker than showing that it follows that condition accurately.

Evaluation

The exact denoiser of a finite empirical distribution need not equal the population denoiser. For data points xix_i under additive Gaussian noise, the empirical posterior weights are proportional to

exp⁡(−∥y−xi∥22σ2).\exp\left(-\frac{\|y-x_i\|^2}{2\sigma^2}\right).

The corresponding clean estimate is the weighted average of the training points. At small noise levels, nearby examples can dominate. Architectural biases and regularization may instead favor reusable local structure, but that claim needs independent evidence.

A small denoising generalization gap is insufficient if both training and held-out losses are poor. Report the absolute losses too. Separate model error from numerical sampling error by comparing samplers with the learned model held fixed.

FID compares the first two moments of image features. It is a set-level statistic, not a complete description of visual quality or replication. A nearest-neighbor audit depends on its search dataset, representation, and threshold. Calibrate it on known transformed copies and unrelated controls before interpreting matches.

For controlled comparisons, keep prompts, seeds, datasets, and evaluation settings aligned. Change one factor at a time when attributing an improvement to a mechanism.

Worked examples: guidance and patch size

Suppose the unconditional noise prediction is [1,0][1,0] and the conditional prediction is [0,2][0,2]. Using ϵ^=ϵu+w(ϵc−ϵu)\hat\epsilon=\epsilon_u+w(\epsilon_c-\epsilon_u) with w=3w=3 gives [−2,6][-2,6]. Guidance extrapolates beyond the conditional estimate. It is not a weighted average with weights restricted to zero through one, which helps explain why very strong guidance can distort samples.

For a 64×6464\times64 latent grid, patches of width two produce 1,024 tokens. Patches of width four produce 256. The dense attention matrix then has one sixteenth as many entries. This comparison concerns attention cost; it does not imply that the entire model becomes sixteen times faster.

Further reading

Denoising Diffusion Implicit Models explains an alternative sampling process. Flow Matching for Generative Modeling develops velocity-field training along probability paths. Compare what each model predicts and how the numerical solver uses that prediction.