Skip to content

Speculative Decoding

This document shows how to use Speculative Decoding with vLLM to reduce inter-token latency under medium-to-low QPS (query per second), memory-bound workloads.

To train your own draft models for optimized speculative decoding, see vllm-project/speculators for seamless training and integration with vLLM.

vLLM Speculation Methods

vLLM supports a variety of methods of speculative decoding. Model-based methods such as EAGLE, MTP, draft models, PARD and MLP provide the best latency reduction, while simpler methods such as n-gram and suffix decoding provide modest speedups without increasing workload during peak traffic.

Method Selection at a Glance

Use this qualitative table as a starting point for method selection. Real gains depend on your model family, traffic pattern, hardware, and sampling settings.

Method Low QPS (latency focused) High QPS (throughput focused) Notes
EAGLE High gain Medium to high gain Strong general-purpose model-based method.
MTP High gain Medium to high gain Best when the target model has native MTP support.
Draft model High gain Medium gain Needs a separate draft model.
Parallel Draft Model High gain Medium to high gain Low draft model latency.
MLP speculator Medium to high gain Medium gain Good when compatible MLP speculators are available.
N-gram Low to medium gain Medium gain Lightweight and easy to enable.
Suffix decoding Low to medium gain Medium gain No extra draft model; dynamic speculation depth.

For reproducible measurements in your environment, use examples/offline_inference/spec_decode.py or the benchmark CLI guide.

Lossless guarantees of Speculative Decoding

In vLLM, speculative decoding aims to enhance inference efficiency while maintaining accuracy. This section addresses the lossless guarantees of speculative decoding, breaking down the guarantees into three key areas:

  1. Theoretical Losslessness - Speculative decoding sampling is theoretically lossless up to the precision limits of hardware numerics. Floating-point errors might cause slight variations in output distributions, as discussed in Accelerating Large Language Model Decoding with Speculative Sampling

  2. Algorithmic Losslessness - vLLM’s implementation of speculative decoding is algorithmically validated to be lossless. Key validation tests include:

    • Rejection Sampler Convergence: Ensures that samples from vLLM’s rejection sampler align with the target distribution. View Test Code
    • Greedy Sampling Equality: Confirms that greedy sampling with speculative decoding matches greedy sampling without it. This verifies that vLLM's speculative decoding framework, when integrated with the vLLM forward pass and the vLLM rejection sampler, provides a lossless guarantee. Almost all of the tests in tests/spec_decode/e2e. verify this property using this assertion implementation
  3. vLLM Logprob Stability - vLLM does not currently guarantee stable token log probabilities (logprobs). This can result in different outputs for the same request across runs. For more details, see the FAQ section titled Can the output of a prompt vary across runs in vLLM? in the FAQs.

While vLLM strives to ensure losslessness in speculative decoding, variations in generated outputs with and without speculative decoding can occur due to following factors:

  • Floating-Point Precision: Differences in hardware numerical precision may lead to slight discrepancies in the output distribution.
  • Batch Size and Numerical Stability: Changes in batch size may cause variations in logprobs and output probabilities, potentially due to non-deterministic behavior in batched operations or numerical instability.

For mitigation strategies, please refer to the FAQ entry Can the output of a prompt vary across runs in vLLM? in the FAQs.

Known Feature Incompatibility

  1. Pipeline parallelism is not composible with speculative decoding as of vllm<=0.15.0
  2. Speculative decoding with a draft models is not supported in vllm<=0.10.0

Resources for vLLM contributors