Bellman Optimal Stepsize Straightening of Flow-Matching Models

Bao Nguyen, Binh Nguyen, Viet Anh Nguyen

TL;DR

Flow-matching models generate stunning images but require heavy computation for both sampling and distillation. This paper introduces Bellman Optimal Stepsize Straightening (BOSS), a highly efficient two-phase technique that first uses dynamic programming to find optimal non-uniform sampling steps, and then finetunes the model to straighten the generation path along those specific steps. BOSS drastically reduces the compute needed to distill models for few-step generation while achieving superior image quality compared to standard uniform-step methods.

The Bottleneck in Flow-Matching Generation

Generative models like diffusion and flow-matching (or rectified flows) rely on simulating a continuous probability path that transforms pure noise into a high-fidelity image. Simulating this path accurately requires many sequential steps, formally known as Number of Function Evaluations (NFEs), making generation slow.

To speed this up, researchers use distillation techniques like "reflow" to straighten the probability paths, allowing the model to generate images in just 1 to 8 steps. However, standard reflow assumes uniform step sizes and requires a massive computational budget. For instance, distilling a high-resolution model can take hundreds of A100 GPU days. The authors tackle this bottleneck: How can we adapt a pretrained flow-matching model for few-step generation using only a modest computational budget?

The BOSS Methodology

The authors propose BOSS, which splits the distillation process into two distinct phases to maximize both computational efficiency and image quality:

Phase 1: Bellman Optimal Stepsizes

Instead of blindly using uniform time steps, the authors estimate the local truncation error of an Euler solver across different time intervals. They formulate the search for the optimal $K$-step schedule as a network-flow problem.

Network flow formulation for finding optimal step sizes

By applying a Dynamic Programming algorithm based on the Bellman equation, they efficiently find the exact sequence of step sizes that minimizes the cumulative sampling error. This approach naturally allocates smaller steps to regions of high curvature (near pure noise and the final clean image) and larger steps in the middle.

Phase 2: Straightening

Once the optimal timestamps are found, the authors finetune the pretrained velocity network. They use a custom loss function that encourages the network's velocity predictions to align perfectly with the piecewise linear path defined by those optimal step sizes.

Additionally, the authors experiment with Low-Rank Adaptation (LoRA) during the straightening phase to make the finetuning process highly parameter-efficient, updating only a fraction of the model's weights.

Key Insights

  • Uniform steps are suboptimal: The probability flow ODE trajectories have higher curvature near the start and end. The optimal Bellman schedule adapts to this, significantly reducing overall truncation error.
  • Pre-optimizing stepsizes saves massive compute: By finding the optimal schedule before retraining, the model learns the straightened path much faster. BOSS requires only ~10,000 retraining iterations, bypassing the massive compute wall (300,000+ iterations) of standard reflow techniques.
  • Schedules are transferable: Optimal stepsize schedules exhibit a surprising degree of transferability across different datasets. For example, a schedule optimized for LSUN-Church works well for CelebA-HQ, likely because the curvature patterns of pretrained rectified models are structurally similar across different image domains.

Key Results

The authors evaluated their method on standard unconditional image generation benchmarks, including CIFAR-10 (32x32) and high-resolution (256x256) datasets like CelebA-HQ, LSUN-Church, LSUN-Bedroom, and AFHQ-Cat.

Quantitative comparison of BOSS against baseline reflow methods
  • Quantitative Leap: BOSS significantly outperforms Uniform-Reflow and Distill-K-Reflow baselines. On CelebA-HQ with 6 NFEs, BOSS achieves an FID (Fréchet Inception Distance) of 18.67, compared to 43.57 for Uniform-Reflow.
  • Lightning-Fast Optimization: The dynamic programming step to find the optimal schedule is incredibly lightweight. It takes only ~115 seconds on a single NVIDIA A5000 GPU for the 256x256 datasets.
  • Visual Quality: Images generated with BOSS using just 6 steps visually rival those generated by the heavy, adaptive Runge-Kutta (RK45) solver using over 200 steps.
  • LoRA Efficiency: On CelebA-HQ, a LoRA-4 setup (tuning just 2% of parameters) achieved an FID of 36.70, remaining highly competitive with the full-rank finetuning FID of 33.86.

Limitations and Future Work

While much cheaper than standard reflow, BOSS still requires an upfront computational cost to calculate the local truncation errors and run the dynamic programming algorithm. This is a slight disadvantage compared to purely "training-free" samplers that require zero finetuning.

For future work, the authors suggest extending this framework to distill guided velocity networks (such as text-to-image models that rely on classifier-free guidance). They also propose exploring even cheaper algorithms or heuristics for calculating the optimal Bellman sampling step sizes to further reduce the upfront computational cost.

Summary updated

BibTeX
@inproceedings{nguyen2024bellman,
  author = {Bao Nguyen and Binh Nguyen and Viet Anh Nguyen},
  title = {{Bellman Optimal Stepsize Straightening of Flow-Matching Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=Iyve2ycvGZ},
}
Figure