· Masked / discrete diffusion, Reasoning · Source

Constrained Decoding for Diffusion Language Models via Efficient Inference over Finite Automata

SourceFull paper

Article overview

Verdict

A strong method for finite-automaton constraints: it enables exact globally constrained sampling and 100% syntactic validity, substantially improving structured generation with small overhead. Its scope is limited to regular constraints, and it does not correct semantically wrong but schema-valid values.

Main idea

Represent a finite automaton as a chain graphical model and exactly combine it with the diffusion language model’s factorized distribution at every denoising step. Forward–backward inference and tree-based sampling preserve the target constrained distribution, including under stochastic generation and arbitrary remasking schedules.

Mechanism

Specification: the automaton state is the current position and automaton state; emission weights are token probabilities from the factorized denoising posterior, restricted to allowed transitions. Forward–backward messages incorporate accepting states and weight each edge by the valid-suffix partition function; for NFAs, all edges between state pairs are aggregated. At each denoising step, constrained marginals support sampling and remasking. For parallel inference, skip-transition products are built bottom-up, then midpoint states are sampled recursively; segments are conditionally independent, yielding exact sampling with O(log L) depth and O(L(|S|³+|E||V|)) work. Reproduction: (1) build a DFA/NFA constraint; (2) obtain factorized token scores; (3) run state-space forward–backward inference; (4) use marginals for remasking and constrained sampling; (5) optionally apply the tree sampler and compare it with edge-space or sequential sampling. Training details are absent: the method is presented as a decoding/inference procedure.

What this is useful for

The method is useful for tool calling, JSON/schema decoding, fixed-cell Sudoku constraints, and other DFA/NFA-specifiable tasks, especially when guaranteed syntactic validity, stochastic sampling, or few denoising steps are required. Tree sampling is particularly suitable for GPU parallelism and reducing the critical path.

Risks / not proven

The method directly covers only finite automata and does not extend to richer context-free grammars. It cannot fix schema-valid semantic errors such as wrong arguments, over-specified locations, or omitted inferable optional fields. For NFAs, the pre-reweighting distribution depends on the number of accepting paths, so the intended automaton semantics must be specified. Further details on training, memory use, and actual scaling to longer sequences are not provided.

Full abstract

Constrained decoding is essential for serving LLMs, ensuring that generated outputs follow specific structures such as JSON schema-formatted function calls. Existing systems are designed for autoregressive models and assume left-to-right generation, masking out invalid next tokens at each step. Diffusion language models, however, break this assumption: they sample multiple positions simultaneously from a fully-factorized mean-field distribution at each denoising step. In this paper, we present an exact and tractable algorithm for sampling from the constrained mean-field posterior under any constraint expressible as a finite automaton. Viewing finite automata as graphical models, we obtain tractable representations of the constrained distribution that enable efficient inference. The approach guarantees constraint satisfaction by construction, supports both greedy and sampling-based decoding, and is compatible with parallel and block-wise decoding under arbitrary remasking schedules. Applying depth-reduction techniques from arithmetic circuit theory, we further reduce sampling depth from linear to logarithmic in the sequence length. Empirical evaluations on Dream-7B and LLaDA-8B show substantial accuracy gains across various tasks including function calling (xLAM, BFCL), planning (Sudoku, Countdown), text-to-SQL (Spider), and math reasoning (GSM-Symbolic), with little inference overhead relative to unconstrained decoding. For example, on BFCL-Live, our approach improves Dream-7B's greedy decoding accuracy from 63.9% to 71.5%, and stochastic sampling accuracy from 22.3% to 69.0%, where the unconstrained baseline collapses, with under 5% wall-clock overhead.

Source

BibTeX · RIS · Markdown · JSON