Skip to content

Conversation

yilian49
Copy link
Collaborator

@yilian49 yilian49 commented Jun 24, 2025

Motivation

When loading deepseek v3, post_load_weights function called in loader.py does not pass in a is_nextn argument which reports the following error when loading DeepseekModelNextN models.

Modifications

Add a check for if model architecture is "DeepseekV3ForCausalLMNextN" and pass in is_nextn = true in model.post_load_weights.

Note

There could be a more elegant solution.
Update: This error only happens when using flag "--load-format dummy".

Command

SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK=256 python3 -m sglang.launch_server
--attention-backend fa3
--model-path /mnt/shared-fs/models/deepseek-ai/DeepSeek-V3-0324
--tp 8
--nnodes 1
--node-rank 0
--trust-remote-code
--max-running-requests 32
--mem-fraction-static 0.7 \
--chunked-prefill-size 2048
--schedule-policy fcfs \
--speculative-algo NEXTN
--speculative-num-steps 4
--speculative-eagle-topk 1
--speculative-num-draft-tokens 4
--cuda-graph-max-bs 32 \
--disable-shared-experts-fusion
--load-format dummy

Error pattern

[2025-06-24 23:28:08 TP1] Scheduler hit an exception: Traceback (most recent call last):
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/managers/scheduler.py", line 2631, in run_scheduler_process
scheduler = Scheduler(server_args, port_args, gpu_id, tp_rank, pp_rank, dp_rank)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/managers/scheduler.py", line 328, in init
self.draft_worker = EAGLEWorker(
^^^^^^^^^^^^
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/speculative/eagle_worker.py", line 124, in init
super().init(
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/managers/tp_worker.py", line 79, in init
self.model_runner = ModelRunner(
^^^^^^^^^^^^
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/model_executor/model_runner.py", line 220, in init
self.initialize(min_per_gpu_memory)
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/model_executor/model_runner.py", line 262, in initialize
self.load_model()
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/model_executor/model_runner.py", line 561, in load_model
self.model = get_model(
^^^^^^^^^^
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/model_loader/init.py", line 22, in get_model
return loader.load_model(
^^^^^^^^^^^^^^^^^^
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/model_loader/loader.py", line 558, in load_model
model.post_load_weights()
File "/mnt/shared-fs/yilian/sglang/python/sglang/srt/models/deepseek_v2.py", line 1844, in post_load_weights
self.model.layers[layer_id].self_attn
^^^^^^^^^^^^^^^^^
File "/mnt/shared-fs/yilian/sgl-yilian/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1940, in getattr
raise AttributeError(
AttributeError: 'DeepseekModelNextN' object has no attribute 'layers'

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 @yilian49, 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 implements a crucial fix for loading specific model architectures, particularly the DeepseekV3ForCausalLMNextN model. By introducing a conditional call to the model's post-loading weight processing, it ensures that these models are initialized with the correct parameters, resolving potential loading issues and enabling their proper functionality within the system.

Highlights

  • Model Loading Logic: Introduced conditional logic within the load_model function to specifically handle the DeepseekV3ForCausalLMNextN model architecture. When this architecture is detected, the model.post_load_weights() method is now called with the argument is_nextn=True.
  • Targeted Fix: This change is a targeted fix, likely addressing an issue with the post-processing of weights for the DeepseekV3ForCausalLMNextN model, ensuring it loads correctly as a 'draft model'.
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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 introduces a fix for loading a draft model, specifically for DeepseekV3ForCausalLMNextN within the DummyModelLoader. The change adds special handling during the post-weight-loading process for this architecture. I've suggested refactoring to improve maintainability.

Comment on lines 558 to 561
if model_config.hf_config.architectures[0] == "DeepseekV3ForCausalLMNextN":
model.post_load_weights(is_nextn = True)
else:
model.post_load_weights()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider simplifying this conditional logic. Instead of checking the architecture string directly, pass is_nextn as an argument to post_load_weights based on a boolean flag1. This moves the architecture-specific logic into the DeepseekV3ForCausalLMNextN class itself, improving maintainability.

                is_nextn = model_config.hf_config.architectures[0] == "DeepseekV3ForCausalLMNextN"
                model.post_load_weights(is_nextn=is_nextn)

Style Guide References

Footnotes

  1. Avoid hardcoding model-specific logic in the loader; delegate to the model class. (link)

@yilian49 yilian49 reopened this Jun 25, 2025
@ch-wan ch-wan self-assigned this Jun 25, 2025
@ch-wan ch-wan added the ready-to-merge The PR is ready to merge after the CI is green. label Jul 5, 2025
@ch-wan
Copy link
Collaborator

ch-wan commented Jul 5, 2025

@yilian49 Could you please fix the linter issue?

@yilian49
Copy link
Collaborator Author

yilian49 commented Jul 6, 2025

@ch-wan Just fixed

@ch-wan ch-wan mentioned this pull request Jul 8, 2025
6 tasks
@ch-wan ch-wan merged commit 8aa5ae6 into sgl-project:main Jul 18, 2025
48 of 56 checks passed
ch-wan pushed a commit that referenced this pull request Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge The PR is ready to merge after the CI is green.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants