Add Spec V2 for Qwen 3 next#15591
Conversation
Summary of ChangesHello @vincentzed, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on refining and optimizing the speculative decoding V2 implementation within SGLang. The core changes involve introducing a specialized KV cache management mode for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces Spec V2 for Qwen 3 next, an optimization that enables overlapping the draft and verify stages in speculative decoding. The changes primarily focus on handling a new forward mode, DRAFT_EXTEND_V2, and optimizing Mamba state updates. While the implementation is mostly sound and demonstrates performance improvements, I have identified a critical bug in the calculation of accepted steps within eagle_worker_v2.py that needs to be addressed. Additionally, I've provided a suggestion to improve code clarity by removing a redundant variable.
| ): | ||
| # Calculate accepted_steps for mamba state update | ||
| # Include the bonus token (+1) | ||
| accepted_length_with_bonus = accept_length |
There was a problem hiding this comment.
The variable accepted_length_with_bonus is redundant because accept_length already includes the bonus token, as mentioned in the comment on line 764. You can remove this line and use accept_length directly in torch.cumsum on line 770 and in the calculation on line 785. This will make the code clearer and less prone to confusion.
Various BS benchmark:Cmd: Summary of below:BeforeAfter |
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
de4ad74 to
e405fdd
Compare
Signed-off-by: vincentzed <207368749+vincentzed@users.noreply.github.com>
Signed-off-by: vincentzed <207368749+vincentzed@users.noreply.github.com>
e405fdd to
4747111
Compare
|
@yizhang2077 may you help take a look again? |
|
LGTM |
|
@yizhang2077 Hello, can you give it a approval. And then, in #18808, we can apply the improvements on top.) |
Motivation
Modifications
Here’s a command we want to make work:
Where the key option is that SGLANG_ENABLE_SPEC_V2=1 for overlap of draft + verify
Acc is tested (no gibberish)
Speedup:
By total token throughput:
16373/14293 *100 - 100 = 14.5525781851%GSP benchmark result:
Spec V2, This branch:

Spec V1 on this branch:
Make sure Spec V1 did not have regression. So we test Spec v1 on main:
The result ~= Spec V1 on the branch, which proves our optimization is solid.
Also here is the trace:
All 3:
https://drive.google.com/drive/folders/17HodwEV2LPuyPri7W01b1_8pDid9JCzD?usp=sharing
In this PR, we also fixed a cuda stream sync that caused a perf regression initially (see comments inline), here are some examples of unwanted stream sync.


Accuracy Tests
Benchmarking and Profiling
Checklist