Search

Search papers and lessons

Consistency Models

Yang Song, Prafulla Dhariwal, Mark Chen et al. · 2023

Song et al. train a network that maps any point on a diffusion model's noise-to-data trajectory straight to its clean endpoint, so one call makes a sample and more calls trade compute for quality.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Generative models
  • Linear algebra
  • Discrete math
  • Losses & regularization
  • Sign in to see your progress

TL;DR

Diffusion models make excellent images, but each sample takes many network calls, because sampling walks a noise vector back to data one small step at a time. Song, Dhariwal, Chen and Sutskever train a consistency model that maps any point on a diffusion model's probability-flow trajectory directly to that trajectory's clean endpoint. One network call then gives a sample, and extra calls trade compute for quality. The model can be distilled from a pre-trained diffusion model or trained with no diffusion model at all.

Where you'll see it: one-step and two-step image generation, and distilling a pre-trained diffusion model into a fast sampler.

The problem

Diffusion sampling solves an ODE or SDE numerically, and each step is a call to a large score network. The paper notes that diffusion models typically need 10 to 2000 times more compute per sample than single-step generators such as GANs, VAEs and normalizing flows. Two families of fixes existed, and neither was enough:

  • Better ODE solvers still needed more than about 10 evaluation steps for competitive samples.
  • Distillation of a diffusion model into a faster sampler. Most methods (knowledge distillation, DFNO) first generate a large synthetic dataset with an expensive solver. Progressive distillation avoids that cost, and it is the one the authors compare against most closely.

The open goal was a model that generates in one step, keeps the option of spending more compute for better quality, and still supports zero-shot editing such as inpainting, which the iterative process gives diffusion models for free.

Key idea

Start from a diffusion model's probability-flow (PF) ODE. Integrating it from a data point backwards to noise gives a trajectory, and every point on that trajectory came from the same data point. Call xϵ\mathbf{x}_\epsilon the point at the small time ϵ\epsilon near the data end. A consistency function f\mathbf{f} maps any point (xt,t)(\mathbf{x}_t, t) on a trajectory to xϵ\mathbf{x}_\epsilon. Every point on one trajectory gives the same output. That is the self-consistency property.

The authors train a neural network fθ\mathbf{f}_\theta to have this property. If it does, sampling needs one call: draw noise at the top time TT, and evaluate fθ\mathbf{f}_\theta once. Picture the trajectories as curves from noise to data that never cross. The network has to learn a single map that sends every point on a curve to the curve's endpoint.

The method

Definition and boundary condition

The consistency function must satisfy f(xϵ,ϵ)=xϵ\mathbf{f}(\mathbf{x}_\epsilon, \epsilon) = \mathbf{x}_\epsilon. Call this the boundary condition: at the smallest time, the output is the input. It is the one architectural constraint the authors call confining. They enforce it with a skip connection, using a free-form network FθF_\theta:

fθ(x,t)=cskip(t) x+cout(t) Fθ(x,t)\mathbf{f}_\theta(\mathbf{x}, t) = c_{\text{skip}}(t)\,\mathbf{x} + c_{\text{out}}(t)\,F_\theta(\mathbf{x}, t)

with cskip(ϵ)=1c_{\text{skip}}(\epsilon) = 1 and cout(ϵ)=0c_{\text{out}}(\epsilon) = 0. The paper reuses the EDM preconditioning of Karras et al. (2022) with the offset t−ϵt - \epsilon in place of tt, which makes the boundary hold exactly:

cskip(t)=σdata2(t−ϵ)2+σdata2,cout(t)=σdata (t−ϵ)σdata2+t2c_{\text{skip}}(t) = \frac{\sigma_{\text{data}}^2}{(t-\epsilon)^2 + \sigma_{\text{data}}^2}, \qquad c_{\text{out}}(t) = \frac{\sigma_{\text{data}}\,(t-\epsilon)}{\sqrt{\sigma_{\text{data}}^2 + t^2}}

The paper uses σdata=0.5\sigma_{\text{data}} = 0.5, ϵ=0.002\epsilon = 0.002 and T=80T = 80 for image data scaled to [−1,1][-1, 1]. The worked examples below check the boundary condition with these values.

Sampling

Algorithm 1 (multistep consistency sampling) starts from noise x^T∼N(0,T2I)\hat{\mathbf{x}}_T \sim \mathcal{N}(\mathbf{0}, T^2 \mathbf{I}). It sets x←fθ(x^T,T)\mathbf{x} \leftarrow \mathbf{f}_\theta(\hat{\mathbf{x}}_T, T), which is already a sample. Then, for each chosen time τn\tau_n in a decreasing list, it adds fresh noise to reach x^τn=x+τn2−ϵ2 z\hat{\mathbf{x}}_{\tau_n} = \mathbf{x} + \sqrt{\tau_n^2 - \epsilon^2}\,\mathbf{z} and denoises with x←fθ(x^τn,τn)\mathbf{x} \leftarrow \mathbf{f}_\theta(\hat{\mathbf{x}}_{\tau_n}, \tau_n). With no extra steps this is one call. Each extra step adds one call and usually improves quality. The authors choose the intermediate times greedily, one at a time with ternary search, to minimise FID.

Training by consistency distillation (CD)

Assume a pre-trained score model sϕ(x,t)≈∇log⁡pt(x)\mathbf{s}_\phi(\mathbf{x}, t) \approx \nabla \log p_t(\mathbf{x}). Discretise [ϵ,T][\epsilon, T] into N−1N-1 intervals with the EDM spacing ti=(ϵ1/ρ+i−1N−1(T1/ρ−ϵ1/ρ))ρt_i = (\epsilon^{1/\rho} + \frac{i-1}{N-1}(T^{1/\rho} - \epsilon^{1/\rho}))^\rho, where ρ=7\rho = 7. One Euler step of the PF ODE from tn+1t_{n+1} to tnt_n gives an estimate of the earlier point:

x^tnϕ=xtn+1−(tn−tn+1) tn+1 sϕ(xtn+1,tn+1)\hat{\mathbf{x}}^{\phi}_{t_n} = \mathbf{x}_{t_{n+1}} - (t_n - t_{n+1})\, t_{n+1}\, \mathbf{s}_\phi(\mathbf{x}_{t_{n+1}}, t_{n+1})

Take a data point x\mathbf{x}, add Gaussian noise of scale tn+1t_{n+1} to get xtn+1\mathbf{x}_{t_{n+1}}, and take one ODE step to get x^tnϕ\hat{\mathbf{x}}^{\phi}_{t_n}. Those two points are adjacent on the same trajectory, so the model's outputs on them should agree. The loss is

LCDN(θ,θ−;ϕ)=E[λ(tn) d ⁣(fθ(xtn+1,tn+1),  fθ−(x^tnϕ,tn))]\mathcal{L}^N_{\text{CD}}(\theta, \theta^-; \phi) = \mathbb{E}\left[\lambda(t_n)\, d\!\left(\mathbf{f}_\theta(\mathbf{x}_{t_{n+1}}, t_{n+1}),\; \mathbf{f}_{\theta^-}(\hat{\mathbf{x}}^{\phi}_{t_n}, t_n)\right)\right]

where dd is a distance (squared ℓ2\ell_2, ℓ1\ell_1 or LPIPS), λ≡1\lambda \equiv 1 performs well across the paper's tasks and datasets, and θ−\theta^- is a target network. The target is an exponential moving average of the online weights, with a stop-gradient: θ−←stopgrad⁡(μ θ−+(1−μ) θ)\theta^- \leftarrow \operatorname{stopgrad}(\mu\,\theta^- + (1-\mu)\,\theta). The authors report that this EMA target stabilises training and improves the final result compared with setting θ−=θ\theta^- = \theta.

Theorem 1 gives the justification. If the network is Lipschitz in x\mathbf{x}, the ODE solver has local error of order (tn+1−tn)p+1(t_{n+1} - t_n)^{p+1}, and the loss is exactly zero, then the consistency model's error against the true consistency function is O((Δt)p)O((\Delta t)^p) uniformly over the grid.

Training in isolation by consistency training (CT)

Distillation needs a pre-trained score model. The authors remove that need by replacing the score with an unbiased estimate from data alone. Given x∼pdata\mathbf{x} \sim p_{\text{data}} and xt∼N(x,t2I)\mathbf{x}_t \sim \mathcal{N}(\mathbf{x}, t^2 \mathbf{I}),

∇log⁡pt(xt)=−E[xt−xt2 | xt]\nabla \log p_t(\mathbf{x}_t) = -\mathbb{E}\left[\frac{\mathbf{x}_t - \mathbf{x}}{t^2} \,\middle|\, \mathbf{x}_t\right]

so the displacement −(xt−x)/t2-(\mathbf{x}_t - \mathbf{x})/t^2 is a usable score estimate. Theorem 2 shows that, with Euler steps and N→∞N \to \infty, the CD loss equals a consistency training loss plus a term that vanishes as the step size shrinks. The CT loss pairs two noisy versions of the same data point, using one shared noise vector z\mathbf{z}:

LCTN(θ,θ−)=E[λ(tn) d ⁣(fθ(x+tn+1z,tn+1),  fθ−(x+tnz,tn))]\mathcal{L}^N_{\text{CT}}(\theta, \theta^-) = \mathbb{E}\left[\lambda(t_n)\, d\!\left(\mathbf{f}_\theta(\mathbf{x} + t_{n+1}\mathbf{z}, t_{n+1}),\; \mathbf{f}_{\theta^-}(\mathbf{x} + t_n \mathbf{z}, t_n)\right)\right]

The authors explain the schedule. A small NN gives a biased but low-variance loss that converges fast. A large NN gives a less biased but noisier loss that gives better final samples. So they grow N(k)N(k) during training, and they move the EMA decay μ(k)\mu(k) along with it. Their ablation shows that the adaptive schedules speed up convergence compared with fixed values.

There is also a continuous-time version, with N→∞N \to \infty. It needs Jacobian-vector products and so forward-mode automatic differentiation. In the appendix experiments, the stop-gradient variant of continuous-time distillation works better than the non-stop-gradient one, and LPIPS improves continuous-time CT.

Results

The headline numbers come from the abstract and introduction.

  • CIFAR-10: consistency distillation reaches FID 3.55 in one step and 2.93 in two steps. The authors call these new state-of-the-art few-step values for that benchmark.
  • ImageNet 64x64: FID 6.20 in one step and 4.70 in two steps.
  • Against progressive distillation (Figure 4, text): CD beats PD across the datasets, step counts and metrics the authors tried. The one exception is one-step generation on LSUN Bedroom 256x256 with the squared ℓ2\ell_2 metric.
  • Standalone CT: the paper reports that it beats one-step, non-adversarial VAEs and normalizing flows on CIFAR-10 by a large margin, and that its one-step samples are comparable to one-step samples from progressive distillation. The abstract says CT can outperform existing one-step, non-adversarial generative models on CIFAR-10, ImageNet 64x64 and LSUN 256x256.
  • Hyperparameters on CIFAR-10 (Figure 3): LPIPS is the best metric for CD. The Heun solver beats Euler at the same NN, and N=18N = 18 is the best choice. For CT, small NN converges faster but gives worse samples, and the adaptive NN and μ\mu schedules improve convergence and quality. In the appendix comparison of discrete and continuous-time objectives (models initialised from EDM), discrete CT uses N=120N = 120, learning rate 4e-4 and EMA decay 0.99; the continuous-time runs use learning rate 5e-6.
  • Zero-shot editing (Section 6.3, Appendix D): colorization, super-resolution, stroke-guided editing (SDEdit-style), inpainting, interpolation and denoising. These are shown with pictures, with no numbers.

The results section is a snapshot of the authors' own setup. The comparisons are against models they trained in-house under matched conditions, so the margins say less about the field than the single-step numbers do.

Why it mattered

The paper's contribution is a one-step-capable model that keeps the option of more steps. The distillation methods it compared against needed synthetic data or lagged on quality in the authors' tests. CD gave a way to distill with no synthetic data. CT showed that a consistency model can be a generative model in its own right, with no diffusion model at all. The authors also tie the idea to deep Q-learning's target networks and to momentum contrastive learning, which both use the same kind of slowly moving target. That link is why the EMA target appears in the method at all.

Reading guide

Read the paper in this order. Each prerequisite is listed where it first matters.

  1. Section 1 (introduction): no prerequisites beyond the idea of a generative model. The one-line summary is the consistency property.
  2. Section 2 (diffusion models): the SDE, the probability-flow ODE and the score function. Read the score-based SDE view first. For the discrete noising chain that Denoising Diffusion Probabilistic Models (DDPM) introduced, which the paper's Section 1 cites as earlier diffusion work, read that lesson next. For the deterministic sampler behind the ODE, see the DDIM sampler.
  3. Section 3 (consistency models): the definition, the boundary condition and Algorithm 1. Read Consistency Model first. It covers the same definition in a standalone lesson.
  4. Section 4 (distillation): the CD loss and Theorem 1. Read Knowledge Distillation first, since the paper contrasts its approach with it. The Euler step in Equation 6 is the ODE solver from Section 2.
  5. Section 5 (training in isolation): the score estimator in Equation 11, the CT loss and the schedules. Needs only Section 2.
  6. Section 6 (experiments): the FID and precision and recall metrics are used without definition. The progressive-distillation comparison assumes the reader knows that method. It has no lesson in the graph yet.
  7. Appendices A and B: proofs and continuous-time theory. Skip on a first read.

Check yourself

QuestionWhy does the boundary condition f(x,ϵ)=x\mathbf{f}(\mathbf{x}, \epsilon) = \mathbf{x} matter for training?Show answer

Without it, the trivial solution f(x,t)=0\mathbf{f}(\mathbf{x}, t) = \mathbf{0} would drive the CD loss to zero for every tt and teach nothing. The boundary condition forces the output to depend on the input, so the network has to learn the trajectory endpoint. The paper enforces it architecturally with the skip connection, not with a penalty.

QuestionWith the paper's σdata=0.5\sigma_{\text{data}} = 0.5 and ϵ=0.002\epsilon = 0.002, compute cskip(1)c_{\text{skip}}(1) and cout(1)c_{\text{out}}(1) and check the boundary at t=ϵt = \epsilon.Show answer
  1. t−ϵ=1−0.002=0.998t - \epsilon = 1 - 0.002 = 0.998, so (t−ϵ)2=0.996004(t-\epsilon)^2 = 0.996004.
  2. σdata2=0.25\sigma_{\text{data}}^2 = 0.25, so the denominator of cskipc_{\text{skip}} is 0.996004+0.25=1.2460040.996004 + 0.25 = 1.246004.
  3. cskip(1)=0.25/1.246004≈0.2006c_{\text{skip}}(1) = 0.25 / 1.246004 \approx 0.2006.
  4. σdata2+t2=1.25≈1.11803\sqrt{\sigma_{\text{data}}^2 + t^2} = \sqrt{1.25} \approx 1.11803, and the numerator of coutc_{\text{out}} is 0.5×0.998=0.4990.5 \times 0.998 = 0.499.
  5. cout(1)=0.499/1.11803≈0.4463c_{\text{out}}(1) = 0.499 / 1.11803 \approx 0.4463.
  6. At t=ϵt = \epsilon: t−ϵ=0t - \epsilon = 0, so cskip=0.25/0.25=1c_{\text{skip}} = 0.25 / 0.25 = 1 and cout=0c_{\text{out}} = 0. The output is the input, as the boundary requires.
QuestionIn one Euler step, tn+1=2t_{n+1} = 2, tn=1.5t_n = 1.5, xtn+1=0.8\mathbf{x}_{t_{n+1}} = 0.8, and the score model returns s=−0.5\mathbf{s} = -0.5. Compute the target x^tn\hat{\mathbf{x}}_{t_n} and say what the CD loss then asks for.Show answer

Illustrative numbers, one dimension.

  1. Φ=−tn+1 s=−2×(−0.5)=1\Phi = -t_{n+1}\,\mathbf{s} = -2 \times (-0.5) = 1.
  2. tn−tn+1=1.5−2=−0.5t_n - t_{n+1} = 1.5 - 2 = -0.5.
  3. x^tn=0.8+(−0.5)(1)=0.3\hat{\mathbf{x}}_{t_n} = 0.8 + (-0.5)(1) = 0.3.
  4. The CD loss with λ=1\lambda = 1 and squared error asks the online model at (0.8,2)(0.8, 2) to match the target model at (0.3,1.5)(0.3, 1.5). If the online output is 0.350.35 and the target output is 0.300.30, the loss is (0.35−0.30)2=0.0025(0.35 - 0.30)^2 = 0.0025. Training pushes the online output at the later time toward the target output at the earlier time, and the EMA target moves slowly toward the online model.
QuestionWhy does the paper grow NN during consistency training, rather than fixing it?Show answer

A small NN means the adjacent points are far apart, so the loss has low variance but high bias relative to the consistency distillation objective. It converges quickly but gives worse final samples. A large NN reduces bias and gives better final samples, but the loss is noisier, so it converges slowly. The paper starts with a small NN for speed and grows it for quality. The authors also say the EMA decay schedule has to change with NN.

QuestionApplied: you have a trained consistency model and need samples in under 100 ms on a GPU where one call takes 40 ms. How many calls can you afford, and what does the paper say about quality per call?Show answer

Two calls fit in 80 ms, and a third would take 120 ms, which is over budget. So you can run the one-step sampler or the two-step sampler. The paper reports FID 3.55 at one step and 2.93 at two steps on CIFAR-10, so the second call buys a modest improvement. Use the two-step sampler if quality matters more than the extra 40 ms, and the one-step sampler if latency is the constraint. Check these FIDs on your own data before relying on them, since they are the paper's numbers, not yours.

Sources

  • Song, Dhariwal, Chen, Sutskever. Consistency Models, 2023. arXiv:2303.01469
  • Song et al. Score-Based Generative Modeling through Stochastic Differential Equations, 2020. arXiv:2011.13456
  • Karras et al. Elucidating the Design Space of Diffusion-Based Generative Models, 2022. arXiv:2206.00364

Read the full paper

Yang Song, Prafulla Dhariwal, Mark Chen et al., 2023. arXiv:2303.01469