speculative_num_steps/speculative_num_draft_tokens at runtime instead of keeping a single fixed value for the whole server lifetime.
It is designed for workloads whose accept length changes over time, where one static step count is rarely optimal.
Current support
- Only
--speculative-algorithm EAGLEorEAGLE3 - Only
--speculative-eagle-topk 1 - If either condition is not met, SGLang falls back to static speculative settings
Why adaptive steps help
speculative_num_steps controls how many draft-model autoregressive steps run in each speculative round. In practice, the best value depends on the current workload.
- If
num_stepsis too small, the draft model could have produced more accepted tokens, but the round stops too early. - If
num_stepsis too large, the draft model produces many candidate tokens that the target model rejects, so extra draft work is wasted. - At high batch sizes, the cost of each wasted draft step is multiplied across all sequences in the batch, so the optimal step count is often lower than at low batch sizes.
num_steps.
Design overview
The adaptive mechanism has three pieces:AdaptiveSpeculativeParams: the EMA-based policySpecRuntimeState: the per-tier runtime state bundleAdaptiveController: the coordinator that queries the policy for the current batch size and activates the matching runtime state
Per-batch-size independent tracking
The controller maintains independent EMA trackers for each batch size range, so observations at small BS don’t pollute the large BS signal. Each BS range can have its own candidate steps, hysteresis thresholds, and ceiling coefficient. BS ranges are defined as lower bounds in the config file (e.g., keys"1" and "8" mean BS 1–7 uses one slot, BS 8+ uses another). SpecRuntimeState objects are shared across BS ranges with the same step count — each state owns CUDA graphs captured for the reachable padded batch sizes of that step.
This matters because CudaGraphRunner is shape-dependent. Each candidate tier owns its own graph and backend state, so runtime switching is a reference swap, not an online graph recapture.
Runtime flow
The adaptive update happens in two places:- Pre-draft: query the optimal step for the current batch size and activate if different
- Post-verify: update the matching BS slot’s EMA with observed accept lengths
Tier switch happens after the current round completes. Backends and CUDA graphs are never swapped mid-round.
How the policy decides
After each verify pass, SGLang reads the accepted draft length per request, computes the batch average, smooths it with an exponential moving average (EMA), and switches among the candidate tiers for the matching BS slot. The decision logic is intentionally conservative:warmup_batchesskips the first few batchesupdate_intervalavoids switching every batchdown_hysteresisandup_hysteresisreduce oscillationceiling_coeff— an optional EMA ceiling rule can capnum_stepsproportionally to observed draft quality, preventing over-speculation at high BS
Usage
--speculative-adaptive-config is optional, but the speculative setup still needs to be valid for adaptive mode.
--speculative-adaptive-config /path/to/adaptive_spec.json.
Example config:
ema_alpha, warmup_batches, update_interval) are global overrides applied to every BS slot. Integer keys ("1", "8") define per-BS slots.
Config file reference
The config file is optional. When provided, each integer BS-slot key must specifycandidate_steps; all other keys fall back to defaults.
Per-BS slot parameters
| Key | Default | Meaning |
|---|---|---|
candidate_steps | required | Candidate speculative_num_steps tiers for this BS range. Must be a non-empty list of positive ints; a slot that omits it raises a config error |
down_hysteresis | -0.25 | Extra margin before moving to a smaller step |
up_hysteresis | 0.0 | Extra margin before moving to a larger step |
ceiling_coeff | 0 (disabled) | EMA ceiling coefficient; set > 0 to cap steps proportionally to draft quality |
Global parameters
| Key | Default | Meaning |
|---|---|---|
ema_alpha | 0.2 | EMA smoothing factor for accepted draft length |
update_interval | 5 | Recompute interval, in verify batches, after warmup |
warmup_batches | 10 | Number of verify batches to observe before switching |
Monitoring
You can inspect the active tier and acceptance metric via/server_info:
speculative_num_stepsis the current active tieravg_spec_accept_lengthhelps explain whether the server is likely to move up or down
Tuning tips
- Start with the built-in default (conservative) — it is safe for all draft model qualities
- For strong draft models, use the aggressive config with ceiling rule
- Use fewer candidate steps if you want lower startup GPU memory overhead
- Increase
ema_alphato react faster, or lower it for more stability - Increase
warmup_batchesorupdate_intervalif tier switching is too noisy - At high batch sizes, narrower ladders (e.g.,
[1, 2]or[1]) often outperform wide ones - If your workload is already stable and one static setting is well tuned, adaptive mode may not help much
Recommended configs
The built-in default is conservative — safe for all draft models but may under-speculate for strong ones. Save one of these as a JSON file and pass via--speculative-adaptive-config.
Conservative (default) — for weak draft models
This is the built-in default: BS 8–31 allows[1, 3], and BS≥32 locks to step=1 to avoid wasted compute. Best for models like MiniMax-M2.5, DSV4.
Aggressive — for strong or high-variance draft models
Uses wider ladders with ceiling rule to cap speculation at high BS. Best for models like GLM-4.7-FP8.Custom per-model config
For the best performance, benchmark your specific model across batch sizes with different staticnum_steps values, then build a per-BS config that matches each range’s optimal step. A well-tuned per-model config might outperform the generic presets above.