atlas

Research map / Probabilistic and scientific modeling / Variational and generative sampling

Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective

NeurIPS 2025 · Probabilistic and scientific modeling › Variational and generative sampling · approach: Sequential Monte Carlo for inference · 0 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes an MCMC (Metropolis-Hastings) framework that turns grammar-constrained decoding into a grammar-aligned sampler converging to the true constrained LM distribution, and shows better KL and fuzzing branch coverage than GCD and ASAp with Llama-3.1-8B.

Problem

Constrained decoding for LMs with context-free grammar constraints distorts the model's conditional distribution, and asymptotically correct alternatives such as ASAp converge too slowly; this hurts diverse valid sample generation such as seed generation for program fuzzing.

Approach

Use Metropolis-Hastings over grammar-valid sequences, with proposals that keep a random prefix and resample the suffix via GCD; the LM-likelihood acceptance ratio cancels the intractable normalizer, giving constraint satisfaction, monotone TV convergence, and efficiency at few steps.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use MCMC-Priority (k=10) instead of GCDGrammar-aligned sampling with Llama-3.1-8B-Instruct · SQLbranch coverage: 28.26(0.68) -> 33.70(0.44)Helped
Use MCMC-Priority (k=10) instead of ASAPGrammar-aligned sampling with Llama-3.1-8B-Instruct · SQLbranch coverage: 28.71(0.48) -> 33.70(0.44)Helped
Use MCMC-Priority (k=10) instead of GCDGrammar-aligned sampling with Llama-3.1-8B-Instruct · XMLbranch coverage: 10.67(0.05) -> 12.81(0.05)Helped
Use MCMC-Priority (k=10) instead of ASAPGrammar-aligned sampling with Llama-3.1-8B-Instruct · XMLbranch coverage: 10.66(0.09) -> 12.81(0.05)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Prefix · SQLbranch coverage: 29.47(0.75) -> 32.93(0.83)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Priority · SQLbranch coverage: 29.99(1.40) -> 33.70(0.44)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Restart · SQLbranch coverage: 29.45(0.32) -> 32.36(0.74)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Prefix · XMLbranch coverage: 11.77(0.18) -> 12.16(0.05)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Priority · XMLbranch coverage: 12.10(0.20) -> 12.81(0.05)Helped
Increase MCMC steps from k=2 to k=10 (ablation)MCMC-Restart · XMLbranch coverage: 11.37(0.16) -> 12.00(0.06)Helped
Use Priority proposal instead of Prefix or Restart (ablation)MCMC (k=10) · SQL and XMLbranch coverage: SQL: 32.93(0.83), 32.36(0.74) -> 33.70(0.44); XML: 12.16(0.05), 12.00(0.06) -> 12.81(0.05)Helped
Run MCMC for 10 steps instead of 5 (ablation)MCMC proposal families · SQL and XMLbranch coverage: k=5 already captures ≥95% of the gain realised by k=10Helped

Surprising findings

Limitations

Experimental setup

Datasets: SyGuS benchmarks (SLIA, BV4, CP) libxml2 XML grammar SQLite test-script grammar

Benchmarks: SyGuS SLIA SyGuS BV4 constituency parsing (CP) libxml2 fuzzing SQLite fuzzing

Metrics: KL divergence (empirical, on samples) branch coverage function coverage line coverage acceptance rate

Baselines: GCD ASAp Grammarinator rejection sampling

Builds on: grammar-constrained decoding ASAp Metropolis-Hastings AFL++ Transformers-GAD

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy