Speculative Decoding Speculative decoding is an optimization technique that accelerates inference. While traditional decoding is bottlenecked by memory access when generating one token at a time, speculative decoding leverages a smaller "draft" model to predict next K tokens in one round, achieving up to K times speedup with similar memory usage.
Speculative decoding is an optimization technique that accelerates inference. While traditional decoding is bottlenecked by memory access when generating one token at a time, speculative decoding leverages a smaller "draft" model to predict next K tokens in one round, achieving up to K times speedup with similar memory usage.
This doc is mainly focused on high level SGLang implementation for speculative decoding, For detailed theoretical background, please refer to the original research papers:

Traditional decoding consists of two main stages:
Speculative decoding introduces a draft model to generate multiple tokens in parallel:
Compare to traditional decode stage, in speculative decode, it includes:

Target Verification: The target model verifies N draft tokens through a forward pass. There are three possible cases for verification:
a. Full Match: All N draft tokens are accepted by the target model
b. No Match: None of the draft tokens are accepted
c. Prefix Match: Some initial draft tokens are accepted