← Latest papers
⚡ electrical engineering

HardFlow: Hard-Constrained Sampling for Flow-Matching Models via Trajectory Optimization

HardFlow is a novel framework that reformulates hard-constrained sampling in flow-matching models as a trajectory optimization problem, using numerical optimal control to ensure precise constraint satisfaction at the terminal time while maintaining high sample quality.

Original authors: Zeyang Li, Kaveh Alim, Navid Azizan

Published 2026-04-28
📖 3 min read☕ Coffee break read

Original authors: Zeyang Li, Kaveh Alim, Navid Azizan

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are using a high-tech GPS to drive a car from your house (the "starting point") to a beautiful destination (the "target data").

In the world of AI, "Flow-Matching" models are like these high-tech GPS systems. They know the general route to get you to a perfect destination—like a realistic image of a cat or a smooth path for a robot arm.

The Problem: The "Strict Traffic Cop"

Usually, when we want to add rules—like "don't drive through that park" or "don't hit that wall"—current AI methods use a "Strict Traffic Cop" approach (called Projection-based sampling).

This cop is incredibly annoying. Every single second you are driving, the cop grabs your steering wheel and forces you to stay on a very specific, narrow path. Because the cop is so obsessed with the rules during the whole trip, you end up driving in a weird, jerky, unnatural way. You might reach the destination, but you arrive exhausted, and the journey was so restricted that you missed all the scenic views (this is "degraded sample quality").

The Solution: The "Professional Race Car Driver" (HardFlow)

The authors of this paper, HardFlow, suggest a much smarter way. Instead of a nagging cop, they imagine you are a Professional Race Car Driver using Trajectory Optimization.

Here is how the "HardFlow" driver works:

  1. Focus on the Finish Line: The driver doesn't care if you drift a little bit near a flowerbed in the middle of the trip. They only care about one thing: When you cross the finish line, you must be exactly where you are supposed to be, and you must not have hit anything.
  2. The "Predictive" Brain: Instead of reacting to every tiny bump, the driver has a "mental simulator" (called Model Predictive Control). Before they turn the wheel, they quickly run a "what if" scenario in their head: "If I turn left now, where will I end up in ten minutes?"
  3. The Smooth Correction: If the driver realizes, "Uh oh, if I keep going this way, I'm going to hit that wall at the end," they don't panic and jerk the wheel. They make tiny, smooth, calculated adjustments to the steering to ensure they glide perfectly into the target zone.

Why is this better?

By treating the problem like a "planned journey" rather than a "series of forced corrections," HardFlow achieves two things at once:

  • Perfect Obedience: It hits the "hard constraints" (like avoiding obstacles or keeping a face looking like the same person) almost perfectly.
  • High Quality: Because the "path" isn't being constantly mangled by a strict cop, the final result looks natural, beautiful, and high-quality.

Real-World Examples from the Paper:

  • Robotics: A robot arm learns to reach a target without ever bumping into a pillar.
  • Maze Navigation: A digital ball zips through a complex maze to a goal without ever touching the walls.
  • Image Editing: You can tell an AI, "Make this person smile," but the "HardFlow" driver ensures the person still looks like the same person (it keeps the "identity" constraint hard), whereas older methods might accidentally turn them into a completely different human!

In short: HardFlow stops micromanaging the journey and starts optimizing the destination.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →