[model] fix: Enhance MTP expert weight format detection for Qwen3.6#3740
Open
Yangruipis wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Open
[model] fix: Enhance MTP expert weight format detection for Qwen3.6#3740Yangruipis wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Yangruipis wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Conversation
Add support for detecting MTP expert weight format for Qwen3.5 and Qwen3.6 models. Signed-off-by: 杨睿 <yangruipis@163.com>
Refactor MTP expert weight format detection for clarity and maintainability. Signed-off-by: 杨睿 <yangruipis@163.com>
Author
|
@yaoyu-33 could you please take a review? thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Qwen3.6-35B-A3B mtp expert's weights are packed (https://huggingface.co/Qwen/Qwen3.6-35B-A3B/blob/main/model.safetensors.index.json#L1034-L1035) which is different from Qwen3.5-35B-A3B (https://huggingface.co/Qwen/Qwen3.5-35B-A3B/blob/main/model.safetensors.index.json#L345-L1117).
Both models share the same HF
architectures(Qwen3_5MoeForConditionalGeneration) andmodel_type(qwen3_5_moe), so they are routed to the same bridge. Today the bridge hard-codes the per-expert MTP mapping (mtp.layers.*.mlp.experts.*.gate_proj.weightetc.). On Qwen3.6,none of those HF keys exist, so every routed MTP expert weight is silently skipped during HF→Megatron load and remains randomly initialized —
model_bridge.pyonly emits aWARNING: Can't find ... in hf_keysandcontinues. Withmtp_loss_scaling_factor=0.1this leaks noisegradients into training.
This PR detects the MTP expert storage format from the HF state at provider-build time and selects the correct mapping pair, keeping Qwen3.5 working while fixing Qwen3.6.
reproduction
Changelog
src/megatron/bridge/models/qwen_vl/qwen35_vl_bridge.pyQwen35VLMoEBridge.provider_bridge: peekhf_pretrained.state.source.get_all_keys()whenmtp_num_layers > 0and setself._mtp_experts_packed = Trueiffmtp.layers.0.mlp.experts.gate_up_projis present (Qwen3.6); otherwiseFalse(Qwen3.5, current behavior).Qwen35VLMoEBridge.mapping_registry: branch the MTP routed-expert mapping onself._mtp_experts_packed:FusedGatedExpertMapping(linear_fc1 ↔ mtp.layers.*.mlp.experts.gate_up_proj)+FusedExpertMapping(linear_fc2 ↔ mtp.layers.*.mlp.experts.down_proj, transpose_on_export=True)(mirrors the main-decoder mapping).GatedMLPMapping+AutoMappingovermtp.layers.*.mlp.experts.*.{gate,up,down}_proj.weight.GitHub Actions CI
See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information
WARNING: Can't find the following HF parameters in hf_keys: ['mtp.layers.0.mlp.experts.{i}.gate_proj.weight', ...]for every local routed expert across all EPranks; post-fix both checkpoints load cleanly with no MTP warnings.
hf_pretrainedis a barePretrainedConfig(config-only export). This preserves current behavior; a future PR could thread format detection through the export path as well.