Manuscript Offprint
arXiv:2609.35609Twist, Don't Tilt: Trajectory-Exact Constrained Decoding for Masked Diffusion Models
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ABSTRACT
Constrained decoding for Masked Diffusion Language Models (MDLMs) aims to ensure that generated outputs satisfy a specified structure or syntax constraint. MDLMs generate outputs by repeatedly unmasking masked positions present in their current state. Recent strategies for constrained decoding constrain the model's per-step mean-field posterior (which factorizes over masked positions) by enforcing the desired constraint with an automaton. The resulting chain-structured factor graph allows exact constrained sampling via dynamic programming. However, despite each draw being exact and constraint-satisfying, we prove that their composition, in general, tilts away from the model's relative probabilities over valid trajectories, thus leading to trajectory bias. We derive an exact expression for this bias as a product of ratios measuring how valid continuation mass changes when the denoiser is reconditioned, and characterize when the bias vanishes. We then correct the bias by introducing TWISTER, the first automaton-twisted Sequential Monte Carlo decoder for MDLMs, using the step-exact decoder as the proposal. We show that for regular language constraints, the Feynman–Kac correction is exactly computable, with the twists obtained efficiently using quantities pre-computed for step-exact sampling. We prove that the resulting Feynman–Kac model targets the unbiased Doob h-transformed path law conditioned on constraint satisfaction.
Dang & Ermon TWISTER TWISTER matched rejection split floor rejection MC noise

(a) OWT-130M

(b) DREAMCODER-7B-INST

(c) DREAM-7B-BASE
Figure 1: Trajectory bias in constrained decoding of MDLMs captured by the Total Variation Distance (TVD) between the Doob h-transformed native path law (rejection sampling) and the step-exact automaton-constrained distribution (Dang & Ermon (2026), TWISTER and TWISTER ) across denoising steps. For "a.*".
1 INTRODUCTION
Masked Diffusion Language Models (MDLMs) (Sahoo et al., 2024; Nie et al., 2025; Xie et al., 2025; Ye et al., 2025) are increasingly used for generating text, code, and other data, that may require their outputs to adhere to a specified format structure (syntax), e.g., a JSON schema.
Unlike autoregressive Large Language Models (LLMs), MDLMs decode by repeatedly denoising a masked input; they first predict mask-free token-categoricals over the masked positions, and then retain only a scheduled subset of these predictions. Therefore, the generation order depends on the sequence of these scheduled subsets of positions and is not a left-to-right prefix like in LLMs. This creates a different kind of constrained decoding problem. Suresh et al. (2025) introduced DINGO, an MDLM algorithm for regular languages, which used maximum a posteriori (MAP) decoding over the chain-structured factorization of the model's automaton-constrained posterior. While DINGO is mode-seeking, Dang & Ermon (2026) proposed an algorithm for instead sampling (exactly) from the automaton-constrained posterior at each step using Forward-Filtering Backward-Sampling (FFBS) (Carter & Kohn, 1994).
We show that sampling locally from the automaton-constrained posterior at each step, although exact, is still biased when composed across steps, thus deviating from the globally constrained distribution. The bias arises because the denoising process only retains a scheduled subset of the sampled tokens and discards the rest when producing the next intermediate state. The resulting clamped-partition sum is the total constraint-valid probability mass obtained by fixing (or clamping) the retained predictions to the successor state and marginalizing the discarded ones under the current-state-conditioned MDLM. At the next step, the same positions (discarded in the previous step) are reevaluated under the successor-state-conditioned MDLM, producing a new local-partition sum. The ratios of the clamped-partition sum to the local-partition sum tilt the resulting path law relative to the globally constrained one, which we model via the Doob h-transform (Doob, 1957) of the native path law, conditioned on constraint-satisfaction. The tilt manifests as trajectory bias. Figure 1 shows the trajectory bias when sampling locally from the automaton-constrained posterior using a step-exact decoder, relative to the native decoder conditioned on constraint satisfaction, for different models.
Unlike locally constrained LLM decoding, which ignores future valid mass (Park et al., 2024; Dang et al., 2026), step-exact MDLM decoding accounts for this mass exactly, but under a denoiser frozen at the current state. When these exact local steps are composed, reconditioning the denoiser can change the valid mass and bias the resulting distribution. We correct the bias by introducing TWISTER, which uses a Feynman–Kac correction with the local and clamped-partition sum ratios as the incremental potentials. The correction requires quantities already computed by FFBS of the step-exact sampler proposed by Dang & Ermon (2026), making it exactly and efficiently computable.
2.1 DETERMINISTIC FINITE AUTOMATA AND REGULAR LANGUAGES
A deterministic finite automaton (DFA) over a finite alphabet is a tuple: , where is a finite set of states, is the initial state, is the set of accepting states, and is the transition function. A word is accepted by a DFA if the DFA ends in an accepting state after consuming , i.e., .
Definition 2.1. [Regular Language] The language C recognized by a DFA is the set of all words accepted by it: . A language is regular if it is recognized by a DFA.
2.2 MASKED DIFFUSION LANGUAGE MODELS
MDLMs generate mask-free (or clean) token sequences from partially/fully masked sequences, by repeatedly unmasking the masked positions (Sahoo et al., 2024).
Let be a finite vocabulary of clean tokens, be the mask token, and the augmented token space. denotes a random state (an -length token sequence) and is its realization. The masked positions of are given by: , and is the -th token in .
is the DFA's transition function extended from symbols in to words in (Farzan et al., 2022).
Starting from a masked state , an MDLM evolves as a Markov chain over a finite number of denoising steps to produce a clean state .
The transition (Markov) kernels can be constructed from the three main components of MDLMs. For with , the denoiser outputs categoricals over , where is the -simplex. The token predictions are conditionally independent given , so the denoiser's posterior factorizes over . The scheduler retains some of these factors by drawing a reveal set from some policy such that and is non-empty. The set is the subset of 's masked positions that will be revealed for step . The policy can be uniform (Nie et al., 2025), confidence-based (Wu et al., 2026), entropy-based (Ben-Hamu et al., 2025), etc. Lastly, the decoder independently samples from for , and commits the sampled tokens (retaining 's tokens in the remaining positions) to produce the next state . Since denoising is monotone unmasking, we also use to denote the revealed set of positions between steps and .
Definition 2.2. [Native Joint Kernel] Transition from to and is:
MDLMs can denoise only by unmasking which necessitates in Definition 2.2 . The native kernel is obtained by marginalizing out from Eq. (1). A denoising trajectory is then a sequence of states derived through repeated applications of the native kernels on the corresponding intermediate states starting from the initial state .
Definition 2.3. [Native Path Law] The distribution of denoising trajectories conditioned on :
2.3 TWISTED SEQUENTIAL MONTE CARLO
Sequential Monte Carlo (SMC) is used for approximating trajectory distributions as it performs importance corrections incrementally while building the trajectory (Liu, 2004b) . It approximates them using weighted particles, by propagating, reweighting, and resampling them as trajectories grow. It implements the Feynman–Kac model (Del Moral, 2004).
Definition 2.4. [Feynman–Kac Model] A Feynman–Kac model defines an unnormalized trajectory distribution for , as a product of proposal kernels M and non-negative potentials G:
However, when the target includes only a terminal weight, standard SMC receives no guidance during intermediate steps. Twisted SMC uses twist functions to move this information into incremental potentials, enabling particles to be guided as their trajectories grow (Whiteley & Lee, 2014).
Definition 2.5. [Twist-Constructed Potentials] Consider a Markov path distribution and a non-negative terminal weight . Let be twist functions such that for and . Given proposal kernels , the potentials are defined as:
Substituting the potentials from Eq. (4) into Eq. (3) gives . Therefore, the model targets at . The intermediate twists do not alter it, but move its information into the incremental potentials used to guide particles. The ideal twist at is the expected terminal weight under the remaining native transitions, i.e., the exact lookahead or continuation probabilities.
§We use [N] as the universe for set operations of a state’s positions: , , etc.
¶Importance Sampling performs importance corrections only after a trajectory is built (Liu, 2004a).
3 STEP-EXACT DOES NOT MEAN TRAJECTORY-EXACT
Constrained decoding in MDLMs operates along two axes: state positions and denoising steps . At denoising step , a step-exact decoder draws a clean sequence from the denoiser's automaton-constrained posterior (conditioned on ) that satisfies the regular language constraint , i.e., . Only 's positions in the reveal set are committed to , while the remaining are discarded. A draw can therefore be exact at every step without the resulting trajectory following the native path law (Definition 2.3) conditioned on constraint-satisfaction .
Throughout the paper, we assume: (1) complete reveal at the terminal denoising step ; and (2) full support of the denoiser's predictions for all and for all . We follow Koo et al. (2024) to lift the DFA from symbols in to tokens in the model's vocabulary .
We now formally characterize the trajectory bias introduced by step-exact decoding. We start by defining the target path law, i.e., the native decoder's path law conditioned on constraint-satisfaction, using the Doob h-transform (Section 3.1). Next, we derive the transition kernels of the step-exact decoder (Section 3.2), and show that the involved partition sums are lookahead (valid-continuation probabilities) under a frozen denoiser, and thus step-exact decoding is a frozen Doob transform re-frozen at every step (Section 3.3). Finally, we show that re-freezing is the trajectory bias (Section 3.4).
Definition 3.1. [Unbiased Constrained Decoder] For an initial state and constraint , let be the support of native trajectories satisfying . A constrained decoder with path law is unbiased if its support is and, for every , ,
i.e., the constrained decoder does not alter the relative probabilities of constraint-valid trajectories.
3.1 DOOB-TRANSFORMED DECODER
In order to characterize trajectory bias, we first need the path law of a constrained decoder that is conditioned to satisfy , and is unbiased in the sense of Definition 3.1. The native path law is unconstrained and so does not satisfy by itself. We obtain the unbiased constrained decoder by terminally conditioning on satisfying , i.e., ; using the Doob -transform (Doob, 1957). The Doob -transform conditions Markov processes to satisfy specific constraints, by tilting their transition kernels towards states compatible with highly-probable constraint-valid continuations that are given by the lookahead .
Definition 3.2. [Doob Kernel] For the native kernels (Definition 2.2) and their exact lookahead , with for all in the support of , their Doob h-transform gives:
, is the exact lookahead of and .
Proposition 3.3. [Doob Path Law] The Doob path law is the product of the Doob kernels:
Proof sketch. The product of the Doob kernels for , gives the native path law from Definition 2.3; and the -ratios telescope to , thus giving Eq. (6).
Importantly, the Doob path law from Proposition 3.3 is unbiased as it prunes all trajectories with terminal state , but does so without altering the relative probabilities of the valid trajectories under . This follows from Eq. (6), where the Doob path law is proportional to up to a factor which is constant for a fixed initial state . The Doob terminal law can be obtained by marginalizing out the intermediate states of . Let , then:
gives the probability that the terminal MDLM output is a clean sequence , conditioned on the initial state and on the terminal output satisfying the regular language constraint. When is not too small, this distribution can be sampled efficiently using rejection sampling from the native decoder.
3.2 AUTOMATON-CONSTRAINED STEP-EXACT DECODER
Unlike the Doob-transformed decoder which conditions the native path law on the final state satisfying the constraint , the step-exact decoder constrains the denoiser's mean-field posterior at each denoising step to satisfy and samples it exactly using FFBS (Dang & Ermon, 2026).
Since the denoiser’s published categoricals are conditionally independent given a state , its mean-field posterior factorizes over all the positions of (respecting already committed positions) as:
Sampling the mean-field posterior conditioned on a state gives a clean sequence . This is because we retain 's tokens for non-masked positions while sampling from the mean-field's factors for masked positions. However, this clean sequence may not be in the regular language , i.e., . Since the next intermediate state is derived from and , it may not satisfy the regular constraint either. Therefore, the step-exact decoder constrains the mean-field posterior to satisfy at each step.
Proposition 3.4. [Automaton-Constrained Posterior] Let the DFA recognize , and be a random state chain of , then the automaton-constrained posterior is:
where is the constraint imposed by and is given by:
The automaton-constrained posterior in Proposition 3.4 is a Conditional Random Field (CRF) (Lafferty et al., 2001) with denoiser categoricals as unary potentials and the DFA 's transition function providing the compatibility factor for the transfer or pairwise potentials. Since is deterministic, every constraint-satisfying corresponds to exactly one DFA state chain for which . Thus, marginalizing out gives .
Definition 3.5. [Clamped Partition Sum] For a state reachable from , i.e., , the constraint-valid mass of the completions of under the denoiser conditioned on is:
When , the clamped partition sum is called the local partition sum.
The local partition sum is the normalizer of the constrained CRF in Proposition 3.4, and scores the constraint-valid probability mass of the masked positions of with the denoiser conditioned on the same state , while the clamped partition sum scores it for the masked positions of , but with the denoiser conditioned on a different state . Following Dang & Ermon (2026), we use FFBS both to sample exactly from the constrained CRF and to compute the partition sums.
Proposition 3.6. [Step-Exact Kernel] For the native kernels and partition sums with for all in the support of , the step-exact transition kernel is given by:
Proof sketch. Substituting the constrained CRF into the native joint kernel factors out and leaves as the valid-completion sum. Formal proof in Appendix A.
Interestingly, the step-exact kernel in Eq. (12) looks structurally similar to the Doob kernel in Eq. (5), in the sense that both tilt the native kernel by a ratio of successor to current constraint-valid probability masses, with the partition sums Z of step-exact kernels paralleling the exact lookaheads h of the Doob kernels. We next show that this structural similarity is not a coincidence, but a consequence of the partition sums Z being lookaheads, but of a different Markov chain.
3.3 PARTITION SUMS ARE LOOKAHEADS OF A FROZEN DENOISER MARKOV CHAIN
The exact lookahead is intractable because the native Markov chain reconditions the denoiser on new states for each step. In contrast, a clamped partition sum scores the valid completions of by conditioning the denoiser only once, at . We characterize their similarity by freezing the denoiser at a reference state . Then the frozen native joint kernel for reachable from is:
Here, the denoiser’s conditioning is fixed at instead of the current state as in Definition 2.2. The scheduler is still evaluated at . The frozen terminal law is independent of the order of unmasking since the predicted categoricals are fixed due to freezing the denoiser, yielding a tractable lookahead.
Proposition 3.7. [Frozen Lookahead] The lookahead for the constraint-satisfying terminal law induced by the frozen native kernels, for any state reachable from is:
Therefore, and .
Proof sketch. Monotone unmasking and posterior sampling are independent of the scheduler, giving Eq. (13). The two identities follow from Eq. (11) for . Formal proof in Appendix B.
From Proposition 3.7, both partition sums in Eq. (12) are thus lookaheads of the Markov chain frozen at the current state, which agrees with the native chain on the first transition, i.e., when .
Proposition 3.8. [Re-Frozen Doob Transforms] Each step-exact kernel is the exact Doob transform of the frozen native kernels at its current state :
Proposition 3.8 applies to the chain frozen at the current state. At the next step, however, the denoiser is re-frozen at the new state, replacing the expected successor with . It is this re-freezing that prevents the composition of the step-exact kernels from being the Doob transform of a single Markov chain. Since the partition sums are computed at each step, an intermediate state is thus scored twice, by as a successor (e.g., ② in Figure 2c) and by as the current state (e.g., ③ in Figure 2c) at step . We next show how this causes trajectory bias.
3.4 TRAJECTORY BIAS
We identify the tilt of the path law induced by composing the step-exact kernels, relative to the Doob path law, by multiplying them along a trajectory, yielding the native path law and the tilt factor:
The tilt factor is a product of ratios of partition sums. Since all positions are revealed at , Eq. (11) gives , the Doob terminal weight of Eq. (6). Each highlighted pair holds the two scores of an intermediate state , scored as a successor and as the current state . We call the ratio the re-freezing ratio of . It measures how re-freezing changes the valid mass estimate of 's completions. If it is greater than 1, then the valid mass of was underestimated, so paths through are under-weighted (and vice versa if less than 1):

(a) DFA for C.

(b) Automaton-constrained posterior.

(c) Successor rescoring at t=0 and 1.
Figure 2: A three-token example of trajectory bias. Let , , , and , with position 2 revealed before position 1. Revealing gives , with as its only valid completion under , while revealing gives , whose completions are both valid. Assuming uniform categoricals at (①), (②) and , so the step-exact decoder chooses with probability . After committing , the denoiser rescores position 1 as (③), so 's actual valid mass is ; which is what the Doob path law uses to choose , , i.e., with probability . But step-exact decoding only renormalizes by in the next step, thus never correcting . Since is the only valid completion of , but , due to the per-step mismatch in Eq. (14).
Proposition 3.9. [Re-Freezing Tilt] The step-exact decoder samples the Doob path law tilted by the inverse re-freezing ratios of its intermediate states (for trajectories in common support):
Proof sketch. Substitute the step-exact and Doob kernels into the ratio of their path laws.
Since is constant, the two path laws align if every re-freezing ratio equals 1, i.e.,
However, this generally does not hold, since unmasking tokens changes the denoiser's predictions for , and this is structural to the working of MDLMs itself. Trajectory bias thus manifests due to scoring the same positions under two differently conditioned denoisers. Corollary 3.10 gives the exact condition, which only requires the product of ratios to be constant.
Corollary 3.10. [Trajectory Exactness] The step-exact decoder is unbiased (Definition 3.1) if and only if the product of re-freezing ratios is constant over , i.e., for every :
Corollary 3.11. [No Bias for Vacuous Constraints] For a vacuous regular constraint (does not impose any restrictions), Eq. (16) holds for every , and there is no trajectory bias.
Proof. Formal proof is in Appendix C.2.
Corollary 3.12. [No Bias for One-Step Reveal All] When all masked positions in every initial state are revealed in a single step, i.e., , Eq. (16) holds and there is no trajectory bias.
Proof. Formal proof is in Appendix C.3.
The trajectory bias introduced by the tilt is correctable because: (1) the tilt factorizes over the steps as shown in Eq. (14) allowing it to be corrected incrementally at each step; and (2) a re-freezing ratio can be computed efficiently and exactly at its step when is reached by computing the clamped partition sum from the FFBS messages that sampled , and the next step's local partition sum from the denoiser query at that is needed at the next step anyway.
4 TWISTER: AUTOMATON-TWISTED SEQUENTIAL MONTE CARLO
Since the re-freezing tilt factorizes over steps (Proposition 3.9), it can be corrected incrementally at each step. We first show mathematically that the tilt can be corrected via our proposed Feynman–Kac corrector, and then we describe our TWISTER algorithm implementing it.
4.1 FEYNMAN–KAC CORRECTOR FOR THE RE-FREEZING TILT
We use the tractable step-exact kernels from Proposition 3.8 as the proposals: , and correct for the re-freezing ratio formalized in Section 3.4 with an exact twist.
Definition 4.1. [Feynman–Kac Twist] The Feynman–Kac twist is given by:
The ideal twist is the exact lookahead from Definition 3.2, which requires future denoiser calls and is thus intractable. The local partition sum is the frozen lookahead from Proposition 3.7, i.e., a tractable surrogate of from a single denoiser call at at step . From Definition 4.1, the Feynman–Kac twists are just the local partition sums at each step, thus they are exactly computable using the same FFBS already used for sampling the proposals . The potentials of the Feynman–Kac model can then be constructed from the twists by Eq. (4) as:
i.e., the re-freezing ratio of , for , and since .
Theorem 4.2. [Twist Fixes the Tilt] The Feynman–Kac twists correct the re-freezing tilt (Proposition 3.9), thus making the Feynman–Kac model target the Doob path law:
Proof sketch. Substitute for and in Definition 2.4. Formal proof in Appendix D. ☐
In Figure 2, weighting by its re-freezing ratio 9/5 turns the step-exact choice 1/3:2/3 into the Doob choice 9/19:10/19.
4.2 TWISTER ALGORITHM
Algorithm 1 captures TWISTER's working. It requires a DFA A (lifted to the model's vocabulary V) that recognizes the regular language C; an initial state , i.e., a token block containing the prompt and masked tokens; the number of denoising steps T; and the number of SMC particles K.
TWISTER starts by querying the denoiser at , and caching its FFBS messages. Following this, it initializes all SMC particles to with weight . The cached FFBS messages are used to sample from the Feynman–Kac proposal (Proposition 3.8), and compute the predecessor clamped-partition sum . For each propagated nonterminal particle, the denoiser is queried at the successor state to compute the successor partition sum and cache the FFBS messages for the next step. The ratio gives the exact Feynman–Kac potential required for fixing the re-freezing tilt (Section 4.1). Each incoming particle weight is multiplied by this potential, and the resulting weights are normalized. Particles are jointly resampled with their caches and assigned uniform weight when resampling is triggered (described in Appendix E).
Complexity. One weighted-automaton pass costs , and so, the total automaton cost for K SMC particles and T denoising steps is , in addition to the denoiser evaluations. TWISTER is parallelizable over the step-exact FFBS propagate and re-freezing correction phases, since the particles are conditionally independent until weight normalization and resampling.
Algorithm 1 TWISTER for step-exact decoding (adaptive resampling shown in Appendix E).
Require: DFA A recognizing C; initial state ; number of denoising steps T; number of SMC particles K 1: Query denoiser at ; 2: for all 3: for do STEP-EXACT FFBS PROPAGATE 4: parallel for do 5: Sample 6: 7: if then 8: Query denoiser at ; successor partition, cache FFBS messages 9: else 10: RE-FREEZING CORRECTION 11: parallel for do 12: 13: 14: for all 15: return
4.3 TRAJECTORY BIAS EXPERIMENT
We measure trajectory bias using regular language constraints defined over token classes. The number of token classes is an experiment configured parameter. Next, we rank the tokens by the probabilities assigned to them by the model conditioned on a fully masked input. We select the most probable tokens and then partition them equally across the token classes. Tokens outside this pool are assigned to the token class x. A model's generation can then be projected onto a small alphabet of symbols, i.e., token classes , etc..
We use such token classes to build regular expressions which are then used to constrain the model's generation. We permute the token classes to ensure that the results do not depend on a particular token-to-class mapping. Trajectory bias is then measured by using either Dang & Ermon (2026), TWISTER , or TWISTER to sample from the automaton-constrained distribution subject to the regular expression; relative to the native decoder conditioned on constraint satisfaction approximated using rejection sampling (Eq. (7)). We use pairwise total variation distance to measure the similarity between the two distributions. We also compare independent splits of the rejection samples to estimate the finite-sample noise floor. Results are averaged with equal weight across partition configurations. Thus, deviations above the rejection noise floor measure trajectory bias rather than token-level validity or Monte Carlo error. For each model and denoising steps, we generate 40,000 native samples and 10,000 constrained samples at temperature 1 under random remasking. The one-step reveal for is an experimental setting of Corollary 3.12. We evaluate on the models DREAM-7B-BASE, DREAM-7B-INST, DREAMCODER-7B-INST, LLADA-8B-BASE, LLADA-8B-INST, and OWT-130M.
5 RELATED WORK
Constrained Decoding for Autoregressive Models. Most recent approaches consist of maintaining a parser or automaton over the generated prefix and masking out invalid next tokens at each step (Willard & Louf, 2023; Koo et al., 2024; Beurer-Kellner et al., 2024; Geng et al., 2023; Ugare et al., 2024; Dong et al., 2025). While this guarantees constraint satisfaction by construction, Park et al. (2024) showed that such locally constrained decoding distorts the model's distribution over valid sequences. To address this, Loula et al. (2025) approximate the globally constrained posterior with SMC, combining locally constrained decoding with incremental reweighting and resampling to correct the resulting bias. Dang et al. (2026) further improve this setup by constructing stronger automaton-based proposals.
that encode future constraint satisfaction, yielding faster SMC convergence with fewer particles. Like these approaches, we use SMC to target the model's globally constrained distribution rather than local constraint enforcement alone, but we focus on the less-explored domain of constrained decoding for MDLMs. Unlike locally constrained LLM decoding, which ignores future valid mass, step-exact MDLM decoding accounts for this mass exactly, but under a denoiser frozen at the current state.
Constrained Decoding for Diffusion Models. Suresh et al. (2025) proposed DINGO as the first constrained decoder for MDLMs with formal guarantees. DINGO uses dynamic programming over automaton states to select a constraint-satisfying block that maximizes the per-step mean-field probability. Dang & Ermon (2026) further generalize DINGO's approach by replacing per-step MAP with exact sampling from the automaton-constrained mean-field posterior at each denoising step. Like DINGO, their method guarantees that the constraint is satisfied by construction, but it further supports stochastic sampling under arbitrary remasking schedules. Crucially, both the DINGO and Dang & Ermon (2026) still constrain generation only at individual steps. We show that such local exactness does not, however, preserve the model's relative probabilities over valid multi-step denoising trajectories. We address this gap by introducing TWISTER as the first automaton-twisted SMC constrained decoder for MDLMs that targets the trajectory-exact globally constrained path law. Hasan et al. (2025) apply Feynman–Kac SMC correctors to steer discrete diffusion sampling at inference time through temperature scaling or an external reward. Luo et al. (2026) likewise use SMC for MDLMs, but reweight particles by trajectory-level confidence to improve sample quality. In contrast, TWISTER uses SMC to enforce formal constraints.
6 CONCLUSION
We showed that sampling locally from an MDLM's automaton-constrained posterior, despite being exact at each denoising step, still tilts the distribution relative to the globally constrained distribution when composed across steps. We derived this trajectory bias as a product of local and clamped-partition sum ratios, which are a consequence of rescoring the constraint-valid completions of the same intermediate states, but under different denoiser conditionings. We showed that the tilt factorizes across the denoising steps, and thus can be corrected incrementally at each step. We then introduced TWISTER, an automaton-twisted SMC constrained decoder that corrects this tilt by using the step-exact decoder as its proposal. Further, for regular-language constraints, its incremental Feynman–Kac potentials are exactly computable from partition sums already obtained during step-exact sampling.
AI USE STATEMENT
We have not used generative AI tools for this work.
REPRODUCIBILITY STATEMENT
Our code and data will be made publicly available upon acceptance of the paper.
REFERENCES
Heli Ben-Hamu, Itai Gat, Daniel Severo, Niklas Nolte, and Brian Karrer. Accelerated sampling from masked diffusion models via entropy bounded unmasking. In NeurIPS, 2025. doi: 10.48550/arXiv.2505.24857.
Luca Beurer-Kellner, Marc Fischer, and Martin Vechev. Guiding LLMs the right way: fast, non-invasive constrained generation. In ICML, 2024. doi: 10.48550/arXiv.2403.06988.
C. K. Carter and R. Kohn. On Gibbs sampling for state space models. Biometrika, 81(3):541–553, 1994. doi: 10.1093/biomet/81.3.541.
Meihua Dang and Stefano Ermon. Constrained decoding for diffusion language models via efficient inference over finite automata. arXiv preprint arXiv:2607.07026, 2026. doi: 10.48550/arXiv.2607.07026.
Meihua Dang, Linxin Song, Honghua Zhang, Jieyu Zhao, Guy Van den Broeck, and Stefano Ermon. Mitigating bias in locally constrained decoding via tractable proposals. In ICML, 2026. doi:10.48550/arXiv.2606.01926.
Pierre Del Moral. Feynman-Kac Formulae, pp. 47–93. Springer, 2004. ISBN 978-1-4684-9393-1. doi: 10.1007/978-1-4684-9393-1_2.
Yixin Dong, Charlie F. Ruan, Yaxing Cai, Ruihang Lai, Ziyi Xu, Yilong Zhao, and Tianqi Chen. XGrammar: Flexible and efficient structured generation engine for large language models. In MLSys, 2025. doi: 10.48550/arXiv.2411.15100.
Joseph L Doob. Conditional brownian motion and the boundary limits of harmonic functions. Bulletin de la Société mathématique de France, 85:431–458, 1957. doi: 10.24033/bsmf.1494.
Azadeh Farzan, Dominik Klumpp, and Andreas Podelski. Sound sequentialization for concurrent program verification. In PLDI, pp. 506–521, 2022. doi: 10.1145/3519939.3523727.
Saibo Geng, Martin Josifoski, Maxime Peyrard, and Robert West. Grammar-constrained decoding for structured NLP tasks without finetuning. In EMNLP, 2023.
Mohsin Hasan, Marta Skreta, Alan Aspuru-Guzik, Yoshua Bengio, and Kirill Neklyudov. Discrete Feynman-Kac correctors. In AI4Math@ICML, 2025. doi: 10.48550/arXiv.2601.10403.
Terry Koo, Frederick Liu, and Luheng He. Automata-based constraints for language model decoding. In COLM, 2024. doi: 10.48550/arXiv.2407.08103.
John D. Lafferty, Andrew McCallum, and Fernando C. N. Pereira. Conditional random fields: Probabilistic models for segmenting and labeling sequence data. In ICML, pp. 282–289, 2001.
Jun S. Liu. Basic Principles: Rejection, Weighting, and Others, pp. 23–52. Springer, 2004a. ISBN 978-0-387-76371-2. doi: 10.1007/978-0-387-76371-2_2.
Jun S. Liu. Theory of Sequential Monte Carlo, pp. 53–77. Springer, 2004b. ISBN 978-0-387-76371-2. doi: 10.1007/978-0-387-76371-2_3.
João Loula, Benjamin LeBrun, Li Du, Ben Lipkin, Clemente Pasti, Gabriel Grand, Tianyu Liu, Yahya Emara, Marjorie Freedman, Jason Eisner, Ryan Cotterell, Vikash Mansinghka, Alexander K. Lew, Tim Vieira, and Timothy J. O'Donnell. Syntactic and semantic control of large language models via sequential Monte Carlo. In ICLR, 2025. doi: 10.48550/arXiv.2504.13139.
Ziwei Luo, Ziqi Jin, Lei Wang, Lidong Bing, and Thomas B. Schön. Self-rewarding sequential Monte Carlo for masked diffusion language models. arXiv preprint arXiv:2602.01849, 2026. doi:10.48550/arXiv.2602.01849.
Shen Nie, Fengqi Zhu, Zebin You, Xiaolu Zhang, Jingyang Ou, Jun Hu, Jun Zhou, Yankai Lin, Ji-Rong Wen, and Chongxuan Li. Large language diffusion models. In NeurIPS, 2025. doi:10.48550/arXiv.2502.09992.
NousResearch. json-mode-eval. https://huggingface.co/datasets/NousResearch/json-mode-eval, 2024.
Kanghee Park, Jiayu Wang, Taylor Berg-Kirkpatrick, Nadia Polikarpova, and Loris D'Antoni. Grammar-aligned decoding. In NeurIPS, 2024. doi: 10.48550/arXiv.2405.21047.
Subham Sekhar Sahoo, Marianne Arriola, Aaron Gokaslan, Edgar Mariano Marroquin, Alexander M Rush, Yair Schiff, Justin T Chiu, and Volodymyr Kuleshov. Simple and effective masked diffusion language models. In NeurIPS, 2024. doi: 10.48550/arXiv.2406.07524.
Tarun Suresh, Debangshu Banerjee, Shubham Ugare, Sasa Misailovic, and Gagandeep Singh. DINGO: Constrained inference for diffusion LLMs. In NeurIPS, 2025. doi: 10.48550/arXiv.2505.23061.
Shubham Ugare, Tarun Suresh, Hangoo Kang, Sasa Misailovic, and Gagandeep Singh. SynCode: LLM generation with grammar augmentation. TMLR, 2024. doi: 10.48550/arXiv.2403.01632.
Nick Whiteley and Anthony Lee. Twisted particle filters. The Annals of Statistics, 42(1):115–141, 2014. doi: 10.1214/13-AOS1167.
Brandon T. Willard and Rémi Louf. Efficient guided generation for large language models. arXiv preprint arXiv:2307.09702, 2023. doi: 10.48550/arXiv.2307.09702.
Chengyue Wu, Hao Zhang, Shuchen Xue, Zhijian Liu, Shizhe Diao, Ligeng Zhu, Ping Luo, Song Han, and Enze Xie. Fast-dLLM: Training-free acceleration of diffusion LLM by enabling KV cache and parallel decoding. In ICLR, 2026. doi: 10.48550/arXiv.2505.22618.
Zhihui Xie, Jiacheng Ye, Lin Zheng, Jiahui Gao, Jingwei Dong, Zirui Wu, Xueliang Zhao, Shansan Gong, Xin Jiang, Zhenguo Li, et al. Dream-coder 7B: An open diffusion language model for code. arXiv preprint arXiv:2509.01142, 2025. doi: 10.48550/arXiv.2509.01142.
Jiacheng Ye, Zhihui Xie, Lin Zheng, Jiahui Gao, Zirui Wu, Xin Jiang, Zhenguo Li, and Lingpeng Kong. Dream 7B: Diffusion large language models. arXiv preprint arXiv:2508.15487, 2025. doi:10.48550/arXiv.2508.15487.
APPENDIX CONTENTS
A Proof for Step-Exact Kernel 14
B Proof for Frozen Lookahead 14
C Proofs for Trajectory-Bias Boundary Cases 15
C.1 Kernel-Level Trajectory Exactness 15
C.2 Vacuous Constraints 15
C.3 One-Step Reveal All 15
D Proof for Twist Fixes the Tilt 16
E TWISTER Algorithm (With Adaptive Resampling) 16
F Constraint Satisfaction Experiment 17
A PROOF FOR STEP-EXACT KERNEL
Proposition 3.6. [Step-Exact Kernel] For the native kernels and partition sums with for all in the support of , the step-exact transition kernel is given by:
Proof. The joint step-exact kernel is given by:
by Eq. (9)
by Eq. (11)
The step-exact kernel is obtained by marginalizing out the reveal set R from the joint kernels. ☐
B PROOF FOR FROZEN LOOKAHEAD
Proposition 3.7. [Frozen Lookahead] The lookahead for the constraint-satisfying terminal law induced by the frozen native kernels, for any state reachable from is:
Therefore, and .
Proof. Let be the set of valid reveal-set sequences from to . Then is
Therefore, the frozen lookahead is given by:
giving Eq. (13)
Substituting in Eq. (11) gives and .
C PROOFS FOR TRAJECTORY-BIAS BOUNDARY CASES
C.1 KERNEL-LEVEL TRAJECTORY EXACTNESS
Lemma C.1. [Kernel-Level Trajectory Exactness] The step-exact path law composed of step-exact kernels equals that composed of the Doob kernels if and only if, for every , every state reachable with non-zero probability under the path law, with and , and every in the support of :
C.2 VACUOUS CONSTRAINTS
Corollary 3.11. [No Bias for Vacuous Constraints] For a vacuous constraining regular language , i.e., constrains nothing, Eq. (16) holds for every , and there is no trajectory bias.
Proof. Since , every terminal state , and so for all . By backward induction, suppose for every .
by Definition 3.2
by the backward-induction hypothesis
The local partition sum is the normalizer of Eq. (9) and so can be written as:
The clamped partition sum is given as:
Therefore for all .
C.3 ONE-STEP REVEAL ALL
Corollary 3.12. [No Bias for One-Step Reveal All] For a finite horizon T=1, where every initial realization is completely unmasked in one step, Eq. (16) holds and there is no trajectory bias.
Proof. Since , we have from Definition 3.2, and so is given by:
by
The clamped partition sum is given by Eq. (11) as:
The local partition sum is the normalizer of Eq. (12) and so can be written as:
by
Since and ,
D PROOF FOR TWIST FIXES THE TILT
Theorem 4.2. [Twist Fixes the Tilt] The Feynman–Kac twists correct the re-freezing tilt (Proposition 3.9), thus making the step-exact decoder path law target the Doob path law:
Proof. Substituting the twist-constructed potentials from Eq. (4) into the left-hand side gives:
by telescoping the twists
by Definition 4.1
by Eq. (6)
□
E TWISTER ALGORITHM (WITH ADAPTIVE RESAMPLING)
Algorithm 2 gives the complete TWISTER algorithm. It requires a DFA A (lifted to the model's vocabulary V) that recognizes the regular language C; an initial state , i.e., a token block containing the prompt and masked tokens to be unmasked; the maximum number of denoising steps T; the number of SMC particles K; and the minimum effective sample size , i.e., the threshold for triggering resampling of the SMC particles. Resampling is used in SMC to mitigate weight degeneracy: when weights of most SMC particles become too small, rendering them useless and thus wasting compute.
TWISTER starts by querying the denoiser at the initial state , computing its partition sum and caching its FFBS messages. Following this, it initializes all SMC particles to the initial state with weight . The cached FFBS messages are used to sample from the Feynman–Kac proposal , i.e., the step-exact proposal of Proposition 3.8, and compute the predecessor clamped-partition sum . For each propagated nonterminal particle, the denoiser is queried at the successor state to compute the successor partition sum and cache the FFBS messages for the next step. The ratio gives the exact Feynman–Kac potential required in Section 4.1 for fixing the tilt from Proposition 3.9. Each incoming particle weight is multiplied by this potential, and the resulting weights are normalized. Particles are jointly resampled with their caches and assigned uniform weight when resampling is triggered by the effective sample size falling below .
Complexity. One weighted-automaton pass costs , and so, the total automaton cost for SMC particles and denoising steps is , in addition to the denoiser evaluations.
Algorithm 2 TWISTER for step-exact decoding (with adaptive resampling).
Require: DFA A recognizing C; initial state ; number of denoising steps T Require: number of SMC particles K; minimum effective sample size
1: Query the denoiser at 2: for all 3: for do STEP-EXACT FFBS PROPAGATE 4: parallel for do 5: Sample 6: 7: if then 8: Query the denoiser at 9: 10: else 11: RE-FREEZING CORRECTION 12: parallel for do 13: 14: 15: for all ADAPTIVE RESAMPLING 16: ESS 17: if and ESS < then 18: 19: for all 20: return
TWISTER is parallelizable over the step-exact FFBS propagate and re-freezing correction phases, since the particles are conditionally independent until weight normalization and resampling.
F CONSTRAINT SATISFACTION EXPERIMENT
As a sanity check that TWISTER still produces only constraint-satisfying outputs, we evaluate it along with other constrained decoding methods on the JSON-Mode-Eval dataset released by NousResearch (2024). JSON-Mode-Eval consists of 100 zero-shot datapoints, each specifying a given schema and requiring a JSON output that conforms to that schema. Of the 100 datapoints in JSON-Mode-Eval, we exclude six whose schemas cannot be compiled into a regular expression by Outlines (five use a named-root wrapper rather than a valid JSON Schema root, and one is malformed), and evaluate on the remaining 94. For each remaining datapoint, we compile the JSON schema into a regular expression with the Outlines library from Willard & Louf (2023) and transform that regular expression into a token-prefix automaton over the model vocabulary. Figure 3 shows the distribution of token-prefix DFA sizes created for the 94 evaluated schemas. The distribution is concentrated in the low hundreds of states, with most values falling between roughly 100 and 250. The mean number of states is 188, with a minimum of 34 states and a maximum of 625 states.
We build the dataset prompt for each datapoint, append an instruction to emit only the JSON object, and then decode under each of the constrained strategies described below. Figure 4 shows an example of the prompt message for a JSON-Mode-Eval datapoint given to the model.
We compare four constrained decoding strategies. DINGO†, at each denoising step, selects a constraint-satisfying completion that maximizes the automaton-weighted mean-field posterior. DINGO† picks the mode by using dynamic programming over automaton states to select a locally optimal constraint-satisfying block under the mean-field factorization. Our DINGO† implementation follows the original dynamic-programming procedure from Suresh et al. (2025). The original code

Figure 3: Swarm plot of token-prefix DFA state counts on JSON-Mode-Eval. Each point is one datapoint; the diamond marks the mean.
[system] You are a helpful assistant that answers in JSON. Here's the json schema you must adhere to: <schema> { 'title': 'WirelessAccessPoint', 'type': 'object', 'properties': {'ssid': {'title': 'SSID', 'type': 'string'}, 'securityProtocol': {'title': 'SecurityProtocol', 'type': 'string'}, 'bandwidth': {'title': 'Bandwidth', 'type': 'string'}}}, 'required': ['ssid', 'securityProtocol', 'bandwidth'] </schema> [user] I'm currently configuring a wireless access point for our office network and I need to generate a JSON object that accurately represents its settings. The access point's SSID should be 'OfficeNetSecure', it uses WPA2-Enterprise as its security protocol, and it's capable of a bandwidth of up to 1300 Mbps on the 5 GHz band. This JSON object will be used to document our network configurations and to automate the setup process for additional access points in the future. Please provide a JSON object that includes these details. Only output the JSON object, no other text or comments.
Figure 4: Example JSON-Mode-Eval prompt messages (datapoint json-0). The final user-turn line is our appended instruction to emit only the JSON object.
is not publicly available. Dang & Ermon† instead samples exactly from the automaton-constrained mean-field posterior at each step using FFBS (Carter & Kohn, 1994; Dang & Ermon, 2026), which guarantees local validity but is still subject to the trajectory bias characterized in §3.4. Our Dang & Ermon† implementation follows the setup and procedure described in Dang & Ermon (2026). As with DINGO†, the original code is not publicly available. Finally, TWISTER and TWISTER apply TWISTER with K=1 and K=4 particles, using the step-exact constrained posterior and correcting trajectory bias with the Feynman–Kac twists described in §4.
We evaluate all decoding methods on six open MDLMs from the DREAM (Ye et al., 2025), DREAMCODER (Xie et al., 2025), and LLaDA (Nie et al., 2025) families: DREAM-7B-BASE, DREAM-7B-INST, DREAMCODER-7B-BASE, DREAMCODER-7B-INST, LLADA-8B-BASE, and LLADA-8B-INST. We chose these models because they are among the strongest publicly available MDLMs. We set generation length and denoising steps to the gold answer length per datapoint.
Table 1 shows the results of our evaluation of the different decoding methods on the JSON-Mode-Eval dataset. We report the parse validity, schema validity, and average time in seconds of the generated outputs. Parse validity ensures that the generated output is valid JSON, while schema validity ensures that the generated output conforms to the expected schema set by the specific dataset.
Table 1: Constraint satisfaction on JSON-Mode-Eval for all decoding methods. The Parse Valid (%) and Schema Valid (%) columns measure whether outputs are valid JSON and satisfy the schema set by the datapoint; Time (s) measures the average time taken to generate the output.
| Model | Method | Parse Valid (%) | Schema Valid (%) | Time (s) |
|---|---|---|---|---|
| DREAM-7B-BASE | 100 | 98 | ||
| Dang & Ermon | 100 | 98 | ||
| 100 | 98 | |||
| 100 | 98 | |||
| DREAM-7B-INST | 100 | 99 | ||
| Dang & Ermon | 100 | 99 | ||
| 100 | 99 | |||
| 100 | 99 | |||
| DREAMCODER-7B-BASE | 100 | 98 | ||
| Dang & Ermon | 100 | 98 | ||
| 100 | 98 | |||
| 100 | 98 | |||
| DREAMCODER-7B-INST | 100 | 99 | ||
| Dang & Ermon | 100 | 99 | ||
| 100 | 99 | |||
| 100 | 98 | |||
| LLADA-8B-BASE | 100 | 98 | ||
| Dang & Ermon | 100 | 98 | ||
| 100 | 98 | |||
| 100 | 98 | |||
| LLADA-8B-INST | 100 | 99 | ||
| Dang & Ermon | 100 | 99 | ||
| 100 | 99 | |||
| 100 | 99 |
sample. Importantly, all decoding methods, including TWISTER, consistently produce outputs that are valid JSON and conform to the expected schema. Although we report average generation times, our implementation is not optimized for performance. There are techniques to speed up the decoding time such as those described in Dang & Ermon (2026). This experiment acts as a confirmation to show that the trajectory-level correction we achieve with TWISTER does not compromise the constraint satisfaction already guaranteed by step-exact decoding.