-
Notifications
You must be signed in to change notification settings - Fork 903
[megatron] Support qwen3-vl/qwen3-omni cp #5952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[megatron] Support qwen3-vl/qwen3-omni cp #5952
Conversation
Summary of ChangesHello @Jintao-Huang, 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 significantly enhances the Megatron framework by introducing comprehensive support for Context Parallelism (CP) to the Qwen3-VL and Qwen3-Omni models. The core objective is to enable efficient distribution of data and computations across parallel contexts, which is crucial for scaling these large multimodal models. This involved adapting how inputs, especially visual embeddings and decoder inputs, are processed and split, alongside a generalization of the underlying utility functions for parallel data handling. Highlights
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. 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
|
There was a problem hiding this 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 support for context parallelism (CP) in qwen3-vl and qwen3-omni models. The core change is a refactoring that replaces specialized data splitting functions with a single, more generic split_cp_inputs
utility. This new function is then used to correctly partition model inputs, including visual features, across context parallel ranks. While the overall approach and refactoring are good, there are a couple of minor style issues with local imports and a potential bug related to leftover code that could process decoder_input
incorrectly.
batch[key] = _split_tokens_decoder_input(val, packed_seq_params.cu_seqlens_q) | ||
else: | ||
batch[key] = _split_tokens(val, packed_seq_params.cu_seqlens_q) | ||
batch[key] = split_cp_inputs(val, packed_seq_params.cu_seqlens_q, -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplification introduces a potential issue. The previous code had special handling for decoder_input
, which requires splitting along dim=0
due to its (sequence_length, batch_size, hidden_size)
shape. The new code splits all tensors along dim=-1
, which is incorrect for decoder_input
as it would split the hidden dimension.
While MultimodalGPTModel
now handles this splitting separately, the 'decoder_input'
key is still checked for in this function (on line 103), making this code path potentially active for other cases. This is confusing and could lead to silent errors.
To fix this, please either restore the special handling for decoder_input
or, if it's confirmed to be dead code, remove 'decoder_input'
from the keys
list on line 103.
batch[key] = split_cp_inputs(val, packed_seq_params.cu_seqlens_q, -1) | |
if key == 'decoder_input': | |
batch[key] = split_cp_inputs(val, packed_seq_params.cu_seqlens_q, 0) | |
else: | |
batch[key] = split_cp_inputs(val, packed_seq_params.cu_seqlens_q, -1) |
|
||
@staticmethod | ||
def _get_inputs_embeds(inputs_embeds, inputs, visual, processor, config): | ||
from ...trainers.utils import split_cp_inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swift/megatron/model/mm_gpt_model.py
Outdated
elif self.pre_process: | ||
from ..trainers.utils import get_batch_on_this_cp_rank | ||
kwargs.update({'input_ids': input_ids}) | ||
from ..trainers.utils import split_cp_inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.