TL;DR
Speculative Contrastive Decoding (SCD) is a new inference strategy that simultaneously speeds up Large Language Models (LLMs) and improves their output quality. By using a single small "amateur" model to both propose candidate tokens and serve as a contrastive baseline, SCD achieves the acceleration of speculative decoding while maintaining the reasoning and generation improvements of contrastive decoding.
What Problem Does This Paper Address?
LLMs face two major hurdles in production:
- Efficiency: Their auto-regressive nature—generating one token at a time—is computationally expensive and slow.
- Quality: They often suffer from "exposure bias" and systematic errors, leading to hallucinations or repetitive, low-diversity text.
Existing solutions usually tackle these separately. Speculative Decoding (SD) uses a small model to draft tokens that a large model verifies, improving speed. Contrastive Decoding (CD) improves quality by subtracting the log-probabilities of a small model from a large model to penalize common errors. However, running both independently would be inefficient. The authors ask: Can we get the best of both worlds using just one small model?
Methods
The authors introduce Speculative Contrastive Decoding (SCD). The core idea is to replace the standard verification step in speculative decoding with a contrastive one.
- The Setup: You have an "expert" LLM ($M_e$) and a smaller "amateur" LM ($M_a$).
- Drafting: The amateur model $M_a$ generates a sequence of $\gamma$ candidate tokens.
- Contrastive Verification: Instead of the expert model simply checking if it agrees with the amateur, it calculates a contrastive distribution. This distribution amplifies the expert's strengths by penalizing the amateur's likely errors (e.g., $Logit_{expert} - \beta \cdot Logit_{amateur}$).
- Rejection Sampling: Tokens are accepted or rejected based on this contrastive distribution. If a token is rejected, the expert generates a new one from the contrastive distribution, and the cycle repeats.
The authors evaluate two flavors: Original SCD (based on probability differences) and Improved SCD (based on weighted logit differences), finding the latter to be more robust.
Datasets
The researchers tested SCD across four diverse benchmarks to ensure broad applicability:
- WikiText: For open-ended text generation (evaluated via diversity and MAUVE scores).
- HumanEval: For code generation (evaluated via Pass@1 rate).
- AlpacaEval: For human-aligned instruction following (evaluated via GPT-4 win-rate).
- GSM8k: For mathematical reasoning (evaluated via accuracy).
They primarily used Llama2-7B as the amateur and Llama2-70B as the expert.
Key Insights and Ideas
- The Entropy Synergy: The most striking finding is why these two methods are compatible. As shown in the entropy analysis, "easy" tokens (which have low entropy) are accepted quickly by the amateur model, driving acceleration. "Hard" tokens (high entropy), where the amateur is likely to fail or hallucinate, are rejected and corrected by the contrastive distribution, driving quality.
- Negligible Overhead: SCD requires only one additional forward pass of the amateur model per iteration compared to standard speculative decoding, making the computational cost of the quality improvement almost free.
- Robustness of Logits: The "Improved" version of SCD (using logits) is significantly less sensitive to hyperparameters like $\alpha$ and $\beta$ than the "Original" version, making it more practical for real-world deployment.
Key Results
- Speed: SCD achieves theoretical acceleration factors of 2x to 3.3x across different tasks, matching the speedups seen in standard speculative decoding.
- Quality: On HumanEval, SCD improved the Pass@1 rate from 28.66% (base expert) to 37.20%. On GSM8k, it maintained the high accuracy of contrastive decoding while being significantly faster.
- Efficiency vs. Quality: Figure 1 illustrates that with proper hyperparameter tuning, SCD maintains a high token acceptance rate $\lambda$, ensuring that the quality gains don't come at the expense of speed.
Limitations and Future Work
- Hardware Dependency: The actual wall-clock speedup is highly dependent on the "cost coefficient" $c$—the ratio of the amateur's runtime to the expert's. If the infrastructure isn't optimized for switching between models, the benefits may diminish.
- Hyperparameter Tuning: While the improved version is more stable, finding the optimal $\alpha$ (plausibility constraint) and $\beta$ (contrastive weight) still requires some grid searching per task.
- Future Directions: The authors suggest that SCD could be further improved by using more advanced drafting structures, like the tree-based predictions used in methods like Medusa or SpecInfer.
Summary updated