Skip to content

Understanding Flow Matching

Alexander R Izquierdo edited this page Dec 21, 2024 · 1 revision

Understanding Flow Matching

Flow Matching provides an alternative approach to generative modeling by learning velocity fields that transform samples from a prior distribution to the target data distribution.

Mathematical Framework

The core idea of Flow Matching is to learn a continuous transformation of samples through a velocity field. Given a sample X₀ from a prior distribution (typically Gaussian) and a target sample X₁, we define:

dX_t/dt = V_t(X_t)

where t ∈ [0,1] represents the continuous time parameter and V_t is the learned velocity field.

Optimal Transport Path

The transformation follows the optimal transport trajectory between distributions:

X_t = (1-t)X₀ + tX₁

This provides a direct path in the latent space for training the velocity field.

Time Parameter Sampling

The time parameter t is sampled from a logit-normal distribution where the underlying Gaussian has zero mean and unit standard deviation:

z ~ N(0,1)
t = σ(z)

This sampling strategy ensures better coverage of the transformation space compared to uniform sampling.

Training Objective

The model learns to predict velocities V_t that match the optimal transport path:

L = E_{t,X₀,X₁}[||V_t(X_t) - (X₁ - X₀)||²]

where (X₁ - X₀) represents the ground truth velocity.

Generation Process

During inference, we generate samples by integrating the velocity field:

X_t = X₀ + ∫₀ᵗ V_s(X_s)ds

This integration is typically performed using numerical ODE solvers.

Theoretical Properties

  1. The method optimizes directly in the space of continuous flows
  2. No intermediate distributions or noise scheduling required
  3. Training is based on optimal transport principles
  4. The continuous time formulation provides natural interpolation

Note: This is a distinct approach from the methods used in NovelAI V3, which uses different techniques for image generation. See NovelAI V3 Methods for details on that approach.