Abstract
Constrained decoding with lookahead heuristics (CDLH) is a highly effective method for aligning LLM generations to human preferences. However, the extensive lookahead roll-out operations for each generated token makes CDLH prohibitively expensive, resulting in low adoption in practice. In contrast, common decoding strategies such as greedy decoding are extremely efficient, but achieve very low constraint satisfaction. We propose constrained decoding with speculative lookaheads (CDSL), a technique that significantly improves upon the inference efficiency of CDLH without experiencing the drastic performance reduction seen with greedy decoding. CDSL is motivated by the recently proposed idea of speculative decoding that uses a much smaller draft LLM for generation and a larger target LLM for verification. In CDSL, the draft model is used to generate lookaheads which is verified by a combination of target LLM and task-specific reward functions. This process accelerates decoding by reducing the computational burden while maintaining strong performance. We evaluate CDSL in two constraint decoding tasks with three LLM families and achieve 2.2x to 12.15x speedup over CDLH without significant performance reduction.
Introduction
Large Language Models (LLMs) are increasingly required to adhere to complex constraints, ranging from semantic safety guidelines to specific lexical requirements. While Constrained Decoding with Lookahead Heuristics (CDLH) is the current gold standard for constraint satisfaction, its computational cost is prohibitive due to the need for extensive "rollouts" for every candidate token. Conversely, Greedy Decoding offers high efficiency but frequently fails to meet constraints. This paper introduces Constrained Decoding with Speculative Lookaheads (CDSL), a method that bridges this gap by leveraging the principles of speculative decoding to achieve significant speedups without sacrificing performance.
Methodology: The CDSL Framework
CDSL adapts the "draft-then-verify" paradigm of speculative decoding for constrained environments. The process involves three primary stages:
- Speculation: A small, efficient draft model ($M_q$) generates a sequence of $d$ lookahead tokens.
- Linguistic Verification: A larger target model ($M_p$) performs a single parallel forward pass to verify the draft sequence against its own probability distribution.
- Constraint Scoring: A task-specific reward function ($R$) evaluates the speculated sequence for constraint satisfaction.
A four-state decision logic determines the final token acceptance based on an acceptance score ($a$) from the target model and a reward score ($r$) from the constraint checker. If the draft fails, the system falls back to a more robust sampling method or a novel baseline, CDLH-Appx, which uses the draft model to generate lookaheads for the target model's candidates.
Experimental Evaluation
The researchers evaluated CDSL across two primary tasks:
- Lexical Constraints (CommonGen): Generating coherent sentences using specific concept sets (e.g., {dog, run, field}).
- Semantic Constraints (Anthropic’s HH-RLHF): Ensuring harmless and helpful text generation, scored via a DeBERTa-v3 reward model.
Testing utilized the OPT (up to 13B), Bloomz (7.1B), and Qwen1.5 (7B) model families, paired with various smaller draft models.
Key Results
CDSL demonstrates a superior trade-off between inference speed and constraint satisfaction. As shown in Figure 1, CDSL (represented by stars) achieves performance levels comparable to the computationally expensive CDLH while providing massive speedups across different model architectures.
Specifically, CDSL achieved:
- Massive Speedups: Between 2.2x and 12.15x over standard CDLH.
- Efficiency Gains: For the OPT-13B model, target model calls per token were reduced from 14.72 to approximately 0.55.
- Performance Robustness: Maintained constraint satisfaction within 1-5% of the CDLH "skyline," significantly outperforming greedy decoding which often dropped 10-20% in safety metrics.
Discussion and Sensitivity Analysis
The effectiveness of CDSL is contingent on the selection of hyperparameters, including acceptance thresholds for reward and approval scores, as well as the fallback parameter ($b$). Figure 2 illustrates how these parameters influence the balance between speedup and constraint satisfaction.
While CDSL offers a "sweet spot" for efficient constrained decoding, it is limited by the requirement for tokenizer alignment between draft and target models. Future work may explore batching implementations and extensions to closed-source models where logit access is restricted.
Conclusion
CDSL provides a practical solution to the high cost of constrained decoding. By treating verification as a parallelizable task and utilizing small models as efficient "planners," it enables high-quality, rule-abiding LLM generation at a fraction of the traditional computational cost.
Summary updated