Fix Qwen3.5 MoE KeyError with pipeline parallelism#21217
Fix Qwen3.5 MoE KeyError with pipeline parallelism#21217he-yufeng wants to merge 1 commit intosgl-project:mainfrom
Conversation
…rallelism When running Qwen3.5-122B with pp>1, the non-fused expert weight loading path in load_weights accesses params_dict[name_mapped] without checking if the key exists. With pipeline parallelism, layers assigned to other ranks won't have their parameters in the local params_dict, causing a KeyError (e.g., 'model.layers.4.mlp.experts.w13_weight'). The fused expert path (load_fused_expert_weights) was already fixed in sgl-project#21070 but the else branch for non-fused experts was missed. This adds the same guard to both Qwen3_5MoeForCausalLM and Qwen3_5MoeForConditionalGeneration. Fixes sgl-project#21184
Summary of ChangesHello, 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 addresses a critical issue preventing the use of pipeline parallelism with Qwen3.5 MoE models by resolving a Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds checks to handle cases where name_mapped might not be present in params_dict during parallel processing, preventing KeyError. The review comments suggest that these new checks introduce redundancy with existing conditional continue statements, and recommend refactoring to improve code clarity by removing the now-superfluous preceding checks.
| if name_mapped not in params_dict: | ||
| continue |
There was a problem hiding this comment.
While this check correctly fixes the KeyError, it also makes the preceding check on lines 1246-1250 redundant. The logic if (A and B) continue; followed by if (B) continue; is equivalent to just if (B) continue;.
To improve code clarity, please remove the redundant check on lines 1246-1250 and keep only this new one.
| if name_mapped not in params_dict: | ||
| continue |
There was a problem hiding this comment.
Similar to the change above, this check makes the preceding check on lines 1587-1591 redundant. The logic if (A and B) continue; followed by if (B) continue; is equivalent to just if (B) continue;.
To improve code clarity, please remove the redundant check on lines 1587-1591 and keep only this new one.
|
ping — Qwen3.5 MoE + PP KeyError, non-fused expert path missing PP guard. |
Motivation
Running Qwen3.5-122B-A10B with
--pipeline-parallel-size 8crashes during weight loading:The fused expert path (
load_fused_expert_weights) was already fixed in #21070 to handle missing params under PP, but the non-fused expert else branch was missed — it still does a bareparams_dict[name_mapped]without checking if the key exists.With pipeline parallelism, layers assigned to other ranks don't have their parameters in the local
params_dict, so any access without a guard will KeyError.Modifications
Added
if name_mapped not in params_dict: continuebefore the dict access in the non-fused expert path, matching the pattern already used in:load_fused_expert_weights(same file, fixed in [Qwen3.5] Fix broken pipeline parallelism layer splitting #21070)qwen3_5_mtp.py(already guarded)qwen3_omni_moe.py(already guarded)Applied to both
Qwen3_5MoeForCausalLMandQwen3_5MoeForConditionalGeneration.Fixes #21184