fix dsv3 load err in mtp case#9056
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @ssssnow, 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!
I've addressed a critical issue preventing the DeepseekV3 model from loading correctly, specifically in multi-tensor parallel (MTP) configurations. The fix involves ensuring the pipeline parallel group is properly initialized and passed during model construction, which resolves a dependency for the load_weights() method.
Highlights
- DeepseekV3 Model Initialization: I've updated
sglang/srt/models/deepseek_nextn.pyto explicitly initializeself.pp_groupusingget_pp_group()within theDeepseekV3ForCausalLMNextNconstructor. This ensures the pipeline parallel group is available, preventing model loading failures. - Prefix Handling in DeepseekV2 Layers: In
sglang/srt/models/deepseek_v2.py, I've modified how theprefixargument is passed toDeepseekV2DecoderLayerduring its initialization. Instead of dynamically adding a layer index prefix, it now directly uses the providedprefix, which likely streamlines weight loading in distributed setups.
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 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 or fill out our survey 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.
Code Review
This pull request addresses two initialization bugs for DeepSeek V3 models. The first change correctly initializes the pipeline parallelism group in DeepseekV3ForCausalLMNextN, which is crucial for weight loading. The second change fixes an incorrect layer prefix construction in DeepseekV2Model. The changes appear correct. I've added one comment regarding code duplication to improve long-term maintainability.
| self.config = config | ||
| self.tp_size = get_tensor_model_parallel_world_size() | ||
| self.quant_config = quant_config | ||
| # if not set, model load will be broken in DeepseekV3ForCausalLM load_weights() | ||
| self.pp_group = get_pp_group() | ||
| self.determine_num_fused_shared_experts("DeepseekV3ForCausalLMNextN") |
There was a problem hiding this comment.
There is significant code duplication between this __init__ method and DeepseekV2ForCausalLM.__init__. Both methods initialize config, tp_size, quant_config, pp_group, and call determine_num_fused_shared_experts.
This duplication likely exists because super().__init__ cannot be called due to differences in self.model initialization.
To improve maintainability and reduce redundancy, consider refactoring the common initialization logic into a shared helper method within the base class DeepseekV2ForCausalLM. This would make the code cleaner and less prone to errors when one of the initializations is updated but not the other.
Motivation
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist