TL;DR
Enforcing global constraints in discrete diffusion models typically requires training auxiliary models or enduring massive computational overhead during sampling. This paper introduces Primal-Dual Guided Decoding (SPDD), a training-free, inference-time method that formulates constrained generation as an online optimization problem. By dynamically adjusting token probabilities with an adaptive logit bias, SPDD achieves state-of-the-art constraint satisfaction across text, molecular, and music domains with virtually zero additional computational cost.
What Problem Does This Paper Address?
Discrete diffusion models (such as Masked Diffusion Language Models, or MDLMs) have become a powerful alternative to autoregressive models for generating structured sequences like text, code, and molecular strings. They work by starting from a fully masked state and progressively unmasking tokens.
While these models excel at capturing local syntax, enforcing global property constraints—such as ensuring a generated story contains at least 10 ocean-related words, or a generated molecule has a specific target molecular weight—remains a major challenge.
Current solutions fall into two unsatisfactory camps:
- Classifier-based guidance: Requires training a separate predictor model for every single constraint property, which is computationally expensive and inflexible.
- Inner-loop optimization (e.g., Constrained Discrete Diffusion): Avoids retraining but runs an expensive optimization loop at every single denoising step, slowing down generation by 5× to 20×.
The authors tackle this dilemma by asking: Can we enforce global constraints at inference time, without retraining, and without sacrificing sampling speed?
Methods
The authors introduce Stochastic Primal-Dual Decoding (SPDD). Instead of heuristically shifting token probabilities, they formalize constrained generation as a KL-regularized optimization problem: minimize the divergence from the model's original unconstrained distribution while satisfying the global linear constraint.
By dualizing the constraint, they derive an elegant, closed-form solution for the sampling distribution at each denoising step: $$\alpha_{t\ell j} \propto p_\theta(x_t | x_{t+1}) e^{\lambda_{t+1} b_{\ell j}}$$
Here, $b_{\ell j}$ is the constraint score for token $j$ at position $\ell$, and $\lambda$ is a Lagrangian multiplier that acts as an adaptive external force field. If the model is falling behind on its constraint target, $\lambda$ increases, making constraint-satisfying tokens "energetically cheaper" to sample. If the constraint is met early, $\lambda$ steps down to let the base model generate naturally.
The algorithm updates $\lambda$ online using mirror descent based on the running constraint violation (or "slack").
The full implementation is lightweight and integrates directly into the standard sampling loop:
The authors explore three ways to track this slack:
- Accumulated slack: Aggregates contributions over time (stable and conservative).
- Instantaneous slack: Compares current progress directly to the global target.
- Optimistic slack: Uses Optimistic Mirror Descent (OMD) to predict future constraint satisfaction based on the model's current beliefs.
Datasets
The method was evaluated across three structurally distinct domains:
- Topical Text Steering: Evaluated on 50,000 children's stories from the TinyStories dataset, constraining generation to include $\ge 10$ ocean-related tokens.
- Molecular Design: Evaluated on 1 million drug-like molecules from the ZINC20 database (represented as SMILES strings), enforcing a molecular weight target of $\ge 350\text{ Da}$.
- Music Playlist Generation: Evaluated on a proprietary Spotify dataset in a completion setting (given 20 tracks, generate the next 30) to steer playlists toward specific subgenres (e.g., K-Pop, Synthwave).
Key Insights and Ideas
- The "Force Field" Dynamics: The Lagrangian multiplier $\lambda$ dynamically adapts to the generation's history. As seen in Figure 1, $\lambda$ spikes when the sequence lacks constraint tokens and immediately drops when a valid token is committed. This feedback loop prevents the severe "overshooting" common to static bias methods.
- Mathematical Optimality: The additive logit bias isn't just a heuristic; it is mathematically proven to be the optimal KL-regularized projection. This ensures the model stays as close as possible to its learned data distribution while still satisfying the constraint.
- Plug-and-Play Composability: Because the constraints are handled via independent Lagrangian multipliers, multiple constraints can be enforced simultaneously simply by summing their logit biases. No classifier retraining is required when constraints change.
Key Results
SPDD consistently outperformed all baselines in constraint satisfaction (Pass%) while maintaining excellent distributional fidelity (KL) and baseline-level sampling speeds.
- Virtually Free Sampling: SPDD incurs a mere 1.03× computational overhead compared to unconstrained sampling. In comparison, the training-free baseline CDD achieves lower satisfaction while being 7.28× slower.
- Superior Text Steering: On the TinyStories task, SPDD achieved a 92.10% pass rate, more than doubling CDD's performance (38.00%), while keeping perplexity and diversity stable.
- Zero-Shot Transfer: The authors successfully applied SPDD zero-shot to a much larger 8-billion parameter model (LLaDA-8B) at decode time without any fine-tuning, proving the method is backbone-agnostic.
Limitations and Future Work
- Absorbing-State Constraints: SPDD was primarily evaluated on absorbing-state diffusion models, where token commitments are permanent. If a model makes a poor choice early on, it cannot undo it, making early-stage slack estimation critical.
- Linear Decomposability: The current mathematical formulation relies on linear, token-level decomposable constraints. Extending SPDD to non-decomposable constraints (like molecular QED or text sentiment) will require developing advanced partial-sequence estimators.
- Probabilistic Bounds: The method provides formal probabilistic bounds on constraint violations rather than hard, deterministic guarantees. For safety-critical applications, it may still need to be paired with post-hoc rejection sampling.
Summary updated