License YOLO
Back to Ultralytics Glossary

Rectified Flow

Rectified flow trains a model to move noise to data along straight lines, so images need few sampling steps. Covers training, reflow, SD3, and FLUX.

Rectified flow is a generative modeling method that learns a velocity field carrying samples from a simple distribution, usually Gaussian noise, to the data distribution along paths that are as straight as possible. Training is plain regression: pair a noise sample with a data sample, pick a point on the straight line between them, and teach a neural network to predict the line's direction. Generation integrates the learned velocity with an ordinary differential equation (ODE) solver, the same machinery behind neural ODEs, and straight paths can be followed in a few large steps. Xingchao Liu, Chengyue Gong, and Qiang Liu of the University of Texas at Austin introduced the method in September 2022 in Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow, alongside the closely related flow matching from Yaron Lipman and colleagues at Meta.

How Rectified Flow Is Trained#

For noise x0 and data x1, the point x_t = (1 - t) * x0 + t * x1 moves from noise at t = 0 to data at t = 1 with the constant velocity x1 - x0. The network v(x_t, t) is trained to predict that velocity with a squared-error loss function over random pairs and random times. Many lines pass through any given point, so the network learns their average direction, and the ODE paths it defines never cross each other but bend wherever lines heading to different data points meet. A one-dimensional rectified flow in PyTorch learns to turn Gaussian noise into two clusters at -2 and +2:

import torch
from torch import nn

torch.manual_seed(0)
velocity = nn.Sequential(nn.Linear(2, 64), nn.SiLU(), nn.Linear(64, 64), nn.SiLU(), nn.Linear(64, 1))
optimizer = torch.optim.Adam(velocity.parameters(), lr=1e-3)

for step in range(3000):
    x0 = torch.randn(256, 1)  # noise
    x1 = 2.0 * torch.sign(torch.randn(256, 1)) + 0.1 * torch.randn(256, 1)  # data: two modes at -2 and +2
    t = torch.rand(256, 1)
    xt = (1 - t) * x0 + t * x1  # a point on the straight line from noise to data
    loss = ((velocity(torch.cat([xt, t], dim=1)) - (x1 - x0)) ** 2).mean()  # regress the line's direction
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

# Generate by Euler integration of dx/dt = v(x, t), with different step counts
for steps in [1, 2, 4, 32]:
    x = torch.randn(10000, 1)
    with torch.no_grad():
        for i in range(steps):
            x = x + velocity(torch.cat([x, torch.full_like(x, i / steps)], dim=1)) / steps
    near_mode = ((x.abs() - 2).abs() < 0.3).float().mean()
    print(f"{steps:>2} Euler steps: {near_mode:.0%} of samples within 0.3 of a mode")

With one Euler step, 0% of samples land near a mode: at t = 0 the average direction from every noise point leads to the data mean of 0, halfway between the clusters. Two steps put 39% of samples within 0.3 of a mode, four steps 81%, and 32 steps 96%, because the learned paths bend toward the clusters and only small steps follow the bend.

Reflow: Straightening the Paths#

Reflow, called recursive rectification in the paper, removes those bends. The trained flow generates a set of (noise, sample) pairs, and a new flow trains on those pairs instead of random ones. Each pair is already joined by a path of the first flow, so the straight lines between pairs rarely conflict, and the paper proves the new coupling never increases the transport cost. Repeated reflows give nearly straight paths, and the authors reported high-quality images and image translations with a single Euler step:

flowchart TD
    A["Pair random noise with random data"] --> B["Train velocity on straight lines"]
    B --> C["Generate a sample from each noise draw with many ODE steps"]
    C --> D{"Paths straight enough?"}
    D -- "No" --> E["Reflow: pair each noise draw with its own sample"]
    E --> B
    D -- "Yes" --> F["Generate in one or a few steps"]

The same team applied reflow and knowledge distillation to Stable Diffusion 1.5 in InstaFlow (2023). Its one-step model scored an FID of 23.3 on MS COCO 2017-5k, against 37.2 for progressive distillation, generated an image in 0.09 seconds, and cost 199 A100 GPU days to train.

Rectified Flow in Text-to-Image Models#

Stability AI's Stable Diffusion 3 paper, Scaling Rectified Flow Transformers for High-Resolution Image Synthesis (March 2024), compared training formulations and chose rectified flow with training times drawn from a logit-normal distribution, which concentrates training on the middle of the path where predicting the velocity is hardest. The model pairs that objective with a multimodal diffusion transformer (DiT) operating in a latent space. Black Forest Labs, founded by former Stability AI researchers, describes its FLUX.1 dev model as a 12-billion-parameter rectified flow transformer, and its distilled FLUX.1 [schnell] variant generates in one to four steps. These text-to-image models are a common source of synthetic data for vision training. Ultralytics Platform brings text-to-image generation into dataset curation with Generate Similar Images: from one dataset image it writes new scene descriptions, generates up to 16 variations, and adds the ones you keep to the dataset without labels, ready for annotation.

  • Flow matching: The general framework for training ODE generators by regressing velocities along chosen probability paths. Rectified flow's straight line between independent noise and data is its most widely used path, and the two names are often used interchangeably.
  • Diffusion models: Add noise along a schedule whose probability-flow paths curve, and their deterministic samplers typically take 20 to 50 steps.
  • Normalizing flows: Map noise to data through a fixed stack of invertible layers trained by exact maximum likelihood.
  • Consistency models: Learn to jump from any point on a curved trajectory straight to its end, so a single network call can produce a sample.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning