
Speculative decoding là kỹ thuật tăng tốc độ inference của Large Language Models (LLM) lên 2-3x mà không làm giảm chất lượng đầu ra. Ý tưởng cốt lõi: sử dụng một model nhỏ (draft model) để dự đoán nhiều token trước, sau đó dùng model lớn (target model) để verify song song.
Cơ chế hoạt động
- Draft phase: Model nhỏ (thường là distilled hoặc quantized version của model lớn) sinh ra k token tiếp theo (k=3-5)
- Verify phase: Model lớn xử lý song song tất cả k token draft trong một forward pass
- Accept/Reject: So sánh probability distribution. Token draft được accept nếu probability đủ cao, ngược lại reject và sample lại từ target model
- Loop: Tiếp tục từ token cuối cùng được accept
Các phương pháp speculative decoding chính
| Phương pháp | Mô tả | Speedup |
|---|---|---|
| Standard Speculative Decoding | Draft model riêng biệt (distilled/quantized) | 2-3x |
| Self-Speculative Decoding | Cùng model nhưng bỏ qua layers (early exit) | 1.5-2x |
| Prompt Lookup Decoding | Copy tokens từ prompt context (no draft model) | 1.2-1.5x |
| Medusa / Eagle | Multiple decoding heads trên target model | 2-3x |
Yêu cầu và trade-offs
- Draft model quality: Càng giống target model thì accept rate càng cao. Thường dùng knowledge distillation hoặc quantization (INT4/INT8)
- Accept rate: Tỷ lệ token draft được accept quyết định speedup. Rate 0.8-0.9 cho 2-3x speedup
- Memory overhead: Cần load cả draft và target model vào VRAM (hoặc swap draft nếu RAM đủ)
- Output quality: Đảm bảo mathematically giống hệt target model sampling – không degrade quality
Triển khai thực tế 2025
- vLLM: Hỗ trợ speculative decoding built-in với
--speculative-modelflag - TensorRT-LLM: Medusa heads integration cho NVIDIA GPU
- llama.cpp: Speculative decoding cho CPU/Metal với draft model GGUF
- SGLang: Radix attention + speculative decoding cho throughput cao
Benchmark kết quả thực tế
Test trên LLaMA-3-70B với draft model LLaMA-3-8B (INT4) trên 2x H100:
- Baseline (no speculative): ~2,500 tokens/sec
- Speculative decoding (k=4): ~6,800 tokens/sec (2.7x speedup)
- Accept rate: ~85%
- Memory: +8GB VRAM cho draft model
Khi nào nên dùng
- Production serving cần latency thấp (chatbot, code completion)
- Batch inference throughput quan trọng
- Có VRAM dư thừa cho draft model (hoặc có system RAM để offload)
- Model target lớn (>7B params) – speedup rõ rệt hơn trên model lớn
Hướng phát triển tương lai
- Draft model dynamic: Chọn draft model dựa trên prompt complexity
- Speculative decoding cho multimodal LLM (vision + text)
- Kết hợp với KV cache quantization cho memory efficiency tối đa
- Hardware-aware drafting: Tối ưu draft model cho GPU architecture cụ thể



Nguồn tham khảo:
- Accelerating Large Language Model Decoding with Speculative Sampling (Chen et al., 2023)
- Medusa: Simple LLM Acceleration Framework with Multiple Decoding Heads
- vLLM Speculative Decoding Documentation
- TensorRT-LLM Medusa Implementation
- EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty
