Flow map matching

1. Flow map matching (FMM)

The central object in our method is the flow map, which maps points along trajectories of solutions to an ordinary differential equation (ODE)

1.1. Stochastic interpolants and probability flows

Stochastic interpolant: 𝐼𝑑=𝛼𝑑π‘₯0+𝛽𝑑π‘₯1+𝛾𝑑𝑧, where 𝛼0=𝛽1=1,𝛼1=𝛽0=0, and 𝛾0=𝛾1=0.

Probability flow: The probability density of 𝐼𝑑 is the solution to

π‘₯ Μ‡ 𝑑 = 𝑏 𝑑 ( π‘₯ 𝑑 ) , π‘₯ 𝑑 = 0 = π‘₯ 0 ∼ 𝜌 0

where 𝑏𝑑(π‘₯)=𝔼[𝐼̇𝑑|𝐼𝑑=π‘₯]. The drift 𝑏 can be learned efficiently in practice by solving a square loss regression problem

𝑏 = argmin 𝑏 Μ‚ ∫ 0 1 𝔼 [ | 𝑏 Μ‚ 𝑑 ( 𝐼 𝑑 ) βˆ’ 𝐼 Μ‡ 𝑑 | 2 ] 𝑑 𝑑

1.2. Flow map: definition and characterizations

Flow map: The flow map 𝑋𝑠,𝑑:ℝ𝑑→ℝ𝑑 is the unique map such that

𝑋 𝑠 , 𝑑 ( π‘₯ 𝑠 ) = π‘₯ 𝑑 for all ( 𝑠 , 𝑑 ) ∈ [ 0 , 1 ] 2 ,

where (π‘₯𝑑)π‘‘βˆˆ[0,1] is any solution to the ODE.

Tangent condition: Let 𝑋𝑠,𝑑 denote the flow map. Then

lim 𝑠 β†’ 𝑑 πœ• 𝑑 𝑋 𝑠 , 𝑑 ( π‘₯ ) = 𝑏 𝑑 ( π‘₯ ) βˆ€ 𝑑 ∈ [ 0 , 1 ] , βˆ€ π‘₯ ∈ ℝ 𝑑 .

We define 𝑣𝑠,𝑑 as the exact remainder obtained by truncating a Taylor expansion in π‘‘βˆ’π‘  of 𝑋𝑠,𝑑(π‘₯) at first order

𝑋 𝑠 , 𝑑 ( π‘₯ ) = π‘₯ + ( 𝑑 βˆ’ 𝑠 ) 𝑣 𝑠 , 𝑑 ( π‘₯ ) , 𝑣 𝑑 , 𝑑 ( π‘₯ ) = 𝑏 𝑑 ( π‘₯ )

Geometrically, 𝑣𝑠,𝑑 describes the β€œslope” of the line drawn between π‘₯𝑠 and π‘₯𝑑 on a single ODE trajectory.

Some of its useful properties: The flow map 𝑋𝑠,𝑑(π‘₯) is the unique solution to the Lagrangian equation

πœ• 𝑑 𝑋 𝑠 , 𝑑 ( π‘₯ ) = 𝑏 𝑑 ( 𝑋 𝑠 , 𝑑 ( π‘₯ ) ) , 𝑋 𝑠 , 𝑠 ( π‘₯ ) = π‘₯ ,

for all (𝑠,𝑑,π‘₯)∈[0,1]2×ℝ𝑑. In addition, it satisfies

𝑋 𝑑 , 𝜏 ( 𝑋 𝑠 , 𝑑 ( π‘₯ ) ) = 𝑋 𝑠 , 𝜏 ( π‘₯ )

for all (𝑠,𝑑,𝜏,π‘₯)∈[0,1]3×ℝ𝑑. In particular, 𝑋𝑠,𝑑(𝑋𝑠,𝑑(π‘₯))=π‘₯ for all (𝑠,𝑑,π‘₯)∈[0,1]2×ℝ𝑑, i.e., the flow map is invertible.

The flow map 𝑋𝑠,𝑑 is the unique solution of the Eulerian equation,

πœ• 𝑑 𝑋 𝑠 , 𝑑 ( π‘₯ ) + 𝑏 𝑠 ( π‘₯ ) Β· βˆ‡ 𝑋 𝑠 , 𝑑 ( π‘₯ ) = 0 , 𝑋 𝑠 , 𝑠 ( π‘₯ ) = π‘₯ ,

for all (𝑠,𝑑,π‘₯)∈[0,1]2×ℝ𝑑.

1.3. Flow map training

1.3.1. Distillation of a known velocity field

Lagrangian map distillation: Let 𝑀𝑠,π‘‘βˆˆπΏ1([0,1]2) be a weight function satisfying 𝑀𝑠,𝑑>0 and let 𝐼𝑠 be the stochastic interpolant. Then the flow map is the global minimizer over 𝑋̂ of the loss

β„’οΈ€ LMD ( 𝑋 Μ‚ ) = ∫ [ 0 , 1 ] 2 𝑀 𝑠 , 𝑑 𝔼 [ | πœ• 𝑑 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) βˆ’ 𝑏 𝑑 ( 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ,

subject to the boundary condition that 𝑋̂𝑠,𝑠(π‘₯)=π‘₯ for all π‘₯βˆˆβ„π‘‘ and π‘ βˆˆ[0,1]. 𝔼 denotes an expectation over the coupling (π‘₯0,π‘₯1)∼𝜌0(π‘₯0,π‘₯1) and π‘§βˆΌπ‘(0,𝐼𝑑).

Eulerian map distillation: The flow map is the global minimizer over 𝑋̂ of the loss

β„’οΈ€ EMD ( 𝑋 Μ‚ ) = ∫ [ 0 , 1 ] 2 𝑀 𝑠 , 𝑑 𝔼 [ | πœ• 𝑠 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) + 𝑏 𝑠 ( 𝐼 𝑠 ) Β· βˆ‡ 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ,

1.3.1.1. From Distillation to Direct Training: The stopgrad Necessity

The distillation losses β„’οΈ€LMD and β„’οΈ€EMD assume that we have access to the true, smooth drift field 𝑏𝑑. A natural question arises: what if 𝑏𝑑 is unknown and we only have access to samples from the stochastic interpolant, including the noisy velocity 𝐼̇𝑑?

A naive approach might be to simply replace the true drift 𝑏𝑠 with its single-sample, noisy estimate 𝐼̇𝑠 in the loss function. For example, the Eulerian loss would become:

β„’οΈ€ Naive ( 𝑋 Μ‚ ) = ∫ [ 0 , 1 ] 2 𝑀 𝑠 , 𝑑 𝔼 [ | πœ• 𝑠 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) + 𝐼 Μ‡ 𝑠 Β· βˆ‡ 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ,

However, this naive objective is flawed and will not converge to the correct flow map 𝑋.

The issue lies in the relationship 𝑏𝑠(π‘₯)=𝔼[𝐼̇𝑠|𝐼𝑠=π‘₯]. The term 𝐼̇𝑠 is a random variable, while 𝑏𝑠(𝐼𝑠) is its conditional mean. Due to the property 𝔼[π‘Œ2]=(𝔼[π‘Œ])2+Var(π‘Œ), the naive loss implicitly contains an extra variance term:

𝔼 [ | πœ• 𝑠 𝑋 Μ‚ + 𝐼 Μ‡ 𝑠 Β· βˆ‡ 𝑋 Μ‚ | 2 ] = 𝔼 [ | πœ• 𝑠 𝑋 Μ‚ + 𝑏 𝑠 Β· βˆ‡ 𝑋 Μ‚ | 2 ] + 𝔼 [ Var ( 𝐼 Μ‡ 𝑠 Β· βˆ‡ 𝑋 Μ‚ | 𝐼 𝑠 ) ]

This extra variance term acts as a penalty that depends on βˆ‡π‘‹Μ‚. To minimize the total loss, the optimizer is incentivized to find a solution 𝑋̂ with an artificially small gradient βˆ‡π‘‹Μ‚, leading to a biased and incorrect result.

To counteract this, a common technique is to use a stop-gradient operator. The operator, stopgrad(z), allows z to pass through during the forward pass but blocks gradients from flowing back through it during optimization. A corrected Eulerian loss would look like:

β„’οΈ€ EE = ∫ 𝑀 𝑠 , 𝑑 𝔼 [ | πœ• 𝑠 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) + stopgrad ( 𝐼 Μ‡ 𝑠 Β· βˆ‡ 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) ) | 2 ] 𝑑 𝑠 𝑑 𝑑

By blocking the gradient from the noisy term, we can ensure that the expected gradient of the loss is zero at the true solution, making it a valid objective.

This challenge of handling noisy velocities directly is a primary motivation for developing more sophisticated objectives like Flow Map Matching (FMM), which we introduce next. FMM provides an alternative, well-posed loss function for direct training.

1.3.2. Direct training with flow map matching (FMM)

Flow map matching: The flow map is the global minimizer over 𝑋̂ of the loss

β„’οΈ€ FMM ( 𝑋 Μ‚ ) = ∫ [ 0 , 1 ] 2 𝑀 𝑠 , 𝑑 ( 𝔼 [ | πœ• 𝑑 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝑋 Μ‚ 𝑑 , 𝑠 ( 𝐼 𝑑 ) ) βˆ’ 𝐼 Μ‡ 𝑑 | 2 ] + 𝔼 [ | 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝑋 Μ‚ 𝑑 , 𝑠 ( 𝐼 𝑑 ) ) βˆ’ 𝐼 𝑑 | 2 ] ) 𝑑 𝑠 𝑑 𝑑 ,

1.3.3. Progressive distillation

Progressive flow map matching: Let 𝑋̂ be a two-time flow map. Given πΎβˆˆβ„•, let π‘‘π‘˜=𝑠+π‘˜βˆ’1πΎβˆ’1(π‘‘βˆ’π‘ ) for π‘˜=1,…,𝐾. Then the objective

β„’οΈ€ PFMM ( 𝑋 Μ‚ ) = ∫ [ 0 , 1 ] 2 𝑀 𝑠 , 𝑑 𝔼 [ | 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) βˆ’ ( 𝑋 Μ‚ 𝑑 𝐾 βˆ’ 1 , 𝑑 𝐾 ∘ 𝑋 Μ‚ 𝑑 𝐾 βˆ’ 2 , 𝑑 𝐾 βˆ’ 1 ∘ … ∘ 𝑋 Μ‚ 𝑑 1 , 𝑑 2 ) ( 𝐼 𝑠 ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ,

produces the same output in one step as the 𝐾-step iterated map 𝑋̂.

1.3.4. Self-distillation

Self-distillation: The flow map 𝑋𝑠,𝑑 is given for all 0≀𝑠≀𝑑≀1 by 𝑋𝑠,𝑑=π‘₯+(π‘‘βˆ’π‘ )𝑣𝑠,𝑑(π‘₯) where 𝑣𝑠,𝑑(π‘₯) the unique minimizer over 𝑣̂ of

β„’οΈ€ 𝑆 𝐷 ( 𝑣 Μ‚ ) = β„’οΈ€ 𝑏 ( 𝑣 Μ‚ ) + β„’οΈ€ 𝐷 ( 𝑣 Μ‚ ) ,

where ℒ︀𝑏(𝑣̂) is given by

β„’οΈ€ 𝑏 ( 𝑣 Μ‚ ) = ∫ 0 1 𝔼 π‘₯ 0 , π‘₯ 1 [ | 𝑣 Μ‚ 𝑑 , 𝑑 ( 𝐼 𝑑 ) βˆ’ 𝐼 Μ‡ 𝑑 | 2 ] 𝑑 𝑑 ,

and where ℒ︀𝐷(𝑣̂) is any linear combination of the following three objectives:

(i) The Lagrangian self-distillation (LSD) objective,

β„’οΈ€ 𝐷 LSD ( 𝑣 Μ‚ ) = ∫ 0 1 ∫ 0 𝑑 𝔼 π‘₯ 0 , π‘₯ 1 [ | πœ• 𝑑 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) βˆ’ 𝑣 Μ‚ 𝑑 , 𝑑 ( 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ,

(ii) The Eulerian self-distillation (ESD) objective,

β„’οΈ€ 𝐷 ESD ( 𝑣 Μ‚ ) = ∫ 0 1 ∫ 0 𝑑 𝔼 π‘₯ 0 , π‘₯ 1 [ | πœ• 𝑠 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) + βˆ‡ 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) 𝑣 Μ‚ 𝑑 , 𝑑 ( 𝐼 𝑠 ) | 2 ] 𝑑 𝑠 𝑑 𝑑 ;

(iii) The progressive self-distillation (PSD) objective,

β„’οΈ€ 𝐷 PSD ( 𝑣 Μ‚ ) = ∫ 0 1 ∫ 0 𝑑 ∫ 𝑠 𝑑 𝔼 π‘₯ 0 , π‘₯ 1 [ | 𝑋 Μ‚ 𝑠 , 𝑑 ( 𝐼 𝑠 ) βˆ’ 𝑋 Μ‚ 𝑒 , 𝑑 ( 𝑋 Μ‚ 𝑠 , 𝑒 ( 𝐼 𝑠 ) ) | 2 ] 𝑑 𝑒 𝑑 𝑠 𝑑 𝑑 .

Above, 𝑋̂𝑠,𝑑(π‘₯)=π‘₯+(π‘‘βˆ’π‘ )𝑣̂𝑠,𝑑(π‘₯) and 𝔼π‘₯0,π‘₯1 denotes an expectation over the random draw of (π‘₯0,π‘₯1).

1.3.5. Align your flow (AYF)

The first training objective aims to ensure that for a fixed 𝑠, the output of the flow map remains constant as we move (π‘₯𝑑,𝑑) along the PF-ODE.

AYF-Eulerian Map Distillation (AYF-EMD): Let π‘“πœƒ(π‘₯𝑑,𝑑,𝑠) be the flow map. Consider the loss function defined between two adjacent starting time steps 𝑑 and 𝑑′=𝑑+πœ€(π‘ βˆ’π‘‘) for a small πœ€>0,

𝔼 π‘₯ 𝑑 , 𝑑 , 𝑠 [ 𝑀 ( 𝑑 , 𝑠 ) β€– 𝑓 πœƒ ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) βˆ’ 𝑓 πœƒ βˆ’ ( π‘₯ 𝑑 β€² , 𝑑 β€² , 𝑠 ) β€– 2 2 ] ,

where π‘₯𝑑′ is obtained by applying a 1-step Euler solver to the PF-ODE from 𝑑 to 𝑑′. In the limit as πœ€β†’0, the gradient of this loss function with respect to πœƒ gives

βˆ‡ πœƒ 𝔼 π‘₯ 𝑑 , 𝑑 , 𝑠 [ 𝑀 β€² ( 𝑑 , 𝑠 ) sign ( 𝑑 βˆ’ 𝑠 ) β‹… 𝑓 πœƒ 𝑇 ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) β‹… 𝑑 𝑓 πœƒ βˆ’ ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) 𝑑 𝑑 ]

where 𝑀′(𝑑,𝑠)=𝑀(𝑑,𝑠)Γ—|π‘‘βˆ’π‘ |. The AYF-EMD loss naturally generalizes the loss used to train continuous-time consistency models, as it reduces to the same objective when 𝑠=0.

The second approach ensures consistency at timestep 𝑠 instead. This method tries to ensure that for a fixed (π‘₯𝑑,𝑑), the trajectory π‘“πœƒ(π‘₯𝑑,𝑑,Β·) is aligned with that points’ PF-ODE.

AYF-Lagrangian Map Distillation (AYF-LMD): Let π‘“πœƒ(π‘₯𝑑,𝑑,𝑠) be the flow map. Consider the loss function defined between two adjacent ending timesteps 𝑠 and 𝑠′=𝑠+πœ€(π‘‘βˆ’π‘ ) for a small πœ€>0,

𝔼 π‘₯ 𝑑 , 𝑑 , 𝑠 [ 𝑀 ( 𝑑 , 𝑠 ) β€– 𝑓 πœƒ ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) βˆ’ ODE 𝑠 β€² β†’ 𝑠 ( 𝑓 πœƒ βˆ’ ( π‘₯ 𝑑 , 𝑑 , 𝑠 β€² ) ) β€– 2 2 ] ,

where ODE𝑑→𝑠(π‘₯) refers to running a 1-step Euler solver on the PF-ODE starting from π‘₯ at timestep 𝑑 to timestep 𝑠. In the limit as πœ€β†’0, the gradient of this objective with respect to πœƒ converges to:

βˆ‡ πœƒ 𝔼 π‘₯ 𝑑 , 𝑑 , 𝑠 [ 𝑀 β€² ( 𝑑 , 𝑠 ) sign ( 𝑠 βˆ’ 𝑑 ) β‹… 𝑓 πœƒ 𝑇 ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) β‹… ( 𝑑 𝑓 πœƒ βˆ’ ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) 𝑑 𝑠 βˆ’ 𝑣 πœ™ ( 𝑓 πœƒ βˆ’ ( π‘₯ 𝑑 , 𝑑 , 𝑠 ) , 𝑠 ) ) ] ,

where 𝑀′(𝑑,𝑠)=𝑀(𝑑,𝑠)Γ—|π‘‘βˆ’π‘ |.

References

  1. Flow map matching with stochastic interpolants: A mathematical framework for consistency models
  2. How to build a consistency model: Learning flow maps via self-distillation
  3. Align Your Flow: Scaling Continuous-Time Flow Map Distillation