feat: add Qwen3.5 CP support for MCore path#2312
Draft
zpqiu wants to merge 3 commits intoNVIDIA-NeMo:mainfrom
Draft
feat: add Qwen3.5 CP support for MCore path#2312zpqiu wants to merge 3 commits intoNVIDIA-NeMo:mainfrom
zpqiu wants to merge 3 commits intoNVIDIA-NeMo:mainfrom
Conversation
- Megatron-Bridge: 95e5f38f → 53f4c398 (latest main) - Megatron-LM: d30c3ae5 → 546a448b (dev) The dev-branch Megatron-LM is required for Qwen3.5 VL's GDN + context parallelism support (NVIDIA/Megatron-LM#2642, NVIDIA/Megatron-LM#2644). Sync the proxy setup.py CACHED_DEPENDENCIES to match the updated dev pyproject.toml (nv-grouped-gemm, flash_mla, nvidia-resiliency-ext VCS pin, emerging_optimizers python-version marker, etc.) and regenerate uv.lock. Signed-off-by: Zhaopeng Qiu <alexq@nvidia.com>
Qwen3.5 VL's mbridge wrapper (Qwen3VLModel) always runs its own preprocess_packed_seqs internally to pack + CP-shard from a [B, max_seq] input + attention_mask. NeMo-RL's existing path pre-packs and CP-shards before the forward, which collides with mbridge's preprocessing and produces shape mismatches at GDN / RoPE / MoE when CP > 1. Add a sequence_packing.delegate_pack_to_model flag. When true, _prepare_vlm_batch_for_megatron keeps the batch in [B, max_seq] layout, builds a bool attention_mask from the (aligned) padded lengths, and hands the model a PackedSeqParams whose cu_seqlens_padded matches what mbridge will derive internally. The model owns packing and CP-sharding from there. For the target-side path (logprob / loss post-processing), we also produce a packed [1, T] view of input_ids; downstream code already slices per-sequence via cu_seqlens_padded. PP > 1 is supported by absorbing the pad_full_seq_to deficit into the last sequence (same technique as _pack_sequences_for_megatron), so the decoder-side packed length is constant across microbatches. Additional fixes needed for this path: - community_import.py: set calculate_per_token_loss when CP > 1, which Qwen3VLModel asserts. - setup.py: clarify the 'CP > 1 requires sequence_packing' error message to mention delegate_pack_to_model for VLM models. Signed-off-by: Zhaopeng Qiu <alexq@nvidia.com>
_get_tokens_on_this_cp_rank slices a tensor with a list of slices, which
PyTorch 2.9 deprecates ('Using a non-tuple sequence for multidimensional
indexing is deprecated'). Every GDN/attention layer triggers this on the
packed-CP path, flooding the worker logs. Casting to tuple matches the
recommended API and is functionally identical.
Signed-off-by: Zhaopeng Qiu <alexq@nvidia.com>
✅ Submodule Fast-Forward Check ResultsCheck based on commit: 16ae363 (PR #2312 from ✅ Submodules that are properly updated:Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward) All submodule changes look good! ✨ |
Contributor
Author
|
/ok to test 16ae363 |
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 ?
Add a one line overview of what this PR aims to accomplish.
Issues
List issues that this PR closes (syntax):
Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information