Skip to content

fix: skip missing expert params in PP mode for Qwen3.5 MoE#21220

Closed
yang1002378395-cmyk wants to merge 1 commit intosgl-project:mainfrom
yang1002378395-cmyk:fix-qwen3-pp-load-weights
Closed

fix: skip missing expert params in PP mode for Qwen3.5 MoE#21220
yang1002378395-cmyk wants to merge 1 commit intosgl-project:mainfrom
yang1002378395-cmyk:fix-qwen3-pp-load-weights

Conversation

@yang1002378395-cmyk
Copy link

Summary

Fixes #21184

Problem: When running Qwen3.5 MoE with PP>1 (e.g., pp=8 tp=1), the model fails to load weights with:

KeyError: 'model.layers.4.mlp.experts.w13_weight'

Root Cause: In load_weights(), the code accesses params_dict[name_mapped] without checking if the parameter exists. In PP mode, different ranks have different layers, so some expert parameters may not exist on this rank.

Fix: Add explicit checks before accessing params_dict[name_mapped] in two locations (lines 1251 and 1592) to skip parameters that don't exist on this rank.

Test Plan

User reported this fixes the issue when running:

python3 -m sglang.launch_server --model-path /disk1/models/Qwen3.5-122B-A10B-FP8 \
  --disable-radix-cache --mem-fraction-static 0.6 --tp-size 1 --pipeline-parallel-size 8 \
  --trust-remote-code

Checklist

KeyError occurred when loading weights with PP>1 because the code
tried to access params_dict[name_mapped] without checking if the
parameter exists on this rank. In PP mode, different ranks have
different layers, so some parameters may not exist.

Fixes sgl-project#21184
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 resolves a critical issue where Qwen3.5 MoE models failed to load weights in pipeline parallel mode, specifically when certain expert parameters were not available on a given rank. The fix introduces conditional checks during weight loading, ensuring that only relevant parameters are accessed, thereby enabling the stable operation of these models in distributed environments.

Highlights

  • Qwen3.5 MoE Weight Loading Fix: Implemented explicit checks in the load_fused_expert_weights function to prevent KeyError when loading Qwen3.5 MoE models in pipeline parallel (PP) mode, by skipping expert parameters not present on the current rank.

🧠 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 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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

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 adds an explicit check within the load_fused_expert_weights function to skip parameters that are not present on the current processing rank (PP mode). This prevents potential KeyError issues when accessing params_dict if a parameter is not mapped to the current rank. This change is applied in two locations within the file. I have no feedback to provide on the review comments as there were none.

@yang1002378395-cmyk
Copy link
Author

Closing in favor of #21217 by @he-yufeng which was submitted earlier and addresses the same issue. The fix is identical. Good collaboration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] fix pp for qwen3_5 (KeyError when reading params)

1 participant