Efficient and Asymptotically Unbiased Constrained Decoding for Large Language Models
Haotian Ye, Himanshu Jain, Chong You, Ananda Theertha Suresh, Haowei Lin, James Zou, Felix Yu
TL;DR
Constrained decoding equips LLM outputs to lie within a predefined set but can bias the output distribution and incurs inefficiencies when implemented with CPU based data structures during GPU inference. The authors introduce Dynamic Importance Sampling for Constrained Decoding with a GPU friendly Parallel Prefix Verification primitive, yielding asymptotically unbiased constrained sampling and significant speedups. They prove theoretical bounds on KL divergence and expected sampling steps, and demonstrate comprehensive empirical gains across 20 datasets and four tasks, including up to 8.5x faster decoding and improved Micro F1 and R-Precision over trie based methods. The approach is modular and broadly applicable to various constraint types beyond simple set constraints, offering a practical path to reliable and scalable constrained generation in real world applications.
Abstract
In real-world applications of large language models, outputs are often required to be confined: selecting items from predefined product or document sets, generating phrases that comply with safety standards, or conforming to specialized formatting styles. To control the generation, constrained decoding has been widely adopted. However, existing prefix-tree-based constrained decoding is inefficient under GPU-based model inference paradigms, and it introduces unintended biases into the output distribution. This paper introduces Dynamic Importance Sampling for Constrained Decoding (DISC) with GPU-based Parallel Prefix-Verification (PPV), a novel algorithm that leverages dynamic importance sampling to achieve theoretically guaranteed asymptotic unbiasedness and overcomes the inefficiency of prefix-tree. Extensive experiments demonstrate the superiority of our method over existing methods in both efficiency and output quality. These results highlight the potential of our methods to improve constrained generation in applications where adherence to specific constraints is essential.
