TL;DR
This paper introduces two novel frameworks, FM-DD and FM-RE, designed to incorporate sample-wise constraints into Flow Matching generative models. By leveraging either differentiable distance functions or randomized exploration via a membership oracle, these methods drastically reduce constraint violations without sacrificing generation quality—even when dealing with complex, non-convex, or black-box constraints.
What Problem Does This Paper Address?
Generative models like diffusion and flow matching are exceptional at capturing complex data distributions. However, they frequently struggle to respect hard boundaries or rules (constraints)—even if every single sample in the training dataset perfectly satisfies them. This is a major hurdle for real-world applications, such as generating physical simulations that must obey conservation laws, or creating images with strict attribute requirements.
Existing solutions typically require the constraint set to be simple and convex, or they demand explicit mathematical knowledge of the boundary geometry. This paper tackles the much harder, more general problem: how do we enforce constraints when we only have a distance function (FM-DD), or worse, when the constraint is a complete black box that only gives us a "yes/no" answer about whether a sample is valid (FM-RE)?
Methods
The authors build upon the versatile framework of Flow Matching (FM) and propose two distinct constraint-aware variants depending on what information is available:
- FM-DD (Differentiable Distance): If a differentiable distance function to the constraint set is known, the authors simply add a penalty term to the standard Flow Matching objective. This penalizes the model during training if its trajectories end up outside the valid region.
- FM-RE (Randomized Exploration): When constraints are defined by a non-differentiable black-box oracle (an indicator function), standard gradient-based optimization fails because gradients vanish everywhere except right on the boundary. To bypass this, the authors introduce a randomized velocity field (adding noise) during the later stages of the generation trajectory ($t \ge t_0$). This transforms the deterministic output into a random variable, allowing them to use a policy-gradient-like "log-derivative trick" (similar to REINFORCE in reinforcement learning) to optimize the model based on oracle feedback.
To make FM-RE computationally efficient, they introduce a two-stage training approach: the model learns a standard deterministic flow for the first part of the trajectory ($t < t_0$), and only activates randomized exploration at the very end ($t \ge t_0$) where the constraints actually matter.
Datasets
The authors evaluated their methods across a diverse set of synthetic and real-world benchmarks:
- 2D Toy Problems: A simple box constraint and a highly challenging, non-convex, disconnected "2 boxes" constraint.
- High-Dimensional Synthetic Problems: 8D and 20D $\ell_2$ balls, alongside a 10D space projected onto a 9D hyperplane (a subspace constraint with an empty interior).
- MNIST Attributes: Modified MNIST generation tasks requiring specific discrete attributes, namely Brightness ($\ge 100$ white pixels) and Thickness (maximum digit thickness strictly between 2 and 3 pixels).
- Black-Box Adversarial Generation: Generating adversarial images using standard MNIST and CIFAR-10 datasets to fool pre-trained LeNet-5 and ResNet-50 classifiers.
Key Insights and Ideas
- Randomization Smooths the Black Box: Injecting noise into the flow allows the model to "explore" the boundaries of a black-box constraint. This effectively turns a discrete pass/fail oracle into a smooth, differentiable probability of satisfaction.
- Late-Stage Exploration Saves Compute: Instead of randomizing the entire generation path, running a standard deterministic flow for the first part ($t < t_0$) and only introducing randomized exploration at the end ($t \ge t_0$) provides an excellent trade-off between distribution matching and constraint satisfaction while drastically reducing training time.
- Loosest Requirements in the Literature: As shown in the comparison table above, while alternative methods like Mirror Diffusion or Reflected Flow Matching require convex sets or explicit boundary equations, FM-RE works with any constraint that can be queried as a black box.
Key Results
- Drastic Reduction in Violations: In 2D synthetic tests, both FM-DD and FM-RE significantly cut down on constraint violations compared to vanilla FM while maintaining low Sliced Wasserstein Distance (SWD). For the disconnected "2 boxes" task—where many baselines cannot even be applied—FM-RE achieved excellent distribution alignment.
- High-Dimensional Success: On the 20D $\ell_2$ ball task, FM-RE reduced the constraint violation rate from 90.82‰ (vanilla FM) to just 2.513‰.
- Complex Attribute Handling: For MNIST attribute generation, FM-RE successfully generated highly realistic digits satisfying complex thickness constraints where other baselines were completely inapplicable.
- Effective Black-Box Adversarial Attacks: When applied to adversarial example generation, FM-RE successfully fooled hard-label black-box classifiers. It dropped LeNet-5's accuracy on MNIST from 99.1% to 18.7% and ResNet-50's accuracy on CIFAR-10 from 95.3% to 28.2% using subtle, generatively produced perturbations.
Limitations and Future Work
- No Strict Guarantees: Unlike reflection-based methods, FM-DD and FM-RE significantly minimize violations but do not mathematically guarantee zero violations at test time.
- Computational Overhead: Training requires simulating full trajectories to evaluate the terminal constraints, which increases training time compared to vanilla FM (e.g., FM-RE took significantly longer on complex tasks like CIFAR-10).
- Future Directions: Promising future work includes finding an automated, optimal choice for the randomization start time ($t_0$), deriving provable guarantees for constraint satisfaction, and extending randomized exploration to other generative frameworks like DDPMs or SDE-based diffusion models.
Summary updated