AI Wiki中文/EN

Consistency models: boundaries, teachers and direct endpoint maps

一致性模型

Fit stopped-target Gaussian students and expose teacher discretization despite near-zero loss.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Every point on a trajectory should name the same destination

A numerical ODE solver reaches a low-noise endpoint by taking many local steps. A consistency model instead learns a function that maps a point on the trajectory directly to that endpoint. Two different times on the same trajectory should produce the same answer.

That rule alone is insufficient: a constant function gives the same answer for every pair, while generating nothing useful. The boundary condition prevents that trivial solution. Consistency Models, introduced by Song, Dhariwal, Chen and Sutskever in March 2023, combines trajectory consistency with an identity boundary and supports both distillation from a diffusion teacher and training without one. This article reads the initial paper, not every later consistency-training variant. Start with score SDEs and DDIM.

Teacher discretization and starting priors can change the result despite nearly zero consistency loss.
Teacher discretization and starting priors can change the result despite nearly zero consistency loss.

Consistency is along an ODE trajectory

For a probability-flow trajectory xt, define f(xt,t) to be its endpoint xε at a small positive ε:

f(xt,t)=xϵ,f(xt,t)=f(xs,s),f(x,ϵ)=x.f(x_t,t)=x_\epsilon,\qquad f(x_t,t)=f(x_s,s),\qquad f(x,\epsilon)=x.

The equality refers to states on the same ODE trajectory, not any two independently corrupted observations. The last condition anchors the function at the low-noise boundary. A common parameterization enforces that boundary through a skip connection:

fθ(x,t)=cskip(t)x+cout(t)Fθ(x,t),cskip(ϵ)=1,cout(ϵ)=0.f_\theta(x,t)=c_{\rm skip}(t)x+c_{\rm out}(t)F_\theta(x,t),\qquad c_{\rm skip}(\epsilon)=1,\quad c_{\rm out}(\epsilon)=0.

The official code implements boundary-aware scaling factors. A free-form predictor without such a constraint can minimize pair differences by collapsing to a constant. A finite learned function is also not automatically invertible merely because the exact ODE solution map is invertible under its regularity conditions.

A teacher supplies an adjacent state, not a human label

Choose adjacent times tn<tn+1t_n<t_{n+1}. A pretrained diffusion teacher defines a probability-flow ODE; one numerical solver step gives an approximation to the earlier state. Compare the student’s later prediction with a stopped target network’s earlier prediction:

x^tn=xtn+1+(tn−tn+1)Φ(xtn+1,tn+1),LCD=E[λ(tn)d(fθ(xtn+1,tn+1),sg⁡[fθ−(x^tn,tn)])].\widehat x_{t_n}=x_{t_{n+1}}+(t_n-t_{n+1})\Phi(x_{t_{n+1}},t_{n+1}),\qquad L_{\rm CD}=\mathbb E\big[\lambda(t_n)d(f_\theta(x_{t_{n+1}},t_{n+1}),\operatorname{sg}[f_{\theta^-}(\widehat x_{t_n},t_n)])\big].

Here Φ denotes the solver’s update function, d a discrepancy and sg a stop-gradient operation. The target parameters are updated by an exponential moving average rather than by differentiating this loss through the target:

θ−←μθ−+(1−μ)θ,0≤μ<1.\theta^-\leftarrow\mu\theta^-+(1-\mu)\theta,\qquad 0\le\mu<1.

The paper’s Algorithm 2 and the detached target branch in code implement this distinction. When checking gradients, hold the target parameters and teacher-generated states fixed. Differentiating through both branches checks a different objective.

A low distillation loss is not sufficient evidence of an exact continuous endpoint. The paper’s convergence statement involves regularity, a sufficiently accurate teacher/solver and refinement of the time grid. Our example will fit an Euler teacher very accurately and still produce the wrong continuous variance.

Training without a pretrained diffusion teacher

For the paper’s additive Gaussian perturbation family, one can use the same clean sample and noise draw at two nearby levels:

LCT=E[λ(tn)d(fθ(x+tn+1z,tn+1),sg⁡[fθ−(x+tnz,tn)])],z∼N(0,I).L_{\rm CT}=\mathbb E\big[\lambda(t_n)d(f_\theta(x+t_{n+1}z,t_{n+1}),\operatorname{sg}[f_{\theta^-}(x+t_nz,t_n)])\big],\qquad z\sim\mathcal N(0,I).

These paired noisy states are generally not exact points on one probability-flow trajectory. The initial paper’s Theorem 2 relates this objective to distillation in a small-step limit with smoothness, boundedness and exact-score assumptions; it does not make arbitrary finite-step CT and CD losses identical. This article explains that alternative but implements the distillation mechanism only. Later changes to training schedules and targets require their own version-specific analysis.

An endpoint map is not the conditional clean mean

Our clean distribution is N(m,v0), and additive noise of standard deviation t gives N(m,v0+t²). Its probability-flow field is t(x−m)/(v0+t²). Following that field to ε gives:

f∗(x,t)=m+v0+ϵ2v0+t2(x−m).f^*(x,t)=m+\sqrt{\frac{v_0+\epsilon^2}{v_0+t^2}}(x-m).

This transports the whole marginal distribution. It is different from the posterior clean mean, whose multiplier is v0/(v0+t²). Returning a conditional mean can remove variability; returning the exact flow endpoint preserves the appropriate endpoint distribution. At ε>0 that endpoint is still slightly noisy.

For multistep consistency sampling, first predict an endpoint, then inject fresh noise before applying the map again at an intermediate time τ>ε:

xτ=xϵ+τ2−ϵ2 z,xϵ′=fθ(xτ,τ).x_\tau=x_\epsilon+\sqrt{\tau^2-\epsilon^2}\,z,\qquad x'_\epsilon=f_\theta(x_\tau,\tau).

The subtraction matters. In the Gaussian example it restores variance v0+τ² before the next map. Injecting noise with standard deviation τ instead adds the boundary noise twice. Algorithm 1 uses the square-root difference.

Fit two teachers and compare their endpoint distributions

Save as consistency_models.py with Python 3.12 and NumPy 1.26.4. Set m=.7, v0=.36, ε=.1 and T=2. Nine time levels have a fixed identity row at ε and eight learned affine rows, sixteen trainable coefficients in total. Linear interpolation between rows is a teaching choice; the source model is a time-conditioned neural network. Our ε and T intentionally differ from the paper’s image settings.

Nine-point Gaussian quadrature gives population expectations at each later time. The target state comes either from an exact Gaussian teacher transition or a single Euler transition. The online coefficients update by an explicit gradient, while the target coefficients follow EMA=.9. There is no differentiation through the target or teacher, and no neural score training.

For J learned levels and Q nodes, an update costs O(JQ), with O(JQ) cached states and O(J) parameter storage. Direct mapping of N scalar samples costs O(N), while additional consistency sampling steps cost proportionally more. For real models, one forward pass can itself be expensive; “one step” describes a sampling path, not zero training or decoding cost.

"""Original adjacent-level Gaussian consistency distillation with stopped EMA target."""
import json
import numpy as np

MU,VAR,EPS,END=.7,.36,.1,2.
TIMES=np.linspace(EPS,END,9)

def coefficients(time):
    t=np.asarray(time,float)
    if not np.all(np.isfinite(t)) or np.any((t<EPS)|(t>END)):raise ValueError('Time in[0.1,2] required.')
    slope=np.sqrt((VAR+EPS**2)/(VAR+t*t));return np.stack([slope,MU*(1-slope)],axis=-1)

def teacher_step(x,time,earlier,method='exact'):
    if not EPS<=earlier<time<=END:raise ValueError('Require epsilon<=earlier<time<=T.')
    if method=='exact':return MU+np.sqrt((VAR+earlier**2)/(VAR+time**2))*(x-MU)
    if method=='euler':return x+(earlier-time)*time/(VAR+time*time)*(x-MU)
    raise ValueError('Choose exact or euler teacher.')

def model(x,time,theta):
    coefficients(time);theta=np.asarray(theta,float)
    if theta.shape!=(8,2) or not np.all(np.isfinite(theta)):raise ValueError('Finite8 by2 online parameters required.')
    # Boundary row is fixed, never trained. Interpolation is for this teaching model.
    all_coef=np.vstack([[1.,0.],theta]);a=np.interp(time,TIMES,all_coef[:,0]);b=np.interp(time,TIMES,all_coef[:,1]);return a*x+b

def data(method='exact'):
    z,w=np.polynomial.hermite.hermgauss(9);z=np.sqrt(2)*z;w/=np.sqrt(np.pi)
    high=MU+np.sqrt(VAR+TIMES[1:,None]**2)*z
    low=np.array([teacher_step(high[i],TIMES[i+1],TIMES[i],method) for i in range(8)])
    return high,low,w

def objective(theta,target_theta,dataset):
    high,low,w=dataset;theta=np.asarray(theta,float);target_theta=np.asarray(target_theta,float)
    if theta.shape!=(8,2) or target_theta.shape!=(8,2):raise ValueError('8 by2 coefficient tables required.')
    target=np.vstack([[1.,0.],target_theta[:-1]])
    predicted=theta[:,0,None]*high+theta[:,1,None]
    stopped=target[:,0,None]*low+target[:,1,None]
    error=predicted-stopped
    return float(np.mean((error*error)@w)),2/8*np.column_stack([(error*high)@w,error@w])

def train(method='exact',updates=4000):
    if type(updates) is not int or not 1<=updates<=10000:raise ValueError('Updates1..10000 required.')
    dataset=data(method);theta=np.tile([1.,0.],(8,1));target=theta.copy();history=[objective(theta,target,dataset)[0]]
    for i in range(updates):
        theta-=.5*objective(theta,target,dataset)[1]
        target=.9*target+.1*theta
        if (i+1)%1000==0:history.append(objective(theta,target,dataset)[0])
    return theta,target,history

def sample_moments(theta,terminal='true'):
    if terminal=='true':mean,var=MU,VAR+END**2
    elif terminal=='prior':mean,var=0.,END**2
    else:raise ValueError('Choose true or prior terminal.')
    a,b=theta[-1];return [float(a*mean+b),float(a*a*var)]

def multistep_variance(time,wrong_noise=False):
    a=coefficients(time)[0];injected=time*time-(0 if wrong_noise else EPS*EPS)
    return float(a*a*(VAR+EPS**2+injected))

def demo():
    exact,target,history=train();euler,_,euler_history=train('euler')
    return dict(exact_teacher_loss=history,euler_teacher_loss=euler_history,parameter_error=float(np.max(abs(exact-coefficients(TIMES[1:])))),ema_gap=float(np.max(abs(exact-target))),exact_teacher_moments=sample_moments(exact),euler_teacher_moments=sample_moments(euler),standard_prior_moments=sample_moments(exact,'prior'),data_variance=VAR,epsilon_target_variance=VAR+EPS**2,multistep_variance=multistep_variance(.8),wrong_noise_variance=multistep_variance(.8,True),constant_pair_loss=0.,constant_boundary_error=1.)

if __name__=='__main__':print(json.dumps(demo(),indent=2))

After 4,000 updates at rate .5, the exact-teacher fit differs from the analytic coefficient table by about 3.61×10⁻¹⁵. EMA differs from the online coefficients by about 1.22×10⁻¹⁵. From the true terminal marginal, the output has mean .7 and variance .37—the ε endpoint, not the clean .36 variance.

The Euler-teacher student also reaches a loss around 10⁻³¹, yet its output variance is .2898125581. It has accurately learned the endpoint map induced by repeated discrete teacher steps. The independent reference is the product of their affine scale factors:

aEuler=∏i[1+(ti−ti+1)ti+1v0+ti+12],Var⁡(fEuler(XT,T))=aEuler2(v0+T2).a_{\rm Euler}=\prod_i\left[1+\frac{(t_i-t_{i+1})t_{i+1}}{v_0+t_{i+1}^2}\right],\qquad \operatorname{Var}(f_{\rm Euler}(X_T,T))=a_{\rm Euler}^2(v_0+T^2).

Replacing the true terminal Gaussian with N(0,T²) introduces another mismatch: the exact-teacher student’s mean and variance become .49608196 and .33944954. At intermediate time .8, correct fresh-noise scaling preserves endpoint variance .37; injecting standard deviation .8 instead gives .3737. Training error, teacher discretization, boundary noise and initial-prior mismatch are separately visible.

A consistent answer can still be biased

Teacher errors, coarse time grids, model capacity, target updates and optimization all affect what a student learns. Distillation can preserve a teacher’s bias; finite-step teacher-free training has its own approximation and stability questions. Low pair loss is therefore not a substitute for checking sample distributions and boundary behavior.

The implementation’s fixed boundary row prevents the constant-solution pathology, but it does not reproduce the full neural skip parameterization or image training setup. Few-step sampling can trade compute for quality, but it need not improve every metric monotonically. This article does not establish image editing, FID performance or the properties of later improved consistency algorithms.

What does a nearly zero loss prove?

  1. Boundary. A constant function gives identical outputs on every pair. Why is it invalid here? Answer: It fails f(x,ε)=x for general x. Pair agreement alone does not identify the desired endpoint map.
  2. Gradient. Should a finite-difference check perturb the target table together with the online table? Answer: No. Keep the EMA target fixed for that loss evaluation. Perturbing both tests a different derivative from the stopped-target update.
  3. Hand calculation. With v0=.36 and ε=.1, what endpoint variance should the exact map preserve? Answer: .36+.1²=.37. At τ=.8, inject variance .8²−.1²=.63 before applying the map again.
  4. Diagnosis. A student has almost zero loss but variance .2898 rather than .37. Must its optimizer be wrong? Answer: No. The example fits an Euler teacher’s discrete map. Check teacher accuracy and time discretization before interpreting pair loss as continuous correctness.

Follow the boundary, target and sampling rules together

Read Sections 2–5, Algorithms 1–3 and the conditions of Theorems 1–2. Compare boundary scaling, teacher stepping and detached targets. We used official v1 HTML after bounded PDF retrieval failed; full appendix proofs, later revisions and image experiments were not reproduced. The original Gaussian program implements a controlled CD experiment, not the teacher-free CT algorithm or the authors’ image system.

Make a prediction, then check

Does almost-zero pair loss establish the exact continuous endpoint?

Choose one answer

Learning objectives

  • Define same-trajectory consistency and boundary.
  • Trace stopped EMA-target gradients.
  • Distinguish distillation from teacher-free training.
  • Measure teacher, prior and endpoint errors.

Prerequisites & connections

Explore related knowledge →

References

  1. Consistency Models (v1 HTML)
    Yang Song; Prafulla Dhariwal; Mark Chen; Ilya Sutskever · 2023
  2. consistency-karras method reference at e32b69e
    openai/consistency_models contributors · 2023

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-20 · Single AI author checked Consistency Models v1 selected sections2-5/algorithms1-3 and fixed author boundary/teacher/target code. Eight paired equations and four explained exercises;16-parameter affine student, held-target gradients, EMA, exact/Euler teacher bias, positive epsilon endpoint, multistep noise and prior mismatch. No consistency-training theorem replication or image benchmark.

  • Single AI author checked Consistency Models v1 selected sections2-5/algorithms1-3 and fixed author boundary/teacher/target code. Eight paired equations and four explained exercises;16-parameter affine student, held-target gradients, EMA, exact/Euler teacher bias, positive epsilon endpoint, multistep noise and prior mismatch. No consistency-training theorem replication or image benchmark.
  • Four computed SVG variants per topic. Eleven numeric/geometry tests and36 responsive cases passed; twelve final Chinese-mobile/English-desktop screenshots actually inspected. Mobile-title and cost-axis corrections preserved. Full article acceptance recorded separately.

Source locations checked:

  • Consistency Models (v1 HTML) · Read selected Sections2-5, boundary/skip, algorithms1-3, CD/EMA/CT objectives and theorem1-2 conditions. v1 dated2023-03-02; not later revised methods. HTML after bounded PDF failure; no full appendix or image reproduction.
  • consistency-karras method reference at e32b69e · Read 68-79,106-240: boundary coefficients, exact detached target mechanics, teacher Heun versus teacher-free shared-noise Euler and loss norms. MIT license read. Fixed public commit; reference only, no copied/executed code.

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.