Efficient and Asymptotically Unbiased Constrained Decoding for Large Language Models

Haotian Ye, Himanshu Jain, Chong You, Ananda Theertha Suresh, Haowei Lin, James Zou, Felix X. Yu · DOI

Introduction

Constrained decoding is a critical technique for ensuring that Large Language Models (LLMs) adhere to specific formats, such as JSON or Python, or select from predefined sets, such as product catalogs or Wikipedia entities. While essential for reliability, existing constrained decoding methods suffer from two primary limitations: mathematical bias in the output distribution and significant computational overhead. This paper introduces a dual-algorithm approach—DISC and PPV—designed to eliminate these biases and accelerate inference by up to 8.5x.

The Challenges of Constrained Decoding

Modern LLMs are often constrained to prevent "hallucinations" of invalid options. However, current approaches encounter two major hurdles:

  1. The Bias Problem: Standard constrained decoding is inherently "myopic." It selects the next token based on immediate validity and local probability. This often leads the model into "dead-ends" where no valid sequence can be completed, forcing the model to eventually select low-probability tokens to satisfy the constraint. The authors provide a formal proof (Theorem 2.1) demonstrating that this inevitably introduces significant bias, meaning the final output distribution does not accurately reflect the model's underlying knowledge.
  2. The Efficiency Bottleneck: Most tools rely on "tries" (prefix trees) to track valid sequences. These structures typically reside on the CPU. Because the model runs on the GPU, every token generation requires a communication round-trip between the GPU and CPU to mask invalid tokens. This creates a massive bottleneck that slows down inference significantly.

Proposed Methodology

To address these issues, the researchers developed two complementary algorithms: DISC for statistical rigor and PPV for hardware efficiency.

1. DISC: Dynamic Importance Sampling for Constrained Decoding

DISC moves beyond simple token masking. Instead of forcing a choice at every step, DISC samples candidate sequences and utilizes Importance Sampling to evaluate them. By weighting these samples based on how the unconstrained model would have prioritized those paths, the algorithm guarantees that the output is asymptotically unbiased. As the number of sampling steps ($K$) increases, the output distribution converges toward the true mathematical ideal of the model's distribution restricted to the valid set.

2. PPV: Parallel Prefix-Verification

To resolve the efficiency bottleneck, the authors introduced Parallel Prefix-Verification (PPV). Rather than maintaining a complex trie on the CPU, PPV leverages the massive parallelism of GPUs.

  • GPU-Resident Arrays: Valid sequences are stored in a sorted array directly in GPU memory.
  • Verification over Generation: Instead of asking the CPU to identify every valid token in a massive vocabulary, PPV takes the top $M$ tokens (e.g., the 50 most likely candidates) predicted by the model.
  • Parallel Binary Search: The algorithm appends these candidates to the current prefix and performs a parallel binary search across the sorted constraint set. This eliminates CPU-GPU data transfers and utilizes the GPU's architecture to verify validity in parallel.

Experimental Evaluation

The authors evaluated DISC and PPV across 20 datasets spanning four major tasks: Entity Disambiguation (e.g., AIDA, MSNBC), Document Retrieval (KILT and BEIR benchmarks), Entity Retrieval (DBPedia-Entity), and Fact Checking (Climate-FEVER). Testing was conducted using both fine-tuned BART models and Llama-3.2-3B-Instruct in zero-shot settings.

Key Results and Insights

  • Performance Gains: PPV achieved up to an 8.5x speedup compared to traditional trie-based methods. This efficiency is particularly notable because the binary search complexity grows only logarithmically, allowing the system to handle constraint sets as large as 6 million Wikipedia entities.
  • Improved Accuracy: DISC consistently outperformed existing methods. In Entity Retrieval tasks, DISC (with $K=4$) more than doubled the performance of unconstrained decoding and surpassed trie-based methods by 22%.
  • Theoretical Validation: The research confirms that LLMs concentrate most of their probability mass on a small subset of tokens. By focusing on verifying these "favorite" tokens rather than masking the entire vocabulary, PPV aligns with the natural behavior of the model.

Limitations and Future Work

While highly effective, the approach has trade-offs. Storing massive sorted arrays on the GPU increases VRAM consumption, which may require array-splitting for extremely large-scale applications. Additionally, while DISC provides superior accuracy and unbiasedness, the importance sampling process ($K > 1$) introduces more computational overhead than a single greedy pass. Future work may focus on extending the empirical evaluation of DISC/PPV to more complex structures like Context-Free Grammars (JSON/Python) beyond the set-based constraints emphasized in this study.

Summary updated

BibTeX
@inproceedings{ye2025efficient,
  author = {Haotian Ye and Himanshu Jain and Chong You and Ananda Theertha Suresh and Haowei Lin and James Zou and Felix X. Yu},
  title = {{Efficient and Asymptotically Unbiased Constrained Decoding for Large Language Models}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2025},
  url = {https://openreview.net/forum?id=hJicYBZ1Yz},
}
Figure