HardFlow lets generative AI explore before applying safety rules
MIT researchers developed HardFlow, a method that applies hard constraints to a generative AI model’s final output while allowing more freedom during generation. In experiments across robotics, navigation and image editing, it satisfied the required constraints and produced higher-quality solutions than baseline methods.
A generative AI answer can look almost right and still be unsafe. In robot path planning, for example, a route that comes close to avoiding obstacles could still lead to a collision with a human co-worker. MIT researchers have developed HardFlow, a method designed to help generative models meet strict requirements while preserving room to find a useful solution.
“HardFlow addresses safety constraints in AI-generated robot routes, giving the story a mild Terminator lean despite its safety-focused purpose.”Why it scores Terminator
Why enforcing rules at every step can limit results
Generative models create new data by transforming random noise. Pretrained diffusion models such as Stable Diffusion and flow-matching models such as FLUX can be adapted to many tasks, but a plausible result does not necessarily meet every safety, physical or task-specific requirement.
One existing approach, projection-based sampling, repeatedly pushes a model’s intermediate samples to satisfy constraints as generation proceeds. That can keep the process on a narrow track: restricting every partial result may prevent the model from reaching a better final answer. It can also prioritize constraint satisfaction without improving other qualities, such as the length of a robot’s route.
HardFlow takes a different approach to hard constraints: it allows more freedom while the model generates, then enforces the requirements on the final output. The reasoning is that the intermediate steps are discarded; what matters for the task is whether the result that remains is feasible.
Turning generation into an optimization problem
The researchers frame constrained sampling as a trajectory-optimization problem, drawing on tools from optimal control. In this view, the model’s sampling process follows a trajectory that can be steered toward a goal. HardFlow makes adjustments along the way while reserving the strict requirements for the final result.
This framing can account for goals beyond simply obeying a rule. A robot route, for instance, may need to avoid collisions and also be the shortest distance to its destination. The method aims to handle both feasibility and solution quality together.
Applying trajectory optimization to a large neural network presents a computational challenge. To make the problem manageable, the team used the structure of flow-matching models to break it into a sequence of smaller, single-step problems. They then used transformations and approximations to produce an algorithm that can run efficiently at deployment time.
Results across robots, mazes and image editing
In experiments involving robotic manipulation, maze navigation and text-guided image editing, HardFlow achieved perfect constraint satisfaction and consistently outperformed baseline methods on measures of solution quality. The results suggest that a model can retain room to search for better outputs without relaxing requirements that must be met.
In one example, a robotic manipulator avoided obstacles while finding a quick route to a target object. Most competing methods either produced collisions or paths that took significantly more time. HardFlow’s computation time was comparable to or lower than that of most competing methods.
The results cover several kinds of tasks, but the method’s central idea is consistent: guide the model toward a useful answer, and check its nonnegotiable requirements at the point where the answer is complete. That could be relevant wherever an output must obey strict constraints as well as perform well on other measures.
A deployment-time method, with room to extend
HardFlow is designed as a plug-and-play technique that works at deployment time. It can be applied to pretrained generative models without retraining them, which may make it useful in settings where safety rules, physical laws or other strict requirements cannot be violated.
The researchers say future work could extend the framework to settings where the AI model itself is updated. That could allow constraint satisfaction and sample quality to improve in a more adaptive way. For now, the method’s reported experiments show how changing when constraints are enforced can affect both whether a result is acceptable and how well it performs.
The work by lead author Zeyang Li, Kaveh Alim and senior author Navid Azizan appears this week in the IEEE Transactions on Pattern Analysis and Machine Intelligence.
Read next