--- title: "Speculative Decoding" metatags: description: "SGLang speculative decoding: EAGLE-2/EAGLE-3, MTP, DFLASH, draft model configuration, and overlap-scheduler guidance." --- SGLang provides several speculative decoding options, including EAGLE-2/EAGLE-3, MTP, DFLASH, classic draft-model decoding, and an NGRAM-based variant. Our implementation aims to maximize speed and efficiency and is considered to be among the fastest in open-source LLM engines. ## Summary ### Jump to sections - [EAGLE Decoding](#eagle-decoding) - [EAGLE-2 Decoding](#eagle-2-decoding) - [EAGLE-2 Decoding with torch.compile](#eagle-2-decoding-with-torchcompile) - [EAGLE-2 Decoding via Frequency-Ranked Speculative Sampling](#eagle-2-decoding-via-frequency-ranked-speculative-sampling) - [EAGLE-3 Decoding](#eagle-3-decoding) - [Multi Token Prediction](#multi-token-prediction) - [DFlash Decoding](#dflash-decoding) - [Standalone Speculative Decoding (Small Draft Model)](#standalone-speculative-decoding-small-draft-model) - [Speculative Decoding V2 (Overlap Scheduler)](#speculative-decoding-v2-overlap-scheduler) - [Ngram Speculative Decoding](#ngram-speculative-decoding) - [Full Parameter Reference](#full-parameter-reference) - [OOM Troubleshooting](#oom-troubleshooting) - [References](#references) ### Quick guidance - **Best speed/quality (recommended)**: Use **EAGLE-3** with `--speculative-algorithm EAGLE3`. - **Strong default / broad compatibility**: Use **EAGLE-2** with `--speculative-algorithm EAGLE`. - **Workload acceptance changes over time**: Use [**Adaptive speculative decoding**](./adaptive_speculative_decoding) on top of **EAGLE** with `--speculative-eagle-topk 1`. - **Lower `lm_head` overhead for EAGLE-2**: Enable **FR-Spec** with `--speculative-token-map`. - **Model is MTP-enabled**: Use **MTP via speculative decoding** (often with small `speculative_num_steps/topk/num_draft_tokens`, see the example section). - **You have a DFlash draft checkpoint**: Use **DFLASH** with `--speculative-algorithm DFLASH` and `--speculative-draft-model-path ...`. - **You have a smaller draft LLM**: Use **STANDALONE** (`--speculative-algorithm STANDALONE`). - **No extra model available**: Use **NGRAM** (`--speculative-algorithm NGRAM`, CUDA-only). ### Method comparison (mini table)
| Method | Draft source | Separate draft model? | How to enable | Notes / constraints |
|---|---|---|---|---|
| EAGLE-2 | EAGLE draft model (feature drafting + tree) | Typically yes | --speculative-algorithm EAGLE + --speculative-draft-model-path ... |
Tune --speculative-num-steps, --speculative-eagle-topk, --speculative-num-draft-tokens |
EAGLE-2 + torch.compile |
Same as EAGLE-2 | Typically yes | Add --enable-torch-compile (optionally --torch-compile-max-bs) |
Benefit varies by hardware/model; benchmark to verify |
| EAGLE-2 + FR-Spec | Same as EAGLE-2 + token subset | Typically yes | Add --speculative-token-map ... |
Reduces lm_head overhead with high-frequency token vocab |
| EAGLE-3 | EAGLE3 draft model | Yes | --speculative-algorithm EAGLE3 + --speculative-draft-model-path ... |
Best throughput in the benchmark below |
| MTP | Built-in multi-token heads (model-specific) | Often no | See Multi Token Prediction section | Uses speculative workflow; draft path may be auto-handled for some models |
| DFLASH | DFlash draft model (linear block verification) | Yes | --speculative-algorithm DFLASH + --speculative-draft-model-path ... |
No --enable-dp-attention; pp_size == 1; disables overlap scheduler & mixed chunked prefill |
| STANDALONE | Smaller draft LLM (token-level) | Yes | --speculative-algorithm STANDALONE + --speculative-draft-model-path ... |
Does not support --enable-dp-attention |
| NGRAM | Ngram cache from previous tokens | No | --speculative-algorithm NGRAM |
CUDA-only; no --enable-dp-attention; disables overlap scheduler & mixed chunked prefill |
| Method | Throughput (tokens/s) |
|---|---|
| SGLang (w/o speculative, 1x H100) | 158.34 tokens/s |
| SGLang + EAGLE-2 (1x H100) | 244.10 tokens/s |
| SGLang + EAGLE-3 (1x H100) | 373.25 tokens/s |
| Parameter | Description | Default |
|---|---|---|
--speculative-draft-model-path |
Draft model path/weights. Typically required for EAGLE/EAGLE3 and STANDALONE. For some MTP-enabled models, this can be omitted. | None |
--speculative-num-steps |
Depth of autoregressive drafting. Increases speculation range but risks rejection cascades. | Auto (5 for Llama/Grok; 3 for many other models) |
--speculative-eagle-topk |
Branching factor per step. Improves candidate diversity and acceptance rate, but increases memory/compute consumption. | Auto (4 for Llama/Grok; 1 for many other models) |
--speculative-num-draft-tokens |
Maximum parallel verification capacity. Allows deeper tree evaluation but increases GPU memory usage. | Auto (8 for Llama/Grok; 4 for many other models). If topk=1, it is adjusted to num_steps + 1. |
--speculative-accept-threshold-single |
Acceptance threshold for single-token verification. Lower values accept more aggressively. | 1.0 |
--speculative-accept-threshold-acc |
Accumulated acceptance threshold across steps. | 1.0 |
--speculative-attention-mode |
Attention mode for speculative operations (prefill or decode), affecting both target verification and draft extension. |
"prefill" |
--speculative-draft-attention-backend |
Override attention backend for the draft model. | None (same as target) |
--speculative-draft-model-quantization |
Quantization method for the draft model. Use "unquant" to force no quantization even when the target model is quantized. |
Same as target model |
--speculative-draft-model-revision |
Specific revision/commit of the draft model to load. | None (auto-set to "main" when --speculative-draft-model-path is set and revision is omitted) |
--speculative-draft-load-format |
Load format for the draft model weights. | None |
| Parameter | Description | Default |
|---|---|---|
--speculative-draft-model-path |
Required DFlash draft model path/weights. | None |
--speculative-num-draft-tokens |
DFlash verify block size. | Inferred from draft config, otherwise 16 |
--speculative-dflash-block-size |
Alias of --speculative-num-draft-tokens for DFlash. |
None |
--speculative-dflash-draft-window-size |
Draft KV sliding-window size. Must be >= speculative-num-draft-tokens when set. |
None |
| Parameter | Description | Default |
|---|---|---|
--speculative-draft-model-path |
Draft model weights (smaller than the target model). | None |
--speculative-num-steps |
Draft depth (how many steps the draft model runs autoregressively). | 3 (auto default for STANDALONE) |
--speculative-eagle-topk |
Branching factor (token candidates per step). | 1 (auto default for STANDALONE) |
--speculative-num-draft-tokens |
Verification capacity. | 4 (auto default for STANDALONE) |
--speculative-draft-model-quantization |
Quantization for the draft model. Use "unquant" to disable quantization on the draft even when the target is quantized. |
Same as target |
| Parameter | Description | Default |
|---|---|---|
--speculative-num-draft-tokens |
Number of draft tokens verified per step. If omitted, defaults to min(--speculative-ngram-max-trie-depth, 12). |
12 (with default ngram settings) |
--speculative-ngram-min-bfs-breadth |
Minimum BFS breadth. | 1 |
--speculative-ngram-max-bfs-breadth |
Maximum BFS breadth. | 10 |
--speculative-ngram-match-type |
Ngram tree-building mode: "BFS" for recency-based expansion or "PROB" for frequency-based expansion. |
"BFS" |
--speculative-ngram-max-trie-depth |
Maximum suffix length stored and matched by the ngram trie. | 18 |
--speculative-ngram-capacity |
Cache capacity (number of entries). | 10,000,000 |
| Parameter | Type | Default | Description |
|---|---|---|---|
--speculative-algorithm |
str |
None |
Algorithm to use: DFLASH, EAGLE, EAGLE3, STANDALONE, NGRAM, NEXTN (alias of EAGLE) |
--speculative-draft-model-path |
str |
None |
Path to the draft model weights |
--speculative-draft-model-revision |
str |
None |
Specific revision/commit of the draft model ("main" is auto-used when draft path is set and revision is omitted) |
--speculative-draft-load-format |
str |
None |
Load format for draft model weights |
--speculative-num-steps |
int |
None (auto-chosen when omitted) |
Autoregressive drafting depth |
--speculative-eagle-topk |
int |
None (auto-chosen when omitted) |
Branching factor per drafting step |
--speculative-num-draft-tokens |
int |
None (auto-chosen when omitted) |
Maximum number of draft tokens for verification |
--speculative-dflash-block-size |
int |
None |
DFlash-only alias of --speculative-num-draft-tokens |
--speculative-dflash-draft-window-size |
int |
None |
DFlash-only draft KV sliding-window size |
--speculative-accept-threshold-single |
float |
1.0 |
Single-token acceptance threshold |
--speculative-accept-threshold-acc |
float |
1.0 |
Accumulated acceptance threshold |
--speculative-token-map |
str |
None |
Path to FR-Spec high-frequency token map |
--speculative-attention-mode |
str |
"prefill" |
Attention mode for speculative operations ("prefill" or "decode") |
--speculative-draft-attention-backend |
str |
None |
Override attention backend for the draft model |
--speculative-moe-runner-backend |
str |
None |
MoE runner backend for the draft model |
--speculative-moe-a2a-backend |
str |
None |
MoE all-to-all backend for the draft model |
--speculative-draft-model-quantization |
str |
Same as target | Quantization for the draft model ("unquant" to disable) |
| Parameter | Type | Default | Description |
|---|---|---|---|
--speculative-ngram-min-bfs-breadth |
int |
1 |
Minimum BFS breadth |
--speculative-ngram-max-bfs-breadth |
int |
10 |
Maximum BFS breadth |
--speculative-ngram-match-type |
str |
"BFS" |
Ngram tree-building mode: "BFS" for recency-based expansion or "PROB" for frequency-based expansion |
--speculative-ngram-max-trie-depth |
int |
18 |
Maximum suffix length stored and matched by the ngram trie |
--speculative-ngram-capacity |
int |
10,000,000 |
Cache capacity |
| Variable | Default | Description |
|---|---|---|
SGLANG_NGRAM_FORCE_GREEDY_VERIFY |
False |
Force greedy verification for ngram decoding |
| Parameter | Description |
|---|---|
--enable-multi-layer-eagle |
Enable multi-layer EAGLE (auto-enabled for MiMoV2 and Step3p5 models) |
--enable-torch-compile |
Enable torch.compile for kernel-level optimizations |
--torch-compile-max-bs |
Maximum batch size for torch.compile |