arXiv:2610.30920cs.AIOct 2026

Manuscript Offprint

arXiv:2610.30920

DConstrain: Compiling Context-Parameterized Transitions for Diffusion Language Model Constrained Decoding

Shidong Cao, Jing Ma, Wenhao Chai, Yuchen Tian, Lun Du, Da Zheng

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Diffusion language models (DLMs) decode multiple tokens in parallel, so individually valid tokens can be incompatible together under a schema. Exact joint inference over a grammar graph enforces compatibility, but it requires token-labeled successors across many hypothetical parser configurations. Encoding stacks and field histories in compiled states can cause exponential growth, which forces prior exact decoders to fix property orders and exclude valid outputs. We present DConstrain, which compiles schemas into context-parameterized transition programs. Cold compilation specializes token consumption to local grammar states while retaining context-dependent stack operations, environment guards, and caller-dependent deferred parsing symbolically. Tracking field histories as runtime values supports arbitrary property order without enumerating field subsets offline. At runtime, warm compilation binds reached configurations to these programs to construct exact successors, overlapping with the model forward pass because graph construction requires no model scores. Furthermore, token-effect grouping merges tokens with identical compiled effects before runtime contexts are bound, so groups are reused across stacks and environments even when concrete successors differ. Objective-specific score aggregation and token restoration provably preserve both the Viterbi optimum and the token-labeled path distribution of ungrouped inference. Across three benchmarks and two DLM families, DConstrain compiles 100% of BFCL schemas under arbitrary property orders, whereas an optimized finite-state baseline compiles only 71.30–85.81%. Under arbitrary property order, it reduces BFCL end-to-end decoding latency by 6.65–46.26× with 100% schema validity and raises DiffusionGemma’s BFCL accuracy from 37.27% under fixed order to 81.56%.

1 Introduction

Diffusion language models (DLMs) generate text by iteratively denoising multiple tokens in parallel (Austin et al., 2021; Lou et al., 2024; Sahoo et al., 2024; Nie et al., 2025; Ye et al., 2025). Parallel decoding reduces latency and makes DLMs attractive for agentic tasks such as tool calling (Schick et al., 2023; Qin et al.,

†^{\dagger}Corresponding authors.

2024), API interaction, and structured data extraction. These tasks require outputs that strictly follow a schema (Patil et al., 2025; Geng et al., 2025), yet unconstrained DLMs often violate schema rules (Suresh et al., 2025; Dang & Ermon, 2026). In autoregressive (AR) models, schema compliance is enforced by masking invalid next tokens for a fixed left-to-right prefix (Willard & Louf, 2023; Moskal et al., 2025; Dong et al., 2025). This mechanism does not carry over directly to DLMs. Because a DLM fills several masked positions at once, two tokens that are each valid on their own can be invalid together.

Existing DLM constrained decoders follow two main paradigms. Verification-based methods sample masked positions independently and then check whether the proposed output can still be completed (Mündler et al., 2026; Zhang et al., 2026; Jin & Han, 2026). Because independent proposals ignore dependencies among positions, decoding many tokens at once causes frequent conflicts and requires repeated resampling or heuristic fallbacks under finite budgets (Mündler et al., 2026; Jin & Han, 2026). Conversely, automata-based methods enforce compatibility through joint inference (Suresh et al., 2025; Dang & Ermon, 2026; Thimmaiah et al., 2026). For the active denoising window (the canvas), they propagate the grammar position by position into a canvas-specific grammar graph whose paths represent sequences of mutually compatible tokens. The decoder then identifies the highest-scoring path or samples according to the graph's path weights. However, these inference algorithms assume a finite automaton with readily accessible token transitions, leaving the cost of constructing this representation for complex schemas largely unaddressed.

This bottleneck arises because DLM joint inference requires a richer successor-construction interface than AR decoding. An AR decoder only needs a boolean mask of valid next tokens for a single realized prefix (Dong et al., 2025). In contrast, joint inference must compute the exact successor parser configurations for candidate tokens across many hypothetical configurations before any token is committed. Each configuration consists of a local grammar state (a position inside one grammar rule) and a runtime context (a stack of return points and a parsing environment, such as the set of fields already written). Finite-state methods encode runtime contexts as separate automaton states, and DINGO additionally precomputes transitions across the full vocabulary (Suresh et al., 2025). In real schemas, nested objects multiply possible stack contexts, while unordered properties introduce exponentially many field histories. Even context-free grammars (CFGs) can require exponential size to represent all permutations of distinct fields (Ellul et al., 2005). To keep compiled automata tractable, prior exact decoders restrict schemas to a fixed property order (Suresh et al., 2025; Dang & Ermon, 2026; Thimmaiah et al., 2026), excluding valid JSON outputs that the model may prefer.

Our key observation is that context-specific successors need not be compiled as context-specific transitions. Consider a token containing two closing braces, {}}, in a nested JSON object. After the first brace closes the inner object, parsing the remaining brace requires returning to the caller. If the parent still lacks a required field, the token is rejected; otherwise, it may close the parent. The return point depends on the stack, and field completion depends on the parsing environment. These contexts can share one compiled procedure: check field completion, return to the caller, and resume parsing the remaining bytes. Rather than precomputing successors for every combination of stack and field history, we compile how to compute them with the runtime context left as a parameter. This separation allows exact successors to be constructed at runtime without enumerating all possible contexts during compilation.

Building on this insight, we propose DConstrain, which compiles schemas into context-parameterized transition programs (Figure 1). Cold compilation specializes token consumption to local grammar states: it precomputes byte-level parsing and local transitions wherever inputs are known, and retains context-dependent stack operations, environment guards, and deferred parsing symbolically. Tracking field histories as runtime values supports arbitrary property order without enumerating field subsets offline. At runtime, warm compilation instantiates these programs for configurations reachable in the current canvas, resolves context-dependent operations, and constructs the exact successor relations required for joint inference. Since warm graph construction does not require model scores, it overlaps with the model forward pass. Finally, token-effect grouping identifies equivalent compiled token effects during cold compilation, before runtime contexts are bound. The resulting groups can be reused across different stacks and environments, sharing successor computation even when the concrete successors differ across contexts. Objective-specific score aggregation and token restoration preserve the exact Viterbi optimum and token-labeled path distribution.

Our contributions are summarized as follows:

• Successor-Construction Bottleneck. We identify token-labeled successor construction as the primary scalability bottleneck in automata-based DLM decoding. Materializing context-specific transitions incurs combinatorial growth with nesting and field histories. Even CFGs can require exponential size for arbitrary permutations of distinct fields, motivating fixed property orders in prior exact decoders.

• Context-Parameterized Compilation. We introduce context-parameterized transition programs paired with a two-stage compiler and compile-time token-effect grouping. We prove that program execution preserves the reference successor relation and that grouping preserves both the Viterbi optimum and the full token-labeled path distribution of ungrouped inference. The compiled programs can be reused by any constrained-decoding algorithm that consumes token-labeled grammar successors.

• Exact Unordered Decoding. Across three structured-output benchmarks and multiple DLM tokenizers, DConstrain substantially improves compilation coverage and latency under arbitrary property order. On BFCL, exact unordered constraints also improve task accuracy over both fixed-order constraints and unconstrained decoding.

References (91)