TL;DR
This paper introduces an exact and tractable algorithm for enforcing structural constraints (like JSON or SQL schemas) on discrete diffusion language models (dLLMs). By framing finite automata constraints as graphical models and restructuring the linear computation graph into a binary tree, the authors reduce sequential decoding depth from $O(L)$ to $O(\log L)$. This approach guarantees 100% constraint satisfaction with less than 5% wall-clock overhead, preventing the structural collapse typically seen in diffusion models during stochastic sampling.
What Problem Does This Paper Address?
Autoregressive large language models (LLMs) generate text token-by-token from left to right. Enforcing structural constraints—such as ensuring an output matches a specific JSON schema for function calling—is well-understood in this paradigm: you simply mask out invalid tokens at each step based on the current prefix.
However, discrete diffusion language models (dLLMs) break this left-to-right assumption. Instead of generating sequentially, they predict and refine multiple token positions simultaneously from a fully-factorized "mean-field" distribution at each denoising step. Because structural constraints operate globally, masking tokens independently at each position is insufficient; locally valid tokens can easily combine into globally invalid sequences (e.g., generating two decimal points in a single number).
Until now, adapting constrained decoding to dLLMs has been highly inefficient, often relying on rejection sampling that fails under strict budgets. This paper addresses the challenge of performing exact, globally valid constrained decoding for parallel-generation models without sacrificing their inherent speed advantages.
Methods
The authors propose a method to sample exactly from the constrained mean-field posterior at each diffusion step. Their approach relies on two key innovations:
- Automata as Graphical Models: Any regular language constraint can be represented as a finite automaton (FA). The authors view this automaton as a chain-structured graphical model (specifically, a Hidden Markov Model), where latent variables represent valid paths through the automaton, and emissions represent vocabulary tokens. By multiplying the dLLM's factorized token probabilities with the automaton's transition matrices, they construct a tractable product distribution.
- Log-Depth Tree Sampling: Standard ancestral sampling on a chain-structured model requires $O(L)$ sequential steps for a sequence of length $L$, creating a massive bottleneck on GPUs. Inspired by arithmetic circuit theory, the authors restructure this linear chain into a binary tree of prefix-suffix state pairs. This divide-and-conquer approach reduces the sequential depth to $O(\log L)$, unlocking massive parallelization.
The algorithm also recomputes per-token marginal probabilities under the constrained distribution, providing a highly accurate confidence signal to guide the dLLM's remasking schedule.
Datasets
The method was evaluated across five diverse structured-generation tasks using two open-weight dLLMs (Dream-7B and LLaDA-8B):
- Function Calling: xLAM (xlam-function-calling-60k) and the Berkeley Function Calling Leaderboard (BFCL), covering both Live and Non-Live settings in Python and JSON formats.
- Planning: Sudoku (4×4) and Countdown puzzles.
- Code Generation: Spider (a text-to-SQL dataset).
- Math Reasoning: GSM-Symbolic, which modifies standard grade-school math problems with symbolic variables.
Key Insights and Ideas
- The "Format Gap" is Structural, Not Semantic: A striking finding was that switching from JSON to Python format caused unconstrained baseline models to collapse (e.g., Dream's accuracy dropped from 63.9% to 22.4% on BFCL-Live). Enforcing the schema constraint closed this gap entirely, proving that the models possess the underlying semantic knowledge to solve the task but struggle purely with syntax formatting.
- Rescuing Stochastic Sampling: Unconstrained dLLMs suffer from severe performance degradation when switching from greedy decoding ($T=0$) to stochastic sampling ($T=1$). The proposed method completely mitigates this "stochastic collapse," maintaining high accuracy even when sampling diversely.
- The Parallelism Tradeoff: While the tree-structured algorithm actually performs more raw FLOPs than a naive sequential chain (due to matrix multiplications), it dramatically reduces the number of sequential GPU kernel launches. On modern hardware, reducing sequential depth from $O(L)$ to $O(\log L)$ yields a massive net win in wall-clock time.
Key Results
- 100% Guarantee: The method guarantees perfect constraint satisfaction by construction.
- Substantial Accuracy Gains: On the challenging BFCL-Live (JSON) benchmark, the approach boosted Dream-7B's greedy accuracy from 63.9% to 71.5%. More impressively, under stochastic sampling, it rescued Dream-7B from a baseline collapse of 22.3% up to 69.0%.
- Minimal Overhead: Thanks to the log-depth tree formulation, the wall-clock overhead compared to completely unconstrained decoding was kept under 5% for the tree variant, whereas the naive sequential chain variant incurred over 114% overhead.
Limitations and Future Work
The primary limitation is that the framework is strictly bound to constraints expressible as finite automata (regular languages). It cannot natively handle richer, hierarchical constraints defined by Context-Free Grammars (CFGs), such as full programming language syntaxes or deeply nested JSON structures with arbitrary recursive properties. Extending log-depth parallel inference techniques to CFGs represents a vital direction for future work in diffusion-based language generation.
Summary updated