[Speculative decoding] feat: add EAGLE3 speculative decoding support
[!IMPORTANT] The old PR has been backed up in this branch: https://github.com/ruixiang63/llama.cpp/tree/eagle3-v1-backup The new commits in this PR have been rebased onto the latest master branch, refactored to use the new speculative API, cherry-picked from https://github.com/ggml-org/llama.cpp/pull/22728, and made compatible with MTP.
[!TIP] New Eagle3 models for Gemma4 are now supported. With reasoning enabled, speedup can exceed 2x. With reasoning disabled, it can reach over 3x. See https://github.com/ggml-org/llama.cpp/pull/18039#issuecomment-4500827273 With
Q4_K_Mquantization, the speedup still looks good. https://github.com/ggml-org/llama.cpp/pull/18039#issuecomment-4507174617
As discussed in https://github.com/ggml-org/llama.cpp/discussions/15902, Eagle3 represents the current SOTA in speculative decoding and is widely adopted across the industry. Integrating Eagle3 into llama.cpp enhances its performance and strengthens its competitiveness among leading inference frameworks. With Eagle3 speculative decoding now integrated into llama.cpp, inference performance has been significantly improved, achieving a 2–3× speedup. This enhancement is the result of close collaboration between the NVIDIA and GGML teams, showcasing a strong technical partnership.
The following provides a brief overview of this PR:
EAGLE3 is an encoder-decoder based speculative decoding method:
- Extracts features from target model at specific layers
- Uses feature fusion layer to compress target features
- Generates draft tokens with single-layer decoder
- Maps draft vocabulary to target vocabulary via d2t tensor
Key changes:
- Add LLM_ARCH_EAGLE3 architecture
- Add EAGLE3 encoder/decoder graph (src/models/eagle3.cpp)
- Add feature extraction from target model layers
- Add g_embeddings handling for decoder input
- Add GGML_TENSOR_FLAG_SYNC for GPU synchronization
- Add --eagle3 flag for speculative-simple example
- Add EAGLE3 model conversion in convert_hf_to_gguf.py
EAGLE3 Architecture Overview :
┌─────────────────────────────────────────────────────────────────┐
│ EAGLE3 Overview │
└─────────────────────────────────────────────────────────────────┘
Target Model EAGLE3 Encoder EAGLE3 Decoder
(LLaMA 8B) (FC Layer) (1-layer Transformer)
│ │ │
│ │ │
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────────┐
│ Generate │ │ Compress │ │ Generate Draft │
│ Features │───────►│ Features │───────►│ Tokens Fast │
│ [12288] │ │ [4096] │ │ [k tokens] │
└─────────────┘ └─────────────┘ └────────┬────────┘
│
▼
┌─────────────────┐
│ Verify Drafts │
│ with Target │
└─────────────────┘
How to run EAGLE3 in llama.cpp
Requirements
This PR currently ~~only supports two~~ supports following EAGLE3 models:
- RedHatAI/gemma-4-31B-it-speculator.eagle3
- RedHatAI/gemma-4-26B-A4B-it-speculator.eagle3
- yuhuili/EAGLE3-LLaMA3.1-Instruct-8B
- yuhuili/EAGLE3-LLaMA3.3-Instruct-70B
- Tengyunw/qwen3_8b_eagle3
- Tengyunw/qwen3_30b_moe_eagle3
- AngelSlim/Qwen3-8B_eagle3
- AngelSlim/Qwen3-14B_eagle3
- AngelSlim/Qwen3-32B_eagle3
- AngelSlim/Qwen3-30B-A3B_eagle3
- lmsys/EAGLE3-gpt-oss-120b-bf16 (with performance issue due to its MoE arch)
- nvidia/gpt-oss-120b-Eagle3-long-context (with performance issue due to its MoE arch)
- RedHatAI/Qwen3-8B-speculator.eagle3
- RedHatAI/gpt-oss-20b-speculator.eagle3 (with performance issue due to its MoE arch)
- RedHatAI/Qwen3-30B-A3B-Instruct-2507-speculator.eagle3
The following eagle3 models should also work out of the box, though they haven’t been tested yet:
- AngelSlim/Qwen3-4B_eagle3
- AngelSlim/Qwen3-1.7B_eagle3
- Zjcxy-SmartAI/Eagle3-Qwen3-4B-Instruct-2507-zh
- Zjcxy-SmartAI/Eagle3-Qwen3-32B-zh
- Zjcxy-SmartAI/Eagle3-Qwen3-8B-zh
- Qwen3-235B-A22B-EAGLE3
- RedHatAI/Qwen3-14B-speculator.eagle3
- RedHatAI/Qwen3-32B-speculator.eagle3
- RedHatAI/Qwen3-235B-A22B-Instruct-2507-speculator.eagle3
- RedHatAI/Qwen3-235B-A22B-speculator.eagle3
Step 1: Convert Models to GGUF Format
- Convert Target Model
TARGET_MODEL_HF="${MODELS_DIR}/Meta-Llama-3.1-8B-Instruct"
TARGET_MODEL_GGUF="${MODELS_DIR}/Meta-Llama-3.1-8B-Instruct_bf16.gguf"
python convert_hf_to_gguf.py \
"${TARGET_MODEL_HF}" \
--outtype bf16 \
--outfile "${TARGET_MODEL_GGUF}"
- Convert EAGLE3 Draft Model
TARGET_MODEL_HF="${MODELS_DIR}/Meta-Llama-3.1-8B-Instruct"
EAGLE3_MODEL_HF="${MODELS_DIR}/EAGLE3-LLaMA3.1-Instruct-8B"
EAGLE3_MODEL_GGUF="${MODELS_DIR}/EAGLE3-LLaMA3.1-Instruct-8B_fp16.gguf"
python convert_hf_to_gguf.py \
"${EAGLE3_MODEL_HF}" \
--outtype f16 \
--target-model-dir "${TARGET_MODEL_HF}" \
--outfile "${EAGLE3_MODEL_GGUF}"
Step 2: Compile llama.cpp
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release
[Optional] Step 3: Quantize the GGUF model
./build/bin/llama-quantize \
${TARGET_MODEL_GGUF} \
${TARGET_MODEL_GGUF}_Q4_K_M.gguf \
Q4_K_M
./build/bin/llama-quantize \
${EAGLE3_MODEL_GGUF} \
${EAGLE3_MODEL_GGUF}_Q4_K_M.gguf \
Q4_K_M
Step 4: Run EAGLE3 Speculative Decoding
./build/bin/llama-server \
-m Qwen3-8B.gguf \
-md qwen3_8b_eagle3.gguf \
--spec-type draft-eagle3 \
--spec-draft-n-max 8 \
--spec-draft-p-min 0.5 \
-np 1 \
-c 4096 --port 8080 -ngl 99 -fa on \
--jinja --fit off
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "Write a quicksort algorithm in Python. Write code only."}
],
"max_tokens": 256,
"temperature": 0
}'
curl -X POST http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "Explain the Pythagorean theorem"}
],
"max_tokens": 256,
"temperature": 0
}'
Performance Evaluation (RTX A6000 48GB)
[!TIP] Using the chat_template for each model version can improve acceptance rates. Always apply the model’s corresponding chat_template when constructing prompts.
[!NOTE] After refactoring, the performance data below may differ from current results, especially since
llama-servernow supports Eagle3 as well. However, the data is still useful for getting a general sense of the speedup Eagle3 provides.
- LLaMA3.1-Instruct-8B with
BF16, its Eagle3 withFP16
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 44.5 t/s | 146.2 t/s | 80.6% | 3.28x |
| Explain the Pythagorean theorem | 44.5 t/s | 127.1 t/s | 77.4% | 2.85x |
| Plan a 1 day trip to DC | 44.5 t/s | 113.8 t/s | 80.9% | 2.55x |
- LLaMA3.1-Instruct-8B with
Q4_K_M, its Eagle3 withQ4_K_M
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 121.5 t/s | 274.4 t/s | 92.5% | 2.26x |
| Explain the Pythagorean theorem | 121.4 t/s | 238.9 t/s | 79.4% | 1.97x |
| Plan a 1 day trip to DC | 121.4 t/s | 196.5 t/s | 77.2% | 1.62x |
- LLaMA3.3-Instruct-70B with
Q4_K_M, its Eagle3 withQ4_K_M
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 15.6 t/s | 33.4 t/s | 73.6% | 2.14x |
| Explain the Pythagorean theorem | 15.6 t/s | 37.6 t/s | 82.0% | 2.41x |
| Plan a 1 day trip to DC | 15.6 t/s | 28.8 t/s | 69.3% | 1.85x |
- Qwen3-8B with
BF16, its Eagle3 withBF16
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 43.6 t/s | 94.8 t/s | 69.8% | 2.17x |
| Explain the Pythagorean theorem | 43.6 t/s | 86.8 t/s | 68.3% | 1.99x |
| Plan a 1 day trip to DC | 43.6 t/s | 70.7 t/s | 57.3% | 1.62x |
- Qwen3-14B with
BF16, its Eagle3 withBF16
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 24.4 t/s | 35.7 t/s | 40.4% | 1.46x |
| Explain the Pythagorean theorem | 24.4 t/s | 34.5 t/s | 41.3% | 1.41x |
| Plan a 1 day trip to DC | 24.3 t/s | 30.5 t/s | 28.0% | 1.26x |
- Qwen3-32B with
Q4_K_M, its Eagle3 withQ4_K_M
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 32.0 t/s | 39.7 t/s | 39.7% | 1.24x |
| Explain the Pythagorean theorem | 32.0 t/s | 41.5 t/s | 43.3% | 1.30x |
| Plan a 1 day trip to DC | 32.0 t/s | 37.1 t/s | 32.6% | 1.16x |
- Qwen3-30B-A3B with
BF16, its Eagle3 withBF16(tested on NVIDIA DGX Spark 128GB, speedup might be better on other hardwares)
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 31.1 t/s | 43.3 t/s | 64.4% | 1.39x |
| Explain the Pythagorean theorem | 31.2 t/s | 41.2 t/s | 60.6% | 1.32x |
| Plan a 1 day trip to DC | 30.9 t/s | 38.6 t/s | 58.8% | 1.25x |
- GPT-OSS-20B with
BF16, its Eagle3 withBF16(tested on NVIDIA DGX Spark 128GB, similar performance issue as GPT-OSS-120B Eagle3)
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 61.3 t/s | 65.05 t/s | 74.25% | 1.06x |
| Explain the Pythagorean theorem | 61.2 t/s | 58.13 t/s | 69.23% | 0.95x |
| Plan a 1 day trip to DC | 61.4 t/s | 54.50 t/s | 62.96% | 0.89x |
~~Details of GGML backend modifications~~ (Fixed, no longer needed)
~~In the Eagle3 decoder, two parallel inputs are processed:~~
input_embeds ──→ RMS_NORM ──┐
├──→ CONCAT ──→ Transformer Decoder
g_embeddings ──→ RMS_NORM ──┘
~~When both RMS_NORM operations run in the same GPU split, a lack of synchronization causes buffer contention and race conditions (CPU execution is fine as it auto‑syncs between subgraphs).~~
~~Solution:~~
~~Use ggml_set_sync() to add a synchronization point after the first RMS_NORM, forcing the scheduler to create a split boundary and synchronize before continuing.~~
input_embeds ──→ RMS_NORM ──→ [SYNC] ──┐
├──→ CONCAT ──→ Transformer Decoder
g_embeddings ─────────────→ RMS_NORM ──┘
(split 1) | (split 2)
barrier
~~This ensures correct execution and can be applied to any parallel path that needs synchronization, not just Eagle3.~~
Examples results
examples
-
Prompt: "Write a quicksort algorithm in Python. Write code only."
-
Prompt: "Explain the Pythagorean theorem"
-
Prompt: "Plan a 1 day trip to DC"
Future Steps
- Support more Eagle3 models, currently support Qwen, GPT-OSS, Llama
- ~Currently, Eagle3 is integrated only in llama-speculative-simple, support may need to be extended to other APIs if possible~ It now supports llama-server
- Support context-dependent tree sampling (tree attention) as described in the Eagle3 paper to improve accept rate
- ~Support batch processing (batch size > 1) with Eagle3 speculative decoding~
Judging by the description of this PR, I believe many models with multiple-token prediction also have the same strategy of reusing hidden features from the main model.
It can be quite interesting to generalize this features to support other models. I would expect some kind of sub-llama_context that allow both the main and draft models to share the same cgraph, avoiding the need of explicitly passing the intermediate embedding through the host memory.
It can be quite interesting to generalize this features to support other models.
I will definitely be looking at refactoring the implementation to become more generic before merging it. The initial results in terms of performance are really great, but we'll need to work on cleaning up the code and reduce the special-casing in several places. I'll try to provide insights how to do that in the next days.
It can be quite interesting to generalize this features to support other models.
I will definitely be looking at refactoring the implementation to become more generic before merging it. The initial results in terms of performance are really great, but we'll need to work on cleaning up the code and reduce the special-casing in several places. I'll try to provide insights how to do that in the next days.
Thanks @ggerganov @ngxson for your inputs. Definitely, looking forward to hearing your feedback and improving this PR.
Bumping, is there any progress on this? It's probably one of the more coveted features to have right now.
Bumping, is there any progress on this?
I'm currently side-tracked by some graph reallocation optimizations. Will probably come back to this after that.
Eagle3 checkpoints for the Qwen3 series (including both dense and MoE models) are now supported, see the updated PR description for details. Although these Eagle3 checkpoints are from third party, they can still deliver a 1–2× speedup. Speculative decoding performance for MoE models is not as good as dense models, which is expected, since more experts are invoked during the parallel verification phase than during the target model’s decoding phase.
One question: it seems that CUDA Graph is disabled when the input n_tokens > 1. During the target model verification stage of speculative decoding, CUDA Graph is always disabled for the target model, since it’s only used for verification with multiple draft tokens > 1. However, we can fix the number of draft tokens (e.g., by using padding) to make it constant and thus enable CUDA Graph (may need to remove n_tokens > 1 constraint)? @ggerganov
Context: I’m testing GPT-OSS-120B Eagle3 with llama.cpp, and I found that even with Eagle3 (accept rate 86%), the performance is worse than the naive llama-cli. After profiling, I discovered that CUDA Graph is consistently disabled for the target model during speculative decoding, whereas it remains enabled in llama-cli. This results in the target model’s verification(prefiling) phase being roughly >5× times slower compared to normal autoregressive decoding step.
After disabling CUDA graphs for llama-cli using GGML_CUDA_DISABLE_GRAPHS=1, the eagle3 achieved roughly a 1.5× speedup.
I’ve only observed this performance issue with GPT-OSS-120B Eagle3. For other models, even without CUDA Graph enabled for target model in Eagle3 speculative decoding, the performance remains great.
Speculative decoding performance for MoE models is not as good as dense models, which is expected, since more experts are invoked during the parallel verification phase than during the target model’s decoding phase.
I think the small-batch mul_mat_id could be improved in the CUDA backend. AFAIR there the performance for batch sizes (1, 8] is not optimal atm. Need double check.
However, we can fix the number of draft tokens (e.g., by using padding) to make it constant and thus enable CUDA Graph (may need to remove n_tokens > 1 constraint)? @ggerganov
Possibly, but to me this sounds like second-order optimization. Optimizing the mul_mat_id for small batches should bring more generic benefits and would likely have larger impact for speculative decoding compared to enabling CUDA graphs.
After disabling CUDA graphs for llama-cli using GGML_CUDA_DISABLE_GRAPHS=1, the eagle3 achieved roughly a 1.5× speedup.
Hm, this is a bit surprising observation. Can you run a llama-batched-bench test on your system with and without CUDA graphs using the commands from https://github.com/ggml-org/llama.cpp/discussions/18308#discussioncomment-15324617 and share the results. We are interested in batch sizes [1, 4]. So something like this:
llama-batched-bench -m [gpt-oss-120b] -c 65536 -b 2048 -ub 512 -npp 1024 -ntg 32 -npl 1,2,3,4,5,6,7,8
Thanks very much for your inputs! @ggerganov
After disabling CUDA graphs for llama-cli using GGML_CUDA_DISABLE_GRAPHS=1, the eagle3 achieved roughly a 1.5× speedup.
Hm, this is a bit surprising observation. Can you run a llama-batched-bench test on your system with and without CUDA graphs using the commands from https://github.com/ggml-org/llama.cpp/discussions/18308#discussioncomment-15324617 and share the results. We are interested in batch sizes [1, 4]. So something like this:
I double-checked the run today. The previous statement about cuda graph was incorrect due to instability and concurrent CPU activity in my test environment, sorry about that! Currently, enabling or disabling CUDA Graphs doesn’t have much impact in llama-cli for GPT-OSS-120B model. (I am testing on DGX Spark)
- with cuda graph enabled: [ Prompt: 120.1 t/s | Generation: 47.2 t/s ]
- without cuda graph enabled: [ Prompt: 119.2 t/s | Generation: 45.7 t/s ]
Also, the results for llama-batched-bench:
- with cuda graph enabled
| PP | TG | B | N_KV | T_PP s | S_PP t/s | T_TG s | S_TG t/s | T s | S t/s |
|---|---|---|---|---|---|---|---|---|---|
| 1024 | 256 | 1 | 1280 | 1.227 | 834.89 | 5.255 | 48.71 | 6.482 | 197.47 |
| 1024 | 256 | 2 | 2560 | 1.579 | 1296.74 | 9.277 | 55.19 | 10.856 | 235.81 |
| 1024 | 256 | 3 | 3840 | 2.284 | 1344.72 | 10.447 | 73.51 | 12.731 | 301.61 |
| 1024 | 256 | 4 | 5120 | 3.031 | 1351.58 | 11.550 | 88.66 | 14.580 | 351.16 |
| 1024 | 256 | 5 | 6400 | 3.780 | 1354.59 | 12.433 | 102.96 | 16.212 | 394.76 |
| 1024 | 256 | 6 | 7680 | 4.528 | 1356.95 | 13.347 | 115.08 | 17.874 | 429.66 |
| 1024 | 256 | 7 | 8960 | 5.304 | 1351.48 | 13.982 | 128.16 | 19.286 | 464.59 |
| 1024 | 256 | 8 | 10240 | 6.018 | 1361.20 | 14.704 | 139.28 | 20.722 | 494.16 |
- without cuda graph enabled
| PP | TG | B | N_KV | T_PP s | S_PP t/s | T_TG s | S_TG t/s | T s | S t/s |
|---|---|---|---|---|---|---|---|---|---|
| 1024 | 256 | 1 | 1280 | 1.279 | 800.61 | 5.758 | 44.46 | 7.037 | 181.90 |
| 1024 | 256 | 2 | 2560 | 1.597 | 1282.22 | 9.297 | 55.07 | 10.895 | 234.98 |
| 1024 | 256 | 3 | 3840 | 2.286 | 1343.84 | 10.383 | 73.97 | 12.669 | 303.11 |
| 1024 | 256 | 4 | 5120 | 3.031 | 1351.51 | 11.547 | 88.68 | 14.577 | 351.23 |
| 1024 | 256 | 5 | 6400 | 3.771 | 1357.64 | 12.438 | 102.91 | 16.209 | 394.84 |
| 1024 | 256 | 6 | 7680 | 4.525 | 1357.71 | 13.342 | 115.12 | 17.868 | 429.83 |
| 1024 | 256 | 7 | 8960 | 5.289 | 1355.17 | 13.986 | 128.13 | 19.275 | 464.84 |
| 1024 | 256 | 8 | 10240 | 5.999 | 1365.48 | 14.653 | 139.77 | 20.652 | 495.83 |
Possibly, but to me this sounds like second-order optimization. Optimizing the mul_mat_id for small batches should bring more generic benefits and would likely have larger impact for speculative decoding compared to enabling CUDA graphs.
I agree. CUDA graphs could be second-order optimization. Here are the eagle3 GPT-OSS-120B test results on DGX spark: (I will also test this on other hardwares)
| Prompt | Baseline (llama-cli) | EAGLE3 (draft_size=8) | Accept Rate | Speedup |
|---|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 48.3 t/s | 52.2 t/s | 85.0% | 1.08x |
| Explain the Pythagorean theorem | 47.8 t/s | 46.5 t/s | 74.0% | 0.97x |
| Plan a 1 day trip to DC | 48.4 t/s | 40.0 t/s | 55.7% | 0.83x |
For MoE models, prefilling becomes the main performance bottleneck because more active experts are involved. As a result, the assumption that “processing multiple draft tokens concurrently is as fast as processing a single token” no longer holds, which is an important condition for effective speculative decoding. I also saw that as the draft token length increases, the verification cost of the target model also rises. This explains the results shown in the table above, in some cases, Eagle3 can even degrade performance. To observe improvements, the accept rate must exceed a certain lower bound.
Do you have any rough ideas that how much performance gain we can get through imporving mul_mat_id?
The llama-batched-bench results are actually better than I expected. In the previous reported numbers there was a sharp dip at BS = 2. Here the TG performance steadily increases with the batch size which is good, though it is not as linear as we want it to be.
I suppose the explanation is that for MoE models, at low batch sizes the amount of data we need to read from the weights for each batch increases linearly with the batch size (i.e. each extra token in the batch activates more experts and at small batch size the experts for each token are very likely different from each other). So it's probably normal that TG for MoE does not scale as well as TG for dense models as a function of the batch size.
As a result, the assumption that “processing multiple draft tokens concurrently is as fast as processing a single token” no longer holds, which is an important condition for effective speculative decoding.
Yeah, that's my guess as well. Do we have some references to cross-check this? Does the Eagle3 authors discuss it's performance for MoE models? Do we have sample numbers for gpt-oss-120 with Eagle3 using vllm, trrt?
Do you have any rough ideas that how much performance gain we can get through imporving mul_mat_id?
Hm, not sure. Thinking about it now, I feel like mul_mat_id is unlikely to scale good enough due to the increasing data for each new token.
The following eagle3 models should also work out of the box, though they haven’t been tested yet: Qwen3-235B-A22B-EAGLE3
I tested the Baichuan-M3-235B model that was released yesterday (draft here). It's a finetune of the Qwen3 model above. It quantized successfully but failed due to having a different tensor shape (even in the original weights):
load_tensors: EAGLE3 using d2t mapping (draft_vocab_size = 32000)
llama_model_load: error loading model: check_tensor_dims: tensor 'blk.0.attn_q.weight' has wrong shape; expected 8192, 8192, got 8192, 16384, 1, 1
llama_model_load_from_file_impl: failed to load model
failed to load EAGLE3 draft model
I haven't looked into how often this to happen in finetunes of the same model, especially in the context of eagle3.
However, the shapes of the tensors changing might be something to account for in the implementation (in this case Qwen3). Unless those will be treated as completely new models, in which case please disregard this comment.
The following eagle3 models should also work out of the box, though they haven’t been tested yet: Qwen3-235B-A22B-EAGLE3
I tested the Baichuan-M3-235B model that was released yesterday (draft here). It's a finetune of the Qwen3 model above. It quantized successfully but failed due to having a different tensor shape (even in the original weights):
load_tensors: EAGLE3 using d2t mapping (draft_vocab_size = 32000) llama_model_load: error loading model: check_tensor_dims: tensor 'blk.0.attn_q.weight' has wrong shape; expected 8192, 8192, got 8192, 16384, 1, 1 llama_model_load_from_file_impl: failed to load model failed to load EAGLE3 draft modelI haven't looked into how often this to happen in finetunes of the same model, especially in the context of eagle3.
However, the shapes of the tensors changing might be something to account for in the implementation (in this case Qwen3). Unless those will be treated as completely new models, in which case please disregard this comment.
I spent some time analyzing the Baichuan-EAGLE3 draft model. It has a slightly different architecture compared to the standard Qwen3-EAGLE3 model.
The main difference is in the self_attn.q_proj.weight tensor shape:
- Standard Qwen3-EAGLE3 :
[8192, 8192]— outputs Q only - Baichuan-EAGLE3:
[16384, 8192]— outputs Q + Gate (2× the size)
This is because Baichuan-EAGLE3 uses an Attention Output Gate mechanism, which is not present in the standard EAGLE3 model. In this variant:
- The Q projection outputs both query vectors and gate vectors
- After attention computation, the output is element-wise multiplied by sigmoid(gate) before the output projection
This is essentially a variant architecture of EAGLE3, not just a tensor shape difference. Supporting this variant would require:
- Detecting the gate mechanism during model loading
- Modifying the graph construction to split Q/Gate and apply the gating after attention
- Adding the ggml_sigmoid operation in the attention path
I would suggest we focus this PR on the standard EAGLE3 model first. Once merged, we can consider adding support for this gated variant in a follow-up PR.
Have you tested the standard Qwen3-EAGLE3 model as well? Does it work well with the current implementation? If yes, could you please share the t/s and speedup you got with eagle3? @arch-btw
Since EAGLE3 can vary quite a lot for each model, maybe a better way is to consider it as an adapter (the same logic as lora adapter), instead of a dedicated arch?
That way, it can hook into existing models more easily, making internal data like KV state, gate, etc, accessible to the draft model.
Since EAGLE3 can vary quite a lot for each model, maybe a better way is to consider it as an adapter (the same logic as lora adapter), instead of a dedicated arch?
That way, it can hook into existing models more easily, making internal data like KV state, gate, etc, accessible to the draft model.
Good point. However, Eagle3 doesn’t vary much across models. So far, except for Baichuan-Eagle3, all other models essentially use the same Eagle3 architecture. Please refer to the supported models listed in the PR description. I’d say the majority of models share the same Eagle3 architecture, with only a few exceptions. This standalone Eagle3 architecture strategy is also adopted in TensorRT-LLM, vLLM, and SGLang.
I doubt that. In theory, nothing prevent them or another team from making a variant of eagle3 that get the state of more than 3 layers, or even reuse the KV state from earlier layers. Possibilities are endless, and that's why it's important to think about the bigger picture instead of just trying to make it work with one single existing architecture.
I think a more model-agnostic approach via adapter API (or another API based on that form) will likely be the way ultimately. It will allow computing both the next token + draft token in one pass, allowing even higher performance than this approach.
I doubt that. In theory, nothing prevent them or another team from making a variant of eagle3 that get the state of more than 3 layers, or even reuse the KV state from earlier layers. Possibilities are endless, and that's why it's important to think about the bigger picture instead of just trying to make it work with one single existing architecture.
Could you please share some examples or real-world use cases of this? I’d like to better understand how such an approach might be applied in practice.
The main problem with this PR and https://github.com/ggml-org/llama.cpp/pull/15225 is that both assumes that the MTP (multi-token prediction) to work this way:
- main LLM generates first tokens + hidden_state from a list of selected layers
- hidden_state is then forwarded to the speculative model to generate N next tokens
(Note: the dash line is to tell that it's may not be the case for all models; some only use the last hidden state)
While it does work for the moment, this approach doesn't address the true nature of MTP models. In other words, it is not truly model-agnostic. The main drawbacks is that you must manually pass the embeddings between 2 models, so you must know where to get the embeddings, its shapes, etc.
Instead, we should look at MTP models as a normal LLM with multiple output heads:
In this POV, it's not matter what is the implementation of the mtp_head. From the outside world, the model will just output N next tokens given one input token.
In practice, the mtp_head(s) can be:
- A single encoder model in eagle3 case
- Some extra N layers in GLM/deepseek case, N+1 layer use output from N-th layer (serial setup)
- Some extra N layers in Xiaomi Mimo case, but all layers use the same input embeddings (parallel setup) - see https://github.com/ggml-org/llama.cpp/pull/13236 for more info
Now, returning to your question:
Could you please share some examples or real-world use cases of this? I’d like to better understand how such an approach might be applied in practice.
If you already get the idea above, then consider gemma3n: the model has 30 layers, but only 20 layers has KV projection. The last 10 layers reuse the KV from the 20-th layer. Some models also implement this idea, notably GLM, bailing.
The same idea can be apply to MTP layers. Future models may has MTP layers to not just reuse the layer output hidden state, but also the projected KV inside the layer. While there is no models in the wild currently doing that, Baichuan-EAGLE3 (as you shown), already someway heading towards this direction by exposing both the Q+gate to the MTP model.
(I have to split up my comment otherwise it's too long)
My proposal is that we must design this function + the API in a way that it is flexible enough for future models.
For EAGLE3, the MTP model is technically a mtp_head shipped as an extension to the main model (note that the eagle3 repo only contains the extra tensors, but does not contain the main LLM), it can be viewed as an adapter, much like how LoRA works.
For the API, we must avoid leaking the information about the implementation under the hood. The downstream code must only know about how many tokens can be generated, they don't need to know how to generate these extra tokens.
So, an array of API as follow should be enough:
llama_model_load_mtp: load the mtp as allama_adapter_loraor maybe we can add a new struct for itllama_mtp_set_n_draft: set the max number of draft tokens to be generated in the nextllama_decode; set to0for verification passllama_mtp_get_n_draft_max: get max number of draft tokens that the MTP head can generatellama_mtp_get_logits_ith: get logits at for i-th token in batch, returns array of float with sizen_vocab*n_draft
All the info about embeddings and the draft model must be kept private.
CC @ggerganov maybe this is helpful for you
Yeah, that's my guess as well. Do we have some references to cross-check this? Does the Eagle3 authors discuss it's performance for MoE models? Do we have sample numbers for gpt-oss-120 with Eagle3 using vllm, trrt?
As far as I know, the Eagle3 authors did not discuss their approach to MoE model performance in their paper. I am currently cross-checking the performance of GPT-OSS-120B Eagle3 on DGX Spark using SGLang, which essentially employs the same GPT-OSS-120B-Eagle3 draft model as I used for llama.cpp testing.
The running commands I used are as follows: • Baseline: Run the GPT-OSS-120B target model only.
python3 -m sglang.launch_server --model-path gpt-oss-120b --host 0.0.0.0 --port 30000 --trust-remote-code
• Eagle3: Set the draft size to 8 and disable tree decoding to ensure a fair comparison with our tests on llama.cpp.
python3 -m sglang.launch_server --model gpt-oss-120b --speculative-algorithm EAGLE3 --speculative-draft-model-path lmsys/EAGLE3-gpt-oss-120b-bf16 --speculative-num-steps 8 --speculative-eagle-topk 1 --speculative-num-draft-tokens 8 --trust-remote-code --host 0.0.0.0 --port 30000
I am using curl to test prompts, e.g.
curl -sS -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "Write a quicksort algorithm in Python. Write code only.",
"sampling_params": {
"max_new_tokens": 256
}
}' | python3 -c "
import sys, json
d = json.load(sys.stdin)
tokens = d['meta_info']['completion_tokens']
latency = d['meta_info']['e2e_latency']
tps = tokens / latency
print(f'completion_tokens: {tokens}')
print(f'e2e_latency: {latency:.3f}s')
print(f'token/s: {tps:.2f}')
"
Here are the test results on DGX spark:
| Prompt | Baseline | EAGLE3 (draft_size=8) | Speedup |
|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 52.50 t/s | 36.4 t/s | 0.69x |
| Explain the Pythagorean theorem | 52.64 t/s | 24.4 t/s | 0.46x |
| Plan a 1 day trip to DC | 52.69 t/s | 24.7 t/s | 0.47x |
I also tested shorter draft sizes using the following command:
python3 -m sglang.launch_server --model /home/nvidia/models/gpt-oss-120b --speculative-algorithm EAGLE3 --speculative-draft-model-path /home/nvidia/ruixiangw/models/lmsys/EAGLE3-gpt-oss-120b-bf16 --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 --trust-remote-code --host 0.0.0.0 --port 30000
The results:
| Prompt | Baseline | EAGLE3 (draft_size=3) | Speedup |
|---|---|---|---|
| Write a quicksort algorithm in Python. Write code only. | 52.50 t/s | 37.36 t/s | 0.71x |
| Explain the Pythagorean theorem | 52.64 t/s | 27.96 t/s | 0.53x |
| Plan a 1 day trip to DC | 52.69 t/s | 26.53 t/s | 0.50x |
From the tables above, we observed similar performance degradation for GPT-OSS-120B-Eagle3 on a single GPU device in SGLang as well. However, in their blog post, they claimed to have achieved some speedups for GPT-OSS-120B-Eagle3 inference using tp=4, i.e., Tensor Parallelism across four H200 GPUs. It’s unclear whether this configuration is the key factor contributing to the observed speedup.
In addition, I feel batching (i.e., processing multiple prompts concurrently) may also play an important role in achieving Eagle3 speedups. A larger batch size means more experts are already activated during native decoding, so activating additional experts in the target model may not become a bottleneck during the Eagle3 verification stage.
TODO: This can be verified after merging this PR and extending eagle3 within llama-server to support multi-batch inference.
In summary, I believe that for large MoE models such as GPT-OSS-120B, Eagle3 may not provide a performance gain on single GPU device with single prompt use case. However, this does not apply to all MoE models—for example, we observed a performance improvement with Qwen3-30B-A3B_eagle3. This might be related to the number of active experts per token and the overall model size, where loading active experts (a memory-bound operation) dominates the inference time. After profiling, I confirmed that draft token verification for the GPT-OSS MoE target model takes at least twice (depends on how many draft tokens to verify) as long as single-token autoregressive generation on the same GPT-OSS MoE model. @ggerganov
My proposal is that we must design this function + the API in a way that it is flexible enough for future models.
Thank you very much for taking the time for this insightful proposal. Although we discussed the Eagle3 design(https://github.com/ggml-org/llama.cpp/discussions/15902#discussioncomment-14507418) several months ago, it’s still great to hear your perspective. @ggerganov These might be things worth considering.