-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
[Model] Support deepseek with eagle #21086
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
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
This pull request adds support for Eagle speculative decoding with Deepseek models. I've found a few critical issues in the implementation that will prevent it from working correctly. The model implementation in deepseek_eagle.py
incorrectly handles hidden state dimensions and is missing the lm_head
layer, which will cause runtime errors. Additionally, the model registry key in registry.py
seems to be incorrect, which would prevent the model from being loaded.
self.fc = nn.Linear( | ||
self.config.model.hidden_size * 2, | ||
self.config.model.hidden_size, | ||
bias=False, | ||
) | ||
|
||
self.enorm = RMSNorm(self.config.hidden_size, | ||
eps=self.config.rms_norm_eps) | ||
self.hnorm = RMSNorm(self.config.hidden_size, | ||
eps=self.config.rms_norm_eps) | ||
self.norm = RMSNorm(self.config.hidden_size, | ||
eps=self.config.rms_norm_eps) |
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 implementation of DeepseekV2Model
assumes that the draft model and the target model share the same hidden size. For instance, self.hnorm
is initialized with the draft model's hidden size (self.config.hidden_size
) but is applied to hidden_states
from the target model.
This assumption is incorrect for the models used in testing (deepseek-r1
has a hidden size of 4096, while eagle-deepseek-r1
has 1024), and will lead to a runtime error due to shape mismatch.
To fix this, you should explicitly use the hidden sizes from both the draft and target model configurations. You can access the target model's configuration via vllm_config.model_config
.
target_config = vllm_config.model_config.hf_config
draft_hidden_size = self.config.hidden_size
target_hidden_size = target_config.hidden_size
self.fc = nn.Linear(
draft_hidden_size + target_hidden_size,
draft_hidden_size,
bias=False,
)
self.enorm = RMSNorm(draft_hidden_size,
eps=self.config.rms_norm_eps)
self.hnorm = RMSNorm(target_hidden_size,
eps=target_config.rms_norm_eps)
self.norm = RMSNorm(draft_hidden_size,
eps=self.config.rms_norm_eps)
👋 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 🚀 |
Hi! I tried installing this pr from source. But got
Should the |
Thanks for your comment, fixed now. |
Amazing work! I wonder if you could share how you got eagle618/eagle-deepseek-r1? As this pr could also improve DS V3 etc. Thank you! |
6981998
to
c4cda03
Compare
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.
Do you have a eagle checkpoint to test with this? If you have some numbers that would be great.
Llama 4 EAGLE was landed recently, so I do think we can probably do the same wrt to tests for this (if you need some references for test cases)
Thanks for your review. I have tested with the checkpoint eagle618/eagle-deepseek-r1. Also added unit test case. |
stacked_params_mapping = [ | ||
# (param_name, shard_name, shard_id) | ||
("gate_up_proj", "gate_proj", 0), | ||
("gate_up_proj", "up_proj", 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.
Does this need to be made compatible with the fused_qkv_a_proj optimization from #21116? I have observed multiple issues with weight loading in MTP not being consistent with the DeepSeek base model weight loading. Will similar issues apply here?
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 have updated the stacked_params_mapping. Thanks!
hidden_states = self.fc(inputs) | ||
|
||
# masking inputs at position=0 | ||
hidden_states[positions == 0] = 0 |
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 have been many discussions in the community about how to properly handle the rotated input slot, but this does not seem in line with the final state. If I recall correctly, there was concern that overwriting the hidden states to zero will give out-of-distribution results during attention. See the other EAGLE implementations in vLLM (such as llama_eagle.py
) for reference.
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.
Yes, there's discussion this will mess up the attention normalization. I have removed this. Please review. Thanks.
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 see deepseek_mtp.py has also masked the hidden states to 0: https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/models/deepseek_mtp.py#L74
I can remove the line in deepseek_mtp.py together in this PR. But I can leave it there too. Let me know how you think.
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.
Perhaps best to leave it pending a complete study of impact on AL for MTP. If there isn't a github issue for this task, please create one
|
||
inputs = torch.cat( | ||
[self.enorm(input_embeds), | ||
self.hnorm(hidden_states)], dim=-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.
This looks like too many norms being applied. In the Llama_Eagle reference code, the input layernorm to each layer is disabled, and IIRC there is no output layernorm. Here, there are two norms applied to the input (pre-concat and input-layernorm after concat) and two more norms applied after (post_attention_layernorm and self.norm). This does not seem correct.
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 have taken a look at the deepseek_mtp.py
at https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/models/deepseek_mtp.py#L64. The only difference is output self.norm. But in our benchmarking, we found that including the output norm will increase acceptance rate.
What does this mean? What are the weights of a "vanilla eagle head" in this case? |
582dc36
to
e26554a
Compare
@benchislett Thanks for your review! I mean people can further fine tune the weights and get better acceptance rate. The "vanilla eagle head" in this case is eagle618/eagle-deepseek-r1. |
498955f
to
7d3a40f
Compare
Signed-off-by: Xin Yang <[email protected]>
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 implementation now seems more in-line with the MTP implementation. There are still differences between how we handle EAGLE and MTP models (whether norms are applied to input_layernorm or not, normed before output, for example) and this PR blends the two by implementing an EAGLE class in a manner more consistent with MTP.
We should try to find some way to unify implementations and reconcile the differences, but this is probably not the PR to bear that burden. For now, this will suffice and can be extended if future eagle-style MTP modules are released with slight differences in implementation.
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.
Stamping given Benjamin approved.
Signed-off-by: Xin Yang <[email protected]>
Head branch was pushed to by a user without write access
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]> Signed-off-by: Duncan Moss <[email protected]>
Signed-off-by: Xin Yang <[email protected]> Signed-off-by: Boyuan Feng <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: Xin Yang <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Signed-off-by: Xin Yang <[email protected]>
Why export VLLM_MLA_DISABLE=1? Is it ok that DeepSeek-R1 inference with VLLM_MLA_DISABLE=0 and deepseek_eagle with VLLM_MLA_DISABLE= 0 ? |
Signed-off-by: Xin Yang <[email protected]>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
This PR is to support running eagle speculative decoding on deepseek model. Changed the following file:
deepseek_eagle.py
: deepseek eagle model definitionregistry.py
: add the model to registryTest Plan
Added test in
test_spec_decode.py
:vllm serve cmd:
Test Result
The following unit tests passed:
serve deepseek-ai/DeepSeek-R1 and benchmarking with llmperf:
(Optional) Documentation Update