Primal-Dual Flow Matching for Sample-Wise Constrained Generation

Zhengyan Huan, Peter Y. Lu, Shuchin Aeron

TL;DR

Primal-Dual Flow Matching (PDFM) is a new framework for generative models that ensures generated samples satisfy specific, user-defined constraints (like physical laws or chemical rules) with a target probability. Unlike previous methods, PDFM only requires a simple "pass/fail" check for constraints, making it compatible with complex, non-differentiable, or black-box validation tools.

What Problem Does This Paper Address?

Modern generative models, such as Diffusion and Flow Matching (FM), are incredibly good at mimicking the "look and feel" of training data. However, in scientific and engineering applications, "looking right" isn't enough—samples must also be physically consistent. For example, a model generating fluid dynamics must obey conservation laws, and a model generating molecules must produce stable chemical structures.

Existing techniques for "constrained generation" usually suffer from one of three flaws:

  1. Differentiability Requirements: They need the constraint to be a smooth mathematical function so they can calculate gradients.
  2. Structural Assumptions: They only work if the constraint set is "nice" (e.g., convex).
  3. Inference Overhead: They require expensive projections or corrections every time you generate a sample, slowing down the model.

The authors of this paper tackle the challenge of enforcing sample-wise constraints using only a membership oracle—a black box that tells you whether a sample is valid or not—while allowing the user to specify exactly how often the constraint should be satisfied (e.g., "I want 99% of my samples to be valid").

Methods

The researchers build their approach on Flow Matching (FM), a generative framework that learns a "velocity field" to transform simple noise into complex data. To enforce constraints, they frame the training as a Primal-Dual optimization problem.

The "Primal" part aims to match the data distribution (minimizing negative log-likelihood), while the "Dual" part acts as a dynamic penalty that increases whenever the model fails to meet the target constraint satisfaction rate.

The Secret Sauce: The Differentiable Surrogate Since a binary "pass/fail" oracle provides no gradient information (you can't do math on a "Yes/No" answer), the authors introduce a feasibility predictor ($f_\phi$). This is a small neural network trained alongside the generative model to predict the probability that a trajectory will end in a valid sample. This predictor provides the smooth gradients needed to steer the generative model toward the "valid" regions of the data space without needing to differentiate through the actual constraint checker (which might be a complex PDE solver or a legacy script).

Datasets

The authors evaluated PDFM across a diverse set of challenges:

  • Synthetic 2D: A toy problem involving disconnected regions to test distributional matching.
  • $\ell_2$-ball Constraints: High-dimensional (8D and 20D) Gaussian mixtures where samples must stay within a specific radius.
  • Kuramoto-Sivashinsky (KS) Equation: A classic chaotic spatiotemporal PDE. This serves as a benchmark for scientific emulation where samples must satisfy complex dynamical residuals.
  • SOCOFing Fingerprints: Generating fingerprint images that must maintain "ridge connectivity" (checked via a non-differentiable image processing pipeline).
  • QM9 Molecule Dataset: Generating 3D molecular structures that must satisfy valency rules for chemical stability.

Key Insights and Ideas

  • Direct Control: PDFM allows users to set a specific target satisfaction rate ($b$). If you need 95% reliability for a safety-critical application, you can bake that directly into the training objective.
  • Oracle Agnostic: Because it uses a surrogate predictor, PDFM can work with any validation tool—even if it's a non-differentiable black box written in a legacy language like Fortran.
  • Training-Time vs. Inference-Time: By baking the constraints into the model during training, PDFM uses standard, fast sampling at inference time. It doesn't need the slow "corrector" steps required by many other constrained models.
  • Theoretical Grounding: The paper provides mathematical guarantees showing that the learned distribution stays close to the ideal constrained distribution, provided the model is expressive enough.

Key Results

  • Superior PDE Emulation: In the Kuramoto-Sivashinsky task with degraded training data, vanilla FM only produced valid samples 9.8% of the time. PDFM achieved 90.48% satisfaction, significantly outperforming other state-of-the-art methods like PCFM and FM-RE.
  • Molecular Stability: On the QM9 dataset, PDFM improved the rate of stable molecules from 32.77% (vanilla FM) to 48.75%, while actually improving the likelihood (NLL) of the generated samples.
  • Efficiency: PDFM was found to be 2–3x faster to train than FM-RE (a recent competitor) because it doesn't require full trajectory sampling for every single gradient update.
  • Constraint vs. Fidelity: In the 2D synthetic task, PDFM hit a 99.51% satisfaction rate (target 99.5%) while maintaining a lower Wasserstein distance (better data matching) than baselines trained on "cleaned" or truncated data.

Limitations and Future Work

The authors identify two primary limitations:

  1. The "Cold Start" Problem: The feasibility predictor ($f_\phi$) needs both positive and negative examples to learn. If the initial model is so bad that it never generates a valid sample, the predictor can't learn where the boundaries are.
  2. Reachability: PDFM assumes the "valid" region is somewhat reachable from the training data. If the constraints are completely alien to the data distribution, the model may struggle to bridge the gap.

Future work could involve making the "cold start" more robust and applying the framework to even larger-scale scientific simulations where physical consistency is currently the primary bottleneck for AI adoption.

Summary updated

BibTeX
@inproceedings{huan2026primal,
  author = {Zhengyan Huan and Peter Y. Lu and Shuchin Aeron},
  title = {{Primal-Dual Flow Matching for Sample-Wise Constrained Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=5hNRSOnqjv},
}
Figure