-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
[V1][Speculative Decoding] Fix DeepSeek MTP #20022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @cjackal, 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 fixing a specific issue with the DeepSeek MTP model in the context of speculative decoding. It includes changes to the model's embedding layer and attention metadata handling to resolve the reported problem. The PR also includes a test plan and results to demonstrate the fix.
Highlights
- DeepSeek MTP Fix: Addresses issue #20021 related to DeepSeek MTP (Multiple KV cache group scenario) in speculative decoding. A more complete fix for multiple KV cache groups is planned for future work.
- Embedding Layer: Added
VocabParallelEmbedding
to the DeepSeek MTP model to handle vocabulary embeddings. - Attention Metadata: Modified the
propose
function ineagle.py
to correctly access attention metadata builders using index 0, which is a temporary fix for multiple KV cache groups.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request fixes an issue with DeepSeek MTP and addresses the multiple KV cache group scenario by selecting the first available builder. The FIXME comment is still present, and there's a potential redundancy in defining self.embed_tokens
in DeepSeekMultiTokenPredictor
.
self.embed_tokens = VocabParallelEmbedding( | ||
config.vocab_size, | ||
config.hidden_size, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the bug? Does the MTP module have a separate vocab embedding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of vocab embedding module raises the 'DeepSeekMultiTokenPredictor' object has no attribute 'embed_tokens'
attribute error, the first traceback in the linked issue.
Architecture-wise all the vocab embeddings are of the same shape as the target model, but we do need to keep vocab embeddings for each mtp layers if the target model has been trained with multiple mtp layers (not the case for official deepseek R1/V3 families though) and the user launches server with PP > 1. There is a similar condition check in EAGLE weight loading step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjackal Thanks for the explanation! Can we use the target model's embedding when PP=1 and only allocate the weights when PP > 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WoosukKwon Another thought after the discussion: the sole purpose of speculative decoding is leveraging the small draft model to get faster generation speed, so allowing pipeline parallelism on draft model weights is rare and kind of contradictory.
We may simply assume that all the MTP layers are on the same (last) pipeline component and always share the vocab embedding of the MTP layers with that of the target model. NVM, even if MTP module is not split, there is no guarantee that target model's embedding is on the same component. Let me just move the vocab embeddings from DeepSeekMultiTokenPredictorLayer
to DeepSeekMultiTokenPredictor
to share them among MTP layers and leave the sharing between target and draft embedding to the EAGLE draft model loading stage that I linked before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjackal Got it. Thanks! Could you please re-run the test locally again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need more refactor on draft weight loading part; let me ping again when ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjackal Got it. Thanks!
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
According to the deepseek v3 tech report, the vocab embeddings are shared among target module and every MTP layers; indeed the weights 'model.layers.61.embed_tokens.weight' and 'model.embed_tokens.weight' coincide for official deepseek-r1 checkpoint. Thus I simply load the first MTP vocab embedding and when PP=1 leave it to be dropped by EAGLE weight loader. I have checked that the model server functions okay and prints the following server log:
@WoosukKwon PTAL |
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com> Signed-off-by: Will Eaton <weaton@redhat.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
Fix #20021.
I need better understanding on multiple KV cache group scenario, so leave it as a future work.
Test Plan
Launch options:
vllm serve /app/model/DEEPSEEK-R1/ \ --served-model-name deepseek-ai/deepseek-r1 \ --gpu-memory-utilization 0.95 \ --tensor-parallel-size 16 \ --max-model-len 65536 \ --max-num-batched-tokens 8192 \ --reasoning-parser deepseek_r1 \ --speculative-config '{"method":"deepseek_mtp","num_speculative_tokeens":1}'
Test request:
Test Result
Server runs successfully and return:
(Optional) Documentation Update