MIT’s HardFlow algorithm helps pretrained generative AI models satisfy strict safety constraints without retraining, for robotics, control, and vision.
Generative AI models like Stable Diffusion and FLUX have gotten remarkably good at producing answers that come close to what’s being asked. For most uses, close enough works fine. But MIT researchers point out a category of problems where that isn’t true at all: safety-critical situations where an output either meets a hard requirement or it doesn’t, with no partial credit.
Picture a robot planning a path across a crowded factory floor. A route that is “nearly correct” might still end with the robot colliding with a co-worker. That’s the exact gap a new MIT-developed technique, called HardFlow, was built to close — giving generative AI models a way to satisfy strict, nonnegotiable constraints without sacrificing the quality of their answers.
“The promise of generative AI is its ability to explore a rich space of possibilities, but the real world places boundaries on which possibilities are acceptable,” says Navid Azizan, the Alfred H. and Jean M. Hayes Career Development Associate Professor at MIT and senior author of the research. “Our approach lets us preserve that generative power while enforcing the nonnegotiable requirements of high-stakes or safety-critical applications.”
He’s joined on the paper by lead author Zeyang Li and co-author Kaveh Alim, both graduate students at MIT. The research appears this week in IEEE Transactions on Pattern Analysis and Machine Intelligence.
The Problem With Constraining Every Step
Today, when developers need a generative AI model to respect hard rules, a common approach is projection-based sampling — repeatedly forcing the model’s in-progress, “intermediate” outputs back into line with the required constraints at every single step of the generation process.
The trouble is that boxing in the entire generation process this way can stop the model from ever reaching a genuinely good final answer. These methods also tend to focus purely on hitting the constraint, missing chances to improve other qualities of the solution — like finding a shorter, more efficient path for a robot to travel.
“For constraint satisfaction, what ultimately matters is the model’s final output, since the internal process is discarded. By not requiring every intermediate step to satisfy the constraints, we give the model more freedom to find high-quality solutions that are still feasible in the end,” says Li.
How HardFlow Steers Without Boxing In
HardFlow’s core idea is to reformulate hard-constrained sampling as a trajectory-optimization problem, borrowing tools from the field of optimal control. That framing lets the system steer a model’s sampling process toward a goal with small, subtle corrections along the way, while only strictly enforcing the hard constraints on the final output.
Making that work at the scale of a real neural network was the hard engineering problem. The researchers leveraged the internal structure of flow-matching models to break the trajectory-optimization problem down into a sequence of smaller, single-step subproblems, then applied a series of transformations and approximations to arrive at something that could actually run efficiently at deployment time — without needing to retrain the underlying model at all.
“Essentially, we transformed the trajectory-optimization problem into something that preserves the key properties of the original problem, but can be solved very efficiently at deployment time,” Azizan says.
Because the method reformulates the task as a true optimization problem, it can also chase additional goals beyond simply satisfying constraints — for instance, finding not just any collision-free path for a robot, but the shortest one.
What Happened When They Tested It
The team ran HardFlow across three very different domains: robotic manipulation, maze navigation, and text-guided image editing. In each case, it consistently satisfied the required hard constraints while outperforming existing baseline methods on solution quality.
In one example, HardFlow let a robotic manipulator avoid collisions with obstacles while also finding the fastest path to its target object. Most competing methods either resulted in collisions or found paths that took meaningfully longer. HardFlow’s computation time, meanwhile, was comparable to or faster than most of the methods it was tested against.
Looking ahead, the researchers want to extend the framework to settings where the underlying AI model itself can also be updated during the process, so that both constraint satisfaction and solution quality can keep improving over time.