Speculative Decoding#
SGLang now provides an EAGLE-based (EAGLE-2/EAGLE-3) speculative decoding option. Our implementation aims to maximize speed and efficiency and is considered to be among the fastest in open-source LLM engines.
Performance Highlights#
Please see below for the huge improvements on throughput for LLaMA-Instruct 3.1 8B tested on MT bench that can be achieved via EAGLE3 decoding. For further details please see the EAGLE3 paper.
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 |
EAGLE Decoding#
To enable EAGLE speculative decoding the following parameters are relevant:
speculative_draft_model_path: Specifies draft model. This parameter is required.speculative_num_steps: Depth of autoregressive drafting. Increases speculation range but risks rejection cascades. Default is 5.speculative_eagle_topk: Branching factor per step. Improves candidate diversity, will lead to higher acceptance rate, but more lead to higher memory/compute consumption. Default is 4.speculative_num_draft_tokens: Maximum parallel verification capacity. Allows deeper tree evaluation but will lead to higher GPU memory usage. Default is 8.
These parameters are the same for EAGLE-2 and EAGLE-3.
You can find the best combinations of these parameters with bench_speculative.py.
In the documentation below, we set --cuda-graph-max-bs to be a small value for faster engine startup. For your own workloads, please tune the above parameters together with --cuda-graph-max-bs, --max-running-requests, --mem-fraction-static for the best performance.
EAGLE-2 decoding#
You can enable EAGLE-2 decoding by setting --speculative-algorithm EAGLE and choosing an appropriate model.
[1]:
from sglang.test.doc_patch import launch_server_cmd
from sglang.utils import wait_for_server, print_highlight, terminate_process
import openai
[2025-11-12 15:42:23] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:42:23] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:42:23] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2]:
server_process, port = launch_server_cmd(
"""
python3 -m sglang.launch_server --model meta-llama/Llama-2-7b-chat-hf --speculative-algorithm EAGLE \
--speculative-draft-model-path lmsys/sglang-EAGLE-llama2-chat-7B --speculative-num-steps 3 \
--speculative-eagle-topk 4 --speculative-num-draft-tokens 16 --cuda-graph-max-bs 8 --log-level warning
"""
)
wait_for_server(f"http://localhost:{port}")
[2025-11-12 15:42:28] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:42:28] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:42:28] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:42:31] WARNING server_args.py:1197: Attention backend not explicitly specified. Use flashinfer backend by default.
[2025-11-12 15:42:31] WARNING server_args.py:1551: Overlap scheduler is disabled because of using eagle3 or standalone speculative decoding.
[2025-11-12 15:42:31] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:42:31] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:42:38] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:42:38] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:42:38] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:42:38] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:42:38] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:42:38] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:42:40] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:42:40] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:42:40] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:42:40] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
Loading safetensors checkpoint shards: 0% Completed | 0/2 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 50% Completed | 1/2 [00:01<00:01, 1.60s/it]
Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:02<00:00, 1.17s/it]
Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:02<00:00, 1.24s/it]
Capturing batches (bs=1 avail_mem=54.86 GB): 100%|██████████| 4/4 [00:00<00:00, 12.11it/s]
[2025-11-12 15:43:05] SPECULATIVE_MOE_RUNNER_BACKEND is not initialized, using auto backend
Loading pt checkpoint shards: 0% Completed | 0/1 [00:00<?, ?it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:01<00:00, 1.15s/it]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:01<00:00, 1.15s/it]
Capturing batches (bs=1 avail_mem=53.67 GB): 100%|██████████| 4/4 [00:10<00:00, 2.65s/it]
Capturing batches (bs=1 avail_mem=53.58 GB): 100%|██████████| 4/4 [00:00<00:00, 113.59it/s]
NOTE: Typically, the server runs in a separate terminal.
In this notebook, we run the server and notebook code together, so their outputs are combined.
To improve clarity, the server logs are displayed in the original black color, while the notebook outputs are highlighted in blue.
To reduce the log length, we set the log level to warning for the server, the default log level is info.
We are running those notebooks in a CI environment, so the throughput is not representative of the actual performance.
[3]:
client = openai.Client(base_url=f"http://127.0.0.1:{port}/v1", api_key="None")
response = client.chat.completions.create(
model="meta-llama/Llama-2-7b-chat-hf",
messages=[
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0,
max_tokens=64,
)
print_highlight(f"Response: {response}")
[4]:
terminate_process(server_process)
EAGLE-2 Decoding with torch.compile#
You can also enable torch.compile for further optimizations and optionally set --torch-compile-max-bs:
[5]:
server_process, port = launch_server_cmd(
"""
python3 -m sglang.launch_server --model meta-llama/Llama-2-7b-chat-hf --speculative-algorithm EAGLE \
--speculative-draft-model-path lmsys/sglang-EAGLE-llama2-chat-7B --speculative-num-steps 5 \
--speculative-eagle-topk 8 --speculative-num-draft-tokens 64 --mem-fraction 0.6 \
--enable-torch-compile --torch-compile-max-bs 2 --log-level warning
"""
)
wait_for_server(f"http://localhost:{port}")
[2025-11-12 15:44:03] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:44:03] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:44:03] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:44:06] WARNING server_args.py:1197: Attention backend not explicitly specified. Use flashinfer backend by default.
[2025-11-12 15:44:06] WARNING server_args.py:1551: Overlap scheduler is disabled because of using eagle3 or standalone speculative decoding.
[2025-11-12 15:44:06] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:44:06] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:44:12] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:44:12] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:44:12] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:44:12] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:44:12] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:44:12] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:44:14] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:44:14] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:44:14] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:44:14] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
Loading safetensors checkpoint shards: 0% Completed | 0/2 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 50% Completed | 1/2 [00:01<00:01, 1.66s/it]
Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:02<00:00, 1.22s/it]
Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:02<00:00, 1.29s/it]
Capturing batches (bs=2 avail_mem=54.89 GB): 25%|██▌ | 1/4 [00:00<00:00, 8.00it/s]/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/functions.py:1575: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
torch._dynamo.utils.warn_once(msg)
Capturing batches (bs=1 avail_mem=54.80 GB): 100%|██████████| 4/4 [00:14<00:00, 3.58s/it]
[2025-11-12 15:44:53] SPECULATIVE_MOE_RUNNER_BACKEND is not initialized, using auto backend
Loading pt checkpoint shards: 0% Completed | 0/1 [00:00<?, ?it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:01<00:00, 1.23s/it]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:01<00:00, 1.23s/it]
Capturing batches (bs=1 avail_mem=53.51 GB): 100%|██████████| 4/4 [00:13<00:00, 3.32s/it]
Capturing batches (bs=1 avail_mem=53.37 GB): 100%|██████████| 4/4 [00:00<00:00, 29.40it/s]
NOTE: Typically, the server runs in a separate terminal.
In this notebook, we run the server and notebook code together, so their outputs are combined.
To improve clarity, the server logs are displayed in the original black color, while the notebook outputs are highlighted in blue.
To reduce the log length, we set the log level to warning for the server, the default log level is info.
We are running those notebooks in a CI environment, so the throughput is not representative of the actual performance.
[6]:
client = openai.Client(base_url=f"http://127.0.0.1:{port}/v1", api_key="None")
response = client.chat.completions.create(
model="meta-llama/Llama-2-7b-chat-hf",
messages=[
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0,
max_tokens=64,
)
print_highlight(f"Response: {response}")
[7]:
terminate_process(server_process)
EAGLE-2 Decoding via Frequency-Ranked Speculative Sampling#
By employing a truncated high-frequency token vocabulary in the draft model, Eagle speculative decoding reduces lm_head computational overhead while accelerating the pipeline without quality degradation. For more details, checkout the paper.
In our implementation, set --speculative-token-map to enable the optimization. You can get the high-frequency token in FR-Spec from this model. Or you can obtain high-frequency token by directly downloading these token from this repo.
Thanks for the contribution from Weilin Zhao and Zhousx.
[8]:
server_process, port = launch_server_cmd(
"""
python3 -m sglang.launch_server --model meta-llama/Meta-Llama-3-8B-Instruct --speculative-algorithm EAGLE \
--speculative-draft-model-path lmsys/sglang-EAGLE-LLaMA3-Instruct-8B --speculative-num-steps 5 \
--speculative-eagle-topk 8 --speculative-num-draft-tokens 64 --speculative-token-map thunlp/LLaMA3-Instruct-8B-FR-Spec/freq_32768.pt \
--mem-fraction 0.7 --cuda-graph-max-bs 2 --dtype float16 --log-level warning
"""
)
wait_for_server(f"http://localhost:{port}")
[2025-11-12 15:45:57] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:45:57] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:45:57] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:45:59] WARNING model_config.py:888: Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:45:59] WARNING server_args.py:1197: Attention backend not explicitly specified. Use flashinfer backend by default.
[2025-11-12 15:45:59] WARNING server_args.py:1551: Overlap scheduler is disabled because of using eagle3 or standalone speculative decoding.
[2025-11-12 15:45:59] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:45:59] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:45:59] Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:46:05] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:46:05] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:46:05] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:46:05] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:46:05] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:46:05] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:46:07] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:46:07] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:46:07] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:46:07] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:46:08] Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:46:08] Casting torch.bfloat16 to torch.float16.
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 25% Completed | 1/4 [00:04<00:12, 4.16s/it]
Loading safetensors checkpoint shards: 50% Completed | 2/4 [00:08<00:08, 4.20s/it]
Loading safetensors checkpoint shards: 75% Completed | 3/4 [00:12<00:04, 4.16s/it]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:13<00:00, 2.98s/it]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:13<00:00, 3.42s/it]
Capturing batches (bs=1 avail_mem=59.73 GB): 100%|██████████| 4/4 [00:00<00:00, 13.91it/s]
[2025-11-12 15:46:45] SPECULATIVE_MOE_RUNNER_BACKEND is not initialized, using auto backend
[2025-11-12 15:46:45] Warning: Target model's context_length (8192) is greater than the derived context_length (2048). This may lead to incorrect model outputs or CUDA errors. Note that the derived context_length may differ from max_position_embeddings in the model's config.
[2025-11-12 15:46:45] Overriding the draft model's max_position_embeddings to 8192.
Loading pt checkpoint shards: 0% Completed | 0/1 [00:00<?, ?it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:00<00:00, 1.02it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:00<00:00, 1.02it/s]
Capturing batches (bs=1 avail_mem=58.40 GB): 100%|██████████| 4/4 [00:04<00:00, 1.19s/it]
Capturing batches (bs=1 avail_mem=58.26 GB): 100%|██████████| 4/4 [00:00<00:00, 106.78it/s]
NOTE: Typically, the server runs in a separate terminal.
In this notebook, we run the server and notebook code together, so their outputs are combined.
To improve clarity, the server logs are displayed in the original black color, while the notebook outputs are highlighted in blue.
To reduce the log length, we set the log level to warning for the server, the default log level is info.
We are running those notebooks in a CI environment, so the throughput is not representative of the actual performance.
[9]:
client = openai.Client(base_url=f"http://127.0.0.1:{port}/v1", api_key="None")
response = client.chat.completions.create(
model="meta-llama/Meta-Llama-3-8B-Instruct",
messages=[
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0,
max_tokens=64,
)
print_highlight(f"Response: {response}")
[10]:
terminate_process(server_process)
EAGLE-3 Decoding#
You can enable EAGLE-3 decoding by setting --speculative-algorithm EAGLE3 and choosing an appropriate model.
[11]:
server_process, port = launch_server_cmd(
"""
python3 -m sglang.launch_server --model meta-llama/Llama-3.1-8B-Instruct --speculative-algorithm EAGLE3 \
--speculative-draft-model-path jamesliu1/sglang-EAGLE3-Llama-3.1-Instruct-8B --speculative-num-steps 5 \
--speculative-eagle-topk 8 --speculative-num-draft-tokens 32 --mem-fraction 0.6 \
--cuda-graph-max-bs 2 --dtype float16 --log-level warning
"""
)
wait_for_server(f"http://localhost:{port}")
[2025-11-12 15:47:38] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:47:38] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:47:38] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:47:41] WARNING model_config.py:888: Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:47:41] WARNING server_args.py:1197: Attention backend not explicitly specified. Use flashinfer backend by default.
[2025-11-12 15:47:41] WARNING server_args.py:1551: Overlap scheduler is disabled because of using eagle3 or standalone speculative decoding.
[2025-11-12 15:47:41] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:47:41] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:47:41] Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:47:47] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:47:47] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:47:47] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:47:47] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:47:47] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:47:47] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:47:49] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:47:49] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:47:49] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:47:49] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:47:49] Casting torch.bfloat16 to torch.float16.
[2025-11-12 15:47:50] Casting torch.bfloat16 to torch.float16.
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 25% Completed | 1/4 [00:04<00:12, 4.27s/it]
Loading safetensors checkpoint shards: 50% Completed | 2/4 [00:08<00:08, 4.34s/it]
Loading safetensors checkpoint shards: 75% Completed | 3/4 [00:12<00:04, 4.31s/it]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:14<00:00, 3.17s/it]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:14<00:00, 3.59s/it]
Capturing batches (bs=1 avail_mem=59.67 GB): 100%|██████████| 4/4 [00:00<00:00, 10.01it/s]
[2025-11-12 15:48:29] SPECULATIVE_MOE_RUNNER_BACKEND is not initialized, using auto backend
[2025-11-12 15:48:29] Warning: Target model's context_length (131072) is greater than the derived context_length (2048). This may lead to incorrect model outputs or CUDA errors. Note that the derived context_length may differ from max_position_embeddings in the model's config.
[2025-11-12 15:48:29] Overriding the draft model's max_position_embeddings to 131072.
Loading pt checkpoint shards: 0% Completed | 0/1 [00:00<?, ?it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:00<00:00, 1.89it/s]
Loading pt checkpoint shards: 100% Completed | 1/1 [00:00<00:00, 1.89it/s]
Capturing batches (bs=1 avail_mem=58.19 GB): 100%|██████████| 4/4 [00:04<00:00, 1.20s/it]
Capturing batches (bs=1 avail_mem=58.04 GB): 100%|██████████| 4/4 [00:00<00:00, 98.09it/s]
NOTE: Typically, the server runs in a separate terminal.
In this notebook, we run the server and notebook code together, so their outputs are combined.
To improve clarity, the server logs are displayed in the original black color, while the notebook outputs are highlighted in blue.
To reduce the log length, we set the log level to warning for the server, the default log level is info.
We are running those notebooks in a CI environment, so the throughput is not representative of the actual performance.
[12]:
client = openai.Client(base_url=f"http://127.0.0.1:{port}/v1", api_key="None")
response = client.chat.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
messages=[
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0,
max_tokens=64,
)
print_highlight(f"Response: {response}")
[13]:
terminate_process(server_process)
Multi Token Prediction#
We support MTP(Multi-Token Prediction) in SGLang by using speculative decoding. We use Xiaomi/MiMo-7B-RL model as example here (deepseek mtp usage refer to deepseek doc)
[14]:
server_process, port = launch_server_cmd(
"""
python3 -m sglang.launch_server --model-path XiaomiMiMo/MiMo-7B-RL --host 0.0.0.0 --trust-remote-code \
--speculative-algorithm EAGLE --speculative-num-steps 1 --speculative-eagle-topk 1 --speculative-num-draft-tokens 2 \
--mem-fraction 0.5 --log-level warning
"""
)
wait_for_server(f"http://localhost:{port}")
[2025-11-12 15:49:23] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:49:23] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:49:23] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:49:25] WARNING server_args.py:1197: Attention backend not explicitly specified. Use flashinfer backend by default.
[2025-11-12 15:49:25] WARNING server_args.py:1551: Overlap scheduler is disabled because of using eagle3 or standalone speculative decoding.
[2025-11-12 15:49:25] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:49:25] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:49:31] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:49:31] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:49:31] INFO utils.py:148: Note: detected 112 virtual cores but NumExpr set to maximum of 64, check "NUMEXPR_MAX_THREADS" environment variable.
[2025-11-12 15:49:31] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:49:31] INFO utils.py:151: Note: NumExpr detected 112 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16.
[2025-11-12 15:49:31] INFO utils.py:164: NumExpr defaulting to 16 threads.
[2025-11-12 15:49:33] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:49:33] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[2025-11-12 15:49:33] INFO trace.py:69: opentelemetry package is not installed, tracing disabled
[2025-11-12 15:49:33] WARNING memory_pool_host.py:36: Current platform not support pin_memory
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 25% Completed | 1/4 [00:00<00:02, 1.49it/s]
Loading safetensors checkpoint shards: 50% Completed | 2/4 [00:01<00:01, 1.38it/s]
Loading safetensors checkpoint shards: 75% Completed | 3/4 [00:02<00:00, 1.23it/s]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:03<00:00, 1.24it/s]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:03<00:00, 1.27it/s]
Capturing batches (bs=1 avail_mem=60.22 GB): 100%|██████████| 4/4 [00:11<00:00, 2.87s/it]
[2025-11-12 15:50:11] SPECULATIVE_MOE_RUNNER_BACKEND is not initialized, using auto backend
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 25% Completed | 1/4 [00:00<00:00, 4.99it/s]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:00<00:00, 7.83it/s]
Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:00<00:00, 7.50it/s]
Capturing batches (bs=1 avail_mem=59.37 GB): 100%|██████████| 4/4 [00:00<00:00, 57.21it/s]
NOTE: Typically, the server runs in a separate terminal.
In this notebook, we run the server and notebook code together, so their outputs are combined.
To improve clarity, the server logs are displayed in the original black color, while the notebook outputs are highlighted in blue.
To reduce the log length, we set the log level to warning for the server, the default log level is info.
We are running those notebooks in a CI environment, so the throughput is not representative of the actual performance.
[15]:
import requests
url = f"http://localhost:{port}/v1/chat/completions"
data = {
"model": "XiaomiMiMo/MiMo-7B-RL",
"messages": [{"role": "user", "content": "What is the capital of France?"}],
}
response = requests.post(url, json=data)
print_highlight(response.json())
[16]:
terminate_process(server_process)
References#
EAGLE process is as follows:
Within EAGLE the draft model predicts the next feature vector, i.e. the last hidden state of the original LLM, using the feature sequence \((f_1, ..., f_k)\) and the token sequence \((t_2, ..., t_{k+1})\).
The next token is then sampled from \(p_{k+2}=\text{LMHead}(f_{k+1})\). Afterwards, the two sequences are extended in a tree style—branching out multiple potential continuations, with the branching factor per step controlled by the
speculative_eagle_topkparameter—to ensure a more coherent connection of context, and are given as input again.EAGLE-2 additionally uses the draft model to evaluate how probable certain branches in the draft tree are, dynamically stopping the expansion of unlikely branches. After the expansion phase, reranking is employed to select only the top
speculative_num_draft_tokensfinal nodes as draft tokens.EAGLE-3 removes the feature prediction objective, incorporates low and mid-layer features, and is trained in an on-policy manner.
This enhances drafting accuracy by operating on the features instead of tokens for more regular inputs and passing the tokens from the next timestep additionally to minimize randomness effects from sampling. Furthermore the dynamic adjustment of the draft tree and selection of reranked final nodes increases acceptance rate of draft tokens further. For more details see EAGLE-2 and EAGLE-3 paper.
For guidance how to train your own EAGLE model please see the EAGLE repo.