Constraint-Aware Flow Matching via Randomized Exploration

Zhengyan Huan, Jacob Boerma, Liping Liu, Shuchin Aeron

TL;DR

This paper introduces two novel methods, FM-DD and FM-RE, to address the common problem of generative models producing outputs that violate specified constraints. FM-RE, in particular, uses a clever randomization strategy to satisfy constraints even when only a membership oracle is available, making it highly versatile.

What Problem Does This Paper Address?

Generative models, like those used for image synthesis, are powerful but often struggle with adhering to specific rules or "constraints." For example, you might want to generate images of faces with a certain number of teeth showing, or medical images that conform to anatomical boundaries. Vanilla generative models, even those that accurately capture the underlying data distribution, frequently produce outputs that break these rules. This is a significant limitation for real-world applications where adherence to constraints is crucial. Existing methods often require strong assumptions about the nature of the constraints (e.g., convexity) or involve complex modifications to the generation process. This paper aims to provide more flexible and effective ways to generate data that satisfies arbitrary constraints.

Methods

The authors propose two main approaches based on Flow Matching (FM):

  • FM-DD (Flow Matching with Differentiable Distance): This method is suitable when a differentiable distance function to the constraint set is available. It modifies the standard FM objective by adding a penalty term that directly penalizes the distance of generated samples from the constraint set. This is a relatively straightforward adaptation.
  • FM-RE (Flow Matching with Randomized Exploration): This is the more novel contribution, designed for scenarios where only a membership oracle (a function that tells you if a point is inside or outside the constraint set) is available. To overcome the difficulty of optimizing with a non-differentiable constraint, FM-RE introduces randomization into the generation process. It uses a two-stage approach:
  • An initial flow is learned using standard FM.
  • For later time steps, a randomized velocity field is introduced. This allows the model to explore the constraint set and learn a "mean flow" that has a high probability of satisfying the constraints. This approach is particularly interesting because it enables gradient-based optimization even with a black-box constraint oracle.

Datasets

The paper evaluates its methods on several synthetic datasets and real-world image generation tasks:

  • Synthetic Datasets:
    • 2D toy examples: Box constraint, disconnected boxes constraint (non-convex).
  • Higher-dimensional constraints: 8-d and 20-d l2 ball constraints.
  • Subspace constraint: Projection onto a 9-D hyperplane.
  • Real-world Image Generation:
    • MNIST digits with "Brightness" (number of white pixels) and "Thickness" constraints.
  • Adversarial example generation for hard-label black-box image classifiers (LeNet-5 on MNIST, ResNet-50 on CIFAR-10).

Key Insights and Ideas

  • Randomization as a Constraint-Satisfaction Tool: The core idea of FM-RE is that introducing controlled randomness can turn a non-differentiable constraint into a probabilistic objective that can be optimized. This is a powerful insight for handling complex, oracle-defined constraints.
  • Two-Stage Approach for Efficiency: FM-RE's two-stage design (deterministic flow for early stages, randomized for later) is not just for constraint satisfaction but also offers computational benefits, especially for harder constraints.
  • Membership Oracle is Sufficient: The success of FM-RE demonstrates that a full understanding of the constraint's geometry (like a distance function) isn't always necessary; a simple "yes/no" oracle is enough to guide the generation process effectively.
  • Balancing Distributional Fidelity and Constraint Satisfaction: The paper highlights the inherent trade-off between generating samples that match the target distribution and ensuring they satisfy constraints. FM-RE provides a framework to navigate this trade-off.

Key Results

  • Improved Constraint Satisfaction: Both FM-DD and FM-RE significantly reduce constraint violation rates compared to standard FM across various synthetic and real-world tasks. For instance, in the MNIST brightness constraint task, FM-RE achieves a violation rate of 5.86%, compared to 9.14% for FM.
  • Competitive Sample Quality: FM-RE generally maintains sample quality (measured by FID and SWD) comparable to standard FM, especially when hyperparameters are tuned well. For example, in the 2-box constraint, FM-RE achieves a SWD of 0.2104, very close to the fine-tuned FM's 0.2755.
  • Versatility of FM-RE: FM-RE demonstrates strong performance on non-convex, disconnected, and even "unclear" constraints like those in adversarial example generation, where only membership information is available.
  • Adversarial Example Generation: FM-RE successfully generates adversarial examples for black-box classifiers, significantly reducing their accuracy (e.g., from 99.1% to 18.7% for LeNet-5 on MNIST).

Limitations and Future Work

  • No Formal Guarantees: While FM-DD and FM-RE significantly improve constraint satisfaction, they do not provide formal guarantees. Excessive constraint pressure (high λ) can degrade sample quality.
  • Computational Cost: Both methods require simulating full trajectories during training, which can be more computationally expensive than standard FM or some inference-time methods (like PDM). However, FM-RE's two-stage approach can mitigate this for complex constraints.
  • Future Work: The authors suggest exploring:
  • Optimal choice of randomization time (to) in FM-RE.
  • Quantifying the "regret" of using a randomized flow compared to an optimal constrained flow.
  • Developing provable guarantees for constraint satisfaction.
  • Extending randomization to other generative frameworks like DDPMs and SDE-based models.

Summary updated

BibTeX
@article{huan2026constraint,
  author = {Zhengyan Huan and Jacob Boerma and Liping Liu and Shuchin Aeron},
  title = {{Constraint-Aware Flow Matching via Randomized Exploration}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2026},
}
Figure