Few-Step Generation

Dive into Deep Learning · §17.8

Few-Step Generation: Flow Maps, Consistency, and Distillation
curved ODE trajectories · Rectified Flow & Reflow · flow maps & average velocity · MeanFlow identity · consistency models · DMD

Why Can a Standard Diffusion Model Not Take One Step?

Motivation

  • Velocity \neq displacement: A velocity network \mathbf{u}_{\boldsymbol\theta}(\mathbf{x}_t, t) predicts the instantaneous tangent d\mathbf{x}_t/dt at time t, not the chord to t = 0.
  • Curved trajectories cause tangent overshoot: Even with the exact field \mathbf{u}_t, a 1-step Euler jump from t = 1 follows \mathbf{u}_1(\mathbf{x}_1) = \mathbf{x}_1 - \mathbb{E}[\mathbf{x}_0] and collapses all samples onto the global mean \mathbb{E}[\mathbf{x}_0].
  • Two routes to 1–4 steps: Straighten or integrate trajectories via Reflow / Flow Maps, or match densities directly via DMD / ADD.

Quantifying Few-Step Euler Failure on the Exact Field

1, 2, 4, and 10 Euler Steps on the 2D Mixture

Running Euler’s method on the exact mixture velocity mix.velocity from 20{,}000 Gaussian starts establishes the baseline that few-step generators must beat:

  • 1 Euler step: Collapses 100\% of starts onto (-0.5, -0.7) in the empty valley between modes (weights [1, 0, 0], 100\% strays).
  • 2 Euler steps: Separates into three clusters, but leaves \approx 25\% strays and severely distorts mode weights to [0.64, 0.22, 0.14] (vs. [0.50, 0.30, 0.20]) because the first half-step pulls all points toward (-0.5, -0.7), closest to mode 1.
  • 4 vs. 10 Euler steps: Strays remain at \approx 6.5\% at 4 steps before dropping to \approx 2\% at 10 steps (\approx 1\% in true data).

 1 Euler steps: weights [1.0, 0.0, 0.0], stray 100.0%
 2 Euler steps: weights [0.644, 0.217, 0.14], stray 25.1%
 4 Euler steps: weights [0.54, 0.277, 0.183], stray 6.5%
10 Euler steps: weights [0.512, 0.291, 0.197], stray 2.2%

Rectified Flow and Reflow: Straightening Trajectories

Re-Pairing Noise and Data Along ODE Chords

\mathcal{L}_{\textrm{Reflow}}(\boldsymbol\theta) = \mathbb{E}_{\mathbf{z}, t}\Big[\big\|\mathbf{u}_{\boldsymbol\theta}\big((1 - t)\hat{\mathbf{x}}_0 + t\mathbf{z},\; t\big) - (\mathbf{z} - \hat{\mathbf{x}}_0)\big\|^2\Big]

  • Why independent chords curve the ODE: Independently drawn segments (1-t)\mathbf{x}_0 + t\boldsymbol\epsilon cross everywhere, forcing non-crossing marginal ODE trajectories to bend around intersections.
  • Reflow (Liu, Gong & Liu, 2022): Pairs noise \mathbf{z} with teacher ODE endpoints \hat{\mathbf{x}}_0 = \Phi_{1 \to 0}(\mathbf{z}) to obtain nearly non-crossing chords, though it requires full synthetic dataset generation and inherits teacher errors.

Flow Maps and the Average Velocity Field

Learning the ODE Solution Instead of Its Derivative

Instead of straightening trajectories by re-pairing data, we can train a network to output the flow map \Phi_{t \to s}(\mathbf{x}_t)—the exact point where the ODE trajectory through (\mathbf{x}_t, t) arrives at time s \le t:

\Phi_{t \to s}(\mathbf{x}_t) = \mathbf{x}_t - \int_s^t \mathbf{u}_\tau(\mathbf{x}_\tau)\,d\tau = \mathbf{x}_t - (t - s)\,\bar{\mathbf{u}}(\mathbf{x}_t, s, t)

  • Average velocity \bar{\mathbf{u}}(\mathbf{x}_t, s, t): The time-averaged velocity along the curved trajectory over [s, t].
  • Boundary condition at zero step (s \to t): As s \to t, the average velocity collapses to the instantaneous velocity: \bar{\mathbf{u}}(\mathbf{x}_t, t, t) = \mathbf{u}_t(\mathbf{x}_t)
  • One-step & multi-step sampling: A single evaluation \mathbf{x}_1 - \bar{\mathbf{u}}(\mathbf{x}_1, 0, 1) jumps straight from noise to data.

Worked Example: Exact Flow Map on 1D Gaussian Data

Why Average Velocity Preserves Spread While Euler Collapses

\Phi_{t \to s}(x) = (1 - s)\,m + \frac{k_s}{k_t}\big(x - (1 - t)\,m\big)

  • Exact quantile preservation: For x_0 \sim \mathcal{N}(2, 0.5^2) with k_t = \sqrt{0.25(1-t)^2 + t^2}, the 1D ODE preserves the standardized z-score from t=1 (k_1 = 1) to s=0 (k_0 = 0.5).
  • 1-Step Euler jump (u_1(x) = x - 2): Lands at x - (x - 2) = \mathbf{2}, collapsing variance to zero.
  • 1-Step Flow-Map jump (\bar{u}(x, 0, 1) = 0.5x - 2): Lands at x - (0.5x - 2) = \mathbf{2 + 0.5x} \sim \mathcal{N}(2, 0.5^2).

Three Differential Identities Characterizing Flow Maps

Compositional, Lagrangian, and Eulerian Formulations

  • 1. Compositional (Semigroup): \Phi_{r \to s}(\Phi_{t \to r}(\mathbf{x}_t)) = \Phi_{t \to s}(\mathbf{x}_t), using two student passes at r and no derivatives (Progressive Distillation, Shortcut Models).
  • 2. Lagrangian (Moving endpoint s): \partial_s \Phi_{t \to s}(\mathbf{x}_t) = \mathbf{u}_s(\Phi_{t \to s}(\mathbf{x}_t)), evaluating velocity \mathbf{u}_s at the landing point \Phi_{t \to s}(\mathbf{x}_t).
  • 3. Eulerian (Moving start t): \partial_t \Phi_{t \to s} + (\nabla_{\mathbf{x}}\Phi_{t \to s})\mathbf{u}_t = \mathbf{0}, evaluating velocity \mathbf{u}_t at the start point \mathbf{x}_t via 1 forward-mode JVP (Consistency Models, MeanFlow).

Consistency Models: Learning the Jump to t = 0

Enforcing Invariance Along Trajectories

\frac{d}{dt}f_{\boldsymbol\theta}(\mathbf{x}_t, t) = \partial_t f_{\boldsymbol\theta}(\mathbf{x}_t, t) + \big(\nabla_{\mathbf{x}} f_{\boldsymbol\theta}(\mathbf{x}_t, t)\big)\,\mathbf{u}_t(\mathbf{x}_t) = \mathbf{0}

  • Fixed endpoint s = 0 (Song et al., 2023): Enforces f_{\boldsymbol\theta}(\mathbf{x}_t, t) = \Phi_{t \to 0}(\mathbf{x}_t) along every trajectory with boundary condition f_{\boldsymbol\theta}(\mathbf{x}_0, 0) = \mathbf{x}_0.
  • Why multi-step sampling requires stochastic re-noising: Because f_{\boldsymbol\theta} only jumps to s = 0, a second step must re-corrupt \hat{\mathbf{x}}_0 to t = 0.5 with fresh noise \boldsymbol\epsilon', losing the deterministic ODE bijection.

Deriving the Two-Time MeanFlow Identity

Exact Regression Target for Average Velocity

\bar{\mathbf{u}}(\mathbf{x}_t, s, t) = \mathbf{u}_t(\mathbf{x}_t) - (t - s)\,\frac{d}{dt}\bar{\mathbf{u}}(\mathbf{x}_t, s, t)

  • Product-rule derivation (Geng et al., 2025): Differentiating (t - s)\,\bar{\mathbf{u}}(\mathbf{x}_t, s, t) = \int_s^t \mathbf{u}_\tau(\mathbf{x}_\tau)\,d\tau with respect to t at fixed s yields an explicit fixed-point target for \bar{\mathbf{u}}.
  • Single forward-mode JVP: Along d\mathbf{x}_t/dt = \mathbf{u}_t, the total derivative \frac{d}{dt}\bar{\mathbf{u}} = \partial_t\bar{\mathbf{u}} + (\nabla_{\mathbf{x}}\bar{\mathbf{u}})\mathbf{u}_t is one JVP along tangent (\mathbf{u}_t, 1).

The Unified Flow-Map Loss and Stop-Gradient Rule

Four Few-Step Methods in One Equation

\mathcal{L}_{\textrm{FM}}(\boldsymbol\theta) = \mathbb{E}\!\left[\Big\|\bar{\mathbf{u}}_{\boldsymbol\theta}(\mathbf{x}_t, s, t) - \mathrm{sg}\!\Big[\mathbf{u}_{\textrm{ref}} - (t - s)\,\big(\partial_t\bar{\mathbf{u}}_{\boldsymbol\theta} + (\nabla_{\mathbf{x}}\bar{\mathbf{u}}_{\boldsymbol\theta})\mathbf{u}_{\textrm{ref}}\big)\Big]\Big\|^2\right]

  • 2×2 unification: Choosing teacher \hat{\mathbf{u}}_{\boldsymbol\phi} vs. conditional \boldsymbol\epsilon - \mathbf{x}_0 and s = 0 vs. s \le t recovers Consistency Distillation, Flow-Map Distillation, Consistency Training, and MeanFlow.
  • Mandatory stop-gradient \mathrm{sg}[\cdot]: Freezing \boldsymbol\theta inside the target prevents the student from minimizing variance by collapsing \nabla_{\mathbf{x}}\bar{\mathbf{u}}_{\boldsymbol\theta}.

Implementing Flow-Map Error & Slow Time Embeddings

Avoiding JVP Instability in Time Features

In code, flow_map_error evaluates \bar{\mathbf{u}}_{\boldsymbol\theta} and its directional derivative d\bar{\mathbf{u}}_{\boldsymbol\theta}/dt simultaneously in a single jvp call:

def flow_map_error(u, teacher, x0, eps, s, t):
    """Per-example squared error of the average velocity u(x_t, s, t) against
    the stop-gradient target v - (t - s) du/dt; v from teacher, or eps - x0."""
    x_t = d2l.GaussianPath.linear().sample(x0, t, eps)
    if teacher is None:
        v = eps - x0
    else:
        with torch.no_grad():
            v = teacher(x_t, t)
    u_t, du_dt = torch.func.jvp(lambda x, r: u(x, s, r), (x_t, t),
                                (v, torch.ones_like(t)))
    gap = (t - s).reshape(-1, *[1] * (x0.dim() - 1))
    target = (v - gap * du_dt).detach()
    return ((u_t - target) ** 2).flatten(1).sum(1)

Implementing Flow-Map Error & Slow Time Embeddings (cont.)

Avoiding JVP Instability in Time Features

  • Why flow maps use slow sinusoidal time frequencies (slow = (1e-4, 1.0)):
    • Differentiating \sin(\omega t) with respect to t multiplies the feature by its angular frequency: \frac{d}{dt}\sin(\omega t) = \omega\cos(\omega t).
    • Standard diffusion embeddings use \omega up to 64 or 1{,}000, which amplifies JVP gradients inside the target by 64\times to 1{,}000\times and destabilizes consistency training (Lu & Song, 2025). Restricting \omega \le 1.0 keeps time derivatives O(1).

Training Three Few-Step Students on the 2D Mixture

Comparing Distillation vs. Teacher-Free MeanFlow

Using a 20,000-step teacher TimeMLP, we train six random seeds (seeds 2..7) of three student types—consistency (s = 0, teacher), distillation (s \le t, teacher), and MeanFlow (s \le t, no teacher):

 consistency, seeds 2 to 7: mean loss of the last 1,000 updates 0.073 to 0.083
distillation, seeds 2 to 7: mean loss of the last 1,000 updates 0.030 to 0.037
    MeanFlow, seeds 2 to 7: mean loss of the last 1,000 updates 76.136 to 81.287
  • Why distilled losses approach 0 while MeanFlow plateaus at \approx 80:
    • Distilled students regress onto a deterministic function of (\mathbf{x}_t, s, t) supplied by the teacher, reaching \approx 0.03–0.08.
    • MeanFlow substitutes the noisy per-example conditional velocity \boldsymbol\epsilon - \mathbf{x}_0 into both \mathbf{u}_{\textrm{ref}} and the JVP tangent (\mathbf{u}_{\textrm{ref}}, 1), creating a large irreducible conditional variance floor (\approx 76–85).

Benchmarking Few-Step Students on the 2D Mixture

1, 2, and 4 Evaluations Across Six Training Seeds

We evaluate all 18 trained student networks on 20{,}000 Gaussian starts against 50-step teacher Euler and true data:

Benchmarking Few-Step Students on the 2D Mixture (results)

1, 2, and 4 Evaluations Across Six Training Seeds

Mode-weight error for each of the six seeds, the fraction of stray samples between modes, and the within-mode spread:

                          largest weight error, each run       stray      spread
                    data  0.005                                0.9%       0.474
       teacher, 50 steps  0.003                                1.6%       0.461
          consistency, 1  0.003 0.003 0.003 0.003 0.003 0.003  2.0%-2.1%  0.457-0.461
consistency, 2 re-noised  0.003 0.002 0.004 0.004 0.003 0.003  1.2%-1.5%  0.472-0.482
         distillation, 1  0.003 0.003 0.003 0.003 0.003 0.003  1.9%-2.1%  0.446-0.453
         distillation, 2  0.004 0.004 0.004 0.003 0.004 0.004  1.0%-1.1%  0.464-0.473
         distillation, 4  0.004 0.003 0.003 0.003 0.004 0.003  0.8%-1.0%  0.457-0.465
             MeanFlow, 1  0.007 0.002 0.004 0.002 0.006 0.002  4.0%-4.4%  0.314-0.339
             MeanFlow, 2  0.003 0.003 0.007 0.009 0.008 0.007  1.3%-1.7%  0.364-0.379
             MeanFlow, 4  0.005 0.005 0.007 0.010 0.023 0.007  0.7%-0.9%  0.360-0.376

Analyzing the Teacher-Free Mode-Contraction Defect

Why a Pretrained Teacher Velocity Is Worth Having

Comparing the six independent seeds of two-time distillation against teacher-free MeanFlow isolates the exact effect of replacing the teacher’s marginal velocity \hat{\mathbf{u}}_t(\mathbf{x}_t) with \boldsymbol\epsilon - \mathbf{x}_0:

Method & Step Budget Max Mode Weight Error (6 Seeds) Stray Fraction (>3s) Within-Mode Spread Key Finding
True Mixture Data 0.005 (sampling noise) 1.1\% 0.474 (Ground-truth target)
Teacher (50 Euler steps) 0.002 1.5\% 0.471 Matches data distribution closely
Consistency (s=0), 1 jump 0.002–0.006 1.9\%–2.1\% 0.453–0.463 Accurate 1-step weights & spread
Distillation (s \le t), 1 / 2 / 4 jumps 0.001–0.006 (all seeds) 2.0\% \to \mathbf{1.0\%} 0.452–0.463 Preserves spread & deterministic map
MeanFlow (no teacher), 1 / 4 jumps \le 0.007 \to up to \mathbf{0.02} \approx 4\% \to \approx 1\% 0.31–0.34 \to 0.35–0.39 Contracts mode spread by \approx 30\% (1 jump), 15–25\% (4 jumps)

Why noisy JVP tangents contract spread: When \boldsymbol\epsilon - \mathbf{x}_0 drives the JVP tangent, high variance in the correction term (t - s)\,d\bar{\mathbf{u}}/dt causes the student to under-fit the curvature correction—partially reverting toward a coarse Euler stride that shrinks mode variance.

Distilling a Few-Step U-Net Student on Fashion-MNIST

Zero-Initialized Gap Conditioning

To distill our 1.2\text{M}-parameter Fashion-MNIST velocity U-Net into a two-time flow map UNetFlowMap, we initialize the student as an exact copy of the teacher and inject the step gap t - s through a zero-initialized linear layer:

class UNetFlowMap(nn.Module):
    """u(x, s, t): a velocity U-Net, plus a zero-initialized input for the
    gap t - s. The caller passes a copy of the teacher's U-Net."""
    def __init__(self, unet):
        super().__init__()
        # the teacher is an EMA copy with gradients off; the student trains
        self.unet = unet.requires_grad_(True)
        self.gap = nn.Linear(unet.emb_dim, unet.emb_dim)
        nn.init.zeros_(self.gap.weight), nn.init.zeros_(self.gap.bias)

    def forward(self, x, s, t):
        gap = self.gap(d2l.time_embedding(t - s, self.unet.emb_dim,
                                          self.unet.time_freqs))
        return self.unet(x, t, cond=gap)

Distilling a Few-Step U-Net Student on Fashion-MNIST (cont.)

Zero-Initialized Gap Conditioning

  • Warm-starting at the teacher’s velocity: Because self.gap is initialized to zero, \bar{\mathbf{u}}_{\boldsymbol\theta}(\mathbf{x}_t, s, t) = \hat{\mathbf{u}}_{\textrm{teacher}}(\mathbf{x}_t, t) at step 0.

  • 50% diagonal anchor (s = t): Half of each minibatch sets s = t (where the target is simply the teacher’s instantaneous velocity \hat{\mathbf{u}}_{\textrm{teacher}}) so the student never forgets the tangent field while learning long jumps s < t over 5{,}000 updates.

Teacher Euler vs. Student Jumps on Fashion-MNIST

FD Scaling from 1 to 50 Evaluations

Evaluating the teacher (1 to 50 Euler steps) and two distilled students (seed 2, 3 at 1, 2, 4 jumps) on 1{,}000 shared noise images shows a massive few-step gain:

  • 1 evaluation: Teacher Euler collapses onto the gray dataset mean (\mathrm{FD} \approx 160), whereas 1 student jump scores \mathrm{FD} \approx 11.5 (14\times lower).
  • 2 evaluations: Teacher Euler scores \mathrm{FD} \approx 80, while 2 student jumps reach \mathrm{FD} \approx 4.5 to 5 (outperforming 10 teacher steps at about 7).
  • 4 evaluations: Student reaches \mathrm{FD} \approx 3.7, matching 20 teacher Euler steps (3.5 to 4) and within 1.4\times of the 50-step teacher (2.6).

FD at evaluations       1       2       4      10      20      50
teacher            163.74   84.70   27.87    6.82    3.70    2.62
student 2           11.58    4.66    3.62
student 3           11.40    4.59    3.73

Trajectory Preservation: Teacher Euler vs. Student

Comparing 50-Step Teacher, 2-Step Teacher, and 1–2 Student Jumps

UNetFlowMap follows the teacher’s deterministic ODE, so each column starts from the same noise \mathbf{z}_i and yields the same garment:

  • Row 1 vs. Row 2 (Teacher 50 vs. 2 Euler steps): Two Euler steps produce blurry, low-contrast ghosts that often fail to commit to the right garment category.
  • Row 3 vs. Row 4 (Student 1 vs. 2 jumps): Even a single jump (Row 3) recovers the 50-step teacher’s garment silhouette and shade in every column; two jumps (Row 4) sharpen edges and textures to near-teacher quality.

Distribution Matching Distillation (DMD) and Critics

Matching Marginal Densities Instead of ODE Trajectories

\nabla_{\boldsymbol\theta} D_{\textrm{KL}}\big(q_{\boldsymbol\theta, t} \,\|\, p_t\big) = \mathbb{E}_{\mathbf{z}, \boldsymbol\epsilon}\!\left[\big(\underbrace{\nabla \log q_{\boldsymbol\theta, t}(\mathbf{x}_t)}_{\text{online fake score}} - \underbrace{\nabla \log p_t(\mathbf{x}_t)}_{\text{frozen teacher score}}\big)^\top \frac{\partial \mathbf{x}_t}{\partial \boldsymbol\theta}\right]

  • Distribution Matching Distillation (DMD; Yin et al., 2024): Re-noises 1-step fake samples \mathbf{x}_t = (1-t)g_{\boldsymbol\theta}(\mathbf{z}) + t\boldsymbol\epsilon and descends the reverse-KL score difference across noise levels t.
  • Trade-off vs. Flow Maps: Adding a real-image adversarial critic (ADD / DMD2) can surpass teacher FD in 1 step, but abandons the deterministic ODE trajectory bijection \mathbf{z} \leftrightarrow \mathbf{x}_0.

Concept Check: Flow Maps, MeanFlow & Stop-Gradients

Check Your Understanding

Test your understanding of flow-map identities and few-step distillation:

  1. Verifying the MeanFlow identity on 1D Gaussians: For x_0 \sim \mathcal{N}(2, 0.5^2) at s = 0, t = 1, we found \bar{u}(x, 0, 1) = 0.5x - 2 and instantaneous velocity u_1(x) = x - 2. According to the MeanFlow identity \bar{u} = u_1 - (1 - 0)\frac{d}{dt}\bar{u}, what must the total derivative \frac{d}{dt}\bar{u}(x_t, 0, t) equal at t = 1?
  2. Why two-step mode weights skew toward the heaviest mode: On our 2D mixture with weights (0.5, 0.3, 0.2), why do 2 Euler steps on the exact velocity field assign weight 0.64 to mode 1 instead of 0.50?

Answers:

  1. By the MeanFlow identity, \frac{d}{dt}\bar{u} = u_1(x) - \bar{u}(x, 0, 1) = (x - 2) - (0.5x - 2) = \mathbf{0.5\,x}. (Directly: along a trajectory \bar{u}(x_t, 0, t) = (x_t - x_0)/t, so \frac{d}{dt}\bar{u} = (u_t - \bar{u})/t = 0.5x at t = 1.)
  2. At t = 1, the first half-step aims every point toward the global data mean \mathbb{E}[\mathbf{x}_0] = (-0.5, -0.7), which lies spatially closest to the heaviest mode (-2.5, -1.5), pushing extra mass into mode 1’s basin of attraction at t = 0.5.

Concept Check: Flow Maps, MeanFlow & Stop-Gradients (cont.)

Check Your Understanding

  1. Preserving the noise-to-image pairing at 2 NFE: Among a consistency model (s = 0), a two-time flow map (s \le t), and an adversarially distilled 1-step generator, which model produces a 2-evaluation sample that is still a purely deterministic function of the initial noise \mathbf{z}?

Answer:

  1. Only the two-time flow map (\bar{\mathbf{u}}(\mathbf{x}_t, s, t)): It composes two deterministic jumps \Phi_{0.5 \to 0}(\Phi_{1 \to 0.5}(\mathbf{z})) along the same ODE trajectory, whereas consistency and 1-step generators must inject fresh random noise \boldsymbol\epsilon' at t = 0.5.

Summary: Few-Step Generation Paradigms

Key Takeaways

Method Network Output & Domain Training Requirement Multi-Step Mechanism Key Strength & Limitation
Euler ODE Solver Instantaneous \mathbf{u}_t(\mathbf{x}_t) Standard CFM regression K tangent steps Collapses to \mathbb{E}[\mathbf{x}_0] at K = 1; needs 20–50 NFE
Reflow (Rectified Flow) Instantaneous \mathbf{u}_t(\mathbf{x}_t) Retrain on teacher pairs (\hat{\mathbf{x}}_0, \mathbf{z}) Straightened Euler steps Straightens chords, but inherits teacher sample errors
Consistency Distillation Endpoint \Phi_{t \to 0}(\mathbf{x}_t) (s = 0) Pretrained teacher + 1 JVP Stochastic re-noising at t' Strong 1-step jump; 2nd step requires fresh noise \boldsymbol\epsilon'
Flow-Map Distillation Average velocity \bar{\mathbf{u}}(\mathbf{x}_t, s, t) Pretrained teacher + 1 JVP Deterministic jumps t \to r \to s Preserves mode spread & noise-to-sample bijection (2 jumps \approx 15 Euler steps)
MeanFlow Average velocity \bar{\mathbf{u}}(\mathbf{x}_t, s, t) Teacher-free (\boldsymbol\epsilon - \mathbf{x}_0) + 1 JVP Deterministic jumps t \to r \to s No teacher training run, but noisy tangent contracts spread
DMD / Adversarial (ADD) 1-step generator g_{\boldsymbol\theta}(\mathbf{z}) Teacher + fake score / critic Re-noising if >1 step Can match or beat teacher FD in 1 step; loses ODE invertibility