Introduction
Autoregressive Large Language Models (LLMs) generate text sequentially, token by token. To ensure these models produce structured outputs—such as valid JSON or mathematical equations—researchers use "constrained decoding." This technique restricts the model's vocabulary at each step based on a formal grammar or regular expression.
However, the rise of Diffusion LLMs introduces a new challenge. Unlike autoregressive models, diffusion models generate blocks of text in parallel through iterative refinement of "mask" placeholders. Traditional sequential constraints cannot be applied to these parallel architectures without severely distorting the model's underlying probability distribution, often leading to syntactically correct but semantically nonsensical outputs.
The DINGO Framework
To address this, we introduce DINGO, a dynamic programming-based constrained decoding strategy specifically designed for the parallel nature of diffusion models. DINGO ensures that the generated text strictly adheres to a regular expression while mathematically preserving the optimal output distribution.
The DINGO algorithm operates in three primary stages:
- DFA Conversion: User-defined constraints (e.g., a JSON schema) are converted into a Deterministic Finite Automaton (DFA).
- Mask Token Integration: The algorithm treats the diffusion "mask" token ($\bot$) as a non-deterministic transition, allowing the model to explore all valid future states during the refinement process.
- Global Optimization via Dynamic Programming: Instead of making local, greedy decisions at each token position, DINGO employs a dynamic programming approach (akin to the Viterbi algorithm) to find the maximum probability path across the entire block that terminates in a valid DFA state.
Experimental Evaluation
We evaluated DINGO across two primary benchmarks: GSM-Symbolic, which requires generating functionally correct mathematical expressions, and JSON-Mode-Eval, a zero-shot task requiring strict adherence to a JSON schema.
As shown in the results for GSM-Symbolic (Figure 4), DINGO consistently outperforms unconstrained and greedy constrained baselines in both accuracy and parse rate, achieving a perfect 100% parse rate across all models.
Key Results and Insights
The implementation of DINGO yields several critical improvements over standard inference methods:
- Perfect Syntactic Validity: DINGO achieved a 100% parse rate across all tested models and benchmarks. In contrast, unconstrained models often fail to produce valid syntax, particularly in complex tasks like JSON generation.
- Significant Accuracy Gains: On the JSON-Mode-Eval task, DINGO improved functional accuracy significantly. For the LLaDA-8B-Base model, DINGO reached 100% accuracy, while the unconstrained version managed only 57%.
- Minimal Latency Overhead: Despite the complexity of the global optimization, DINGO adds negligible computational cost. For instance, generating a JSON block takes approximately 6.43 seconds with DINGO, compared to 6.37 seconds for unconstrained generation.
Conclusion and Future Work
DINGO demonstrates that it is possible to enforce strict formal constraints on parallel diffusion models without sacrificing output quality or speed. By shifting from local greedy filtering to global probability optimization, DINGO provides a robust solution for structured generation.
Future research will focus on extending this framework beyond regular languages to support Context-Free Grammars (CFGs), which are necessary for complex programming languages with nested structures. Additionally, we aim to explore the application of DINGO in multi-block "semi-autoregressive" setups to maintain global optimality across longer sequences.
Summary updated