alanjiach@gmail.com

← all writing

Diffusion and score estimation

study notesdiffusion

Part of the generative visual computing notes.

Forward corruption

A diffusion model starts with a known corruption process. Let αt=1−βt\alpha_t=1-\beta_t and αˉt=∏s=1tαs\bar\alpha_t=\prod_{s=1}^t\alpha_s. One forward step is

xt=αtxt−1+βtϵt,ϵt∼N(0,I).x_t=\sqrt{\alpha_t}x_{t-1}+\sqrt{\beta_t}\epsilon_t, \qquad\epsilon_t\sim\mathcal N(0,I).

Because independent Gaussian increments combine into another Gaussian, we can sample a noisy observation directly:

xt=αˉtx0+1−αˉtϵ.x_t=\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\epsilon.

There is no need to simulate all preceding steps during each training update. At a sufficiently late time, the signal coefficient becomes small and the distribution approaches the chosen Gaussian endpoint. For a finite schedule this is an approximation, not an automatic identity.

The training target

The training program chooses x0x_0, a noise level tt, and a Gaussian draw ϵ\epsilon. It then predicts the noise from (xt,t)(x_t,t):

Lsimple=E[∥ϵ−ϵθ(xt,t)∥2].L_{\mathrm{simple}}=\mathbb E\left[\|\epsilon-\epsilon_\theta(x_t,t)\|^2\right].

The target is known because the program generated it. The network does not observe the clean image at inference time.

For squared error, the optimal predictor is a conditional mean. Different clean images and noise realizations may produce the same noisy observation. The best prediction at that observation averages the compatible targets. It need not recover the exact noise of every individual example.

The same network handles multiple noise levels, so it must receive information about tt. Otherwise it would have to infer both the image and the corruption strength from an ambiguous input.

From a bound to denoising

The reverse model defines a latent-variable likelihood through its intermediate states. A variational bound compares its reverse conditionals with posteriors of the known forward process. Under Gaussian parameterizations, terms in that bound become weighted prediction errors.

The common unweighted noise loss changes those weights. It is useful, but it should not be described as exactly the same objective as the full likelihood bound. Shared parameters can make weighting important even when an unconstrained predictor would have the same pointwise optimum.

During generation, the learned weights are fixed. A standard DDPM mean parameterization is

μθ(xt,t)=1αt(xt−βt1−αˉtϵθ(xt,t)).\mu_\theta(x_t,t)=\frac{1}{\sqrt{\alpha_t}} \left(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\epsilon_\theta(x_t,t)\right).

The sampler combines this mean with its chosen reverse variance. After each step, the network is evaluated again on the new state. A single prediction is not reused for the entire trajectory.

Scores

The score is st(x)=∇xlog⁡pt(x)s_t(x)=\nabla_x\log p_t(x). It points toward increasing log density locally. It is a vector field, not a density value or a probability.

Write Gaussian corruption as xt=atx0+σtϵx_t=a_tx_0+\sigma_t\epsilon. Its conditional score is

∇xtlog⁡q(xt∣x0)=−xt−atx0σt2=−ϵσt.\nabla_{x_t}\log q(x_t\mid x_0)=-\frac{x_t-a_tx_0}{\sigma_t^2}=-\frac{\epsilon}{\sigma_t}.

Averaging this conditional target at a fixed noisy input gives the marginal score. Thus an ideal noise predictor corresponds to st(xt)=−ϵθ(xt,t)/σts_t(x_t)=-\epsilon_\theta(x_t,t)/\sigma_t.

For a forward SDE dx=f(x,t)dt+g(t)dWtdx=f(x,t)dt+g(t)dW_t, the reverse-time drift is f−g2stf-g^2s_t when integrated from high to low time. The probability-flow ODE uses f−12g2stf-\tfrac12g^2s_t. Exact scores give matching marginal distributions under the corresponding constructions, but individual paths differ.

The sign convention matters. Writing a reverse equation and then integrating it in increasing time without changing variables changes the process. Also, following a score deterministically is not generally a sampling procedure: it can concentrate points near modes rather than preserve the desired distribution.

Worked example: recovering a clean signal

Let αˉt=0.64\bar\alpha_t=0.64, x0=2x_0=2, and sampled noise ϵ=−1\epsilon=-1. The forward process gives

xt=0.8(2)+0.6(−1)=1.x_t=0.8(2)+0.6(-1)=1.

An exact noise prediction recovers x0=(1−0.6(−1))/0.8=2x_0=(1-0.6(-1))/0.8=2. If the model predicts −0.5-0.5 instead, the clean estimate is 1.6251.625. More generally, the clean-estimate error is −(1−αˉt)/αˉt(ϵ^−ϵ)-\sqrt{(1-\bar\alpha_t)/\bar\alpha_t}(\hat\epsilon-\epsilon). The same noise-prediction error can therefore produce a larger clean-estimate error at a noisier timestep. This helps explain why timestep weighting and parameterization affect training.

Further reading

Denoising Diffusion Probabilistic Models connects the forward process, reverse parameterization, and simplified training objective. Keep the distinction between αt\alpha_t and the cumulative product αˉt\bar\alpha_t explicit when following the derivation.