-
Notifications
You must be signed in to change notification settings - Fork 830
[train] support Ovis2.5 padding_free #5486
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
[train] support Ovis2.5 padding_free #5486
Conversation
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.
Summary of Changes
Hello @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 refactors the handling of padding_free
and packing
features for multimodal models during training. It removes a restrictive check that limited these features to a predefined list of models and introduces a new mechanism where individual model templates explicitly declare their support for padding_free
training. This change enables broader compatibility for these optimization features, specifically adding support for minicpmv-4
and other multimodal models like InternVL
and Qwen2VL
.
Highlights
- Refactored Padding/Packing Support: The previous hardcoded list of multimodal models supporting
padding_free
andpacking
has been removed fromtrain_args.py
, allowing for more flexible support. - Template-Based Padding Support: A new
support_padding_free
attribute has been added to the baseTemplate
class and set toTrue
forInternvlTemplate
,MiniCPMV2_6Template
, andQwen2VLTemplate
, enabling individual templates to declare their compatibility. - Enhanced Template Validation: A new validation check in
sft.py
ensures that ifpadding_free
orpacking
is enabled for a multimodal model, the selected template explicitly supports these features, preventing misconfigurations. - Multimodal Data Collator Refactoring: The
_data_collator
method inminicpm.py
was refactored and renamed to_data_collator_mm_data
to better handle multimodal data, improving code organization and clarity.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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.
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
-
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. ↩
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 refactors the support check for padding_free
/packing
to be template-specific, which is a good design improvement. It also enables this feature for minicpmv-4
and other multimodal models. The changes are generally well-implemented. However, I've identified a potential runtime issue in the data collator for minicpm
templates due to an incorrect data shape being produced by the _encode
method in MiniCPMV2_6Template
. A fix is suggested to prevent this.
def _data_collator_mm_data(self, batch: List[Dict[str, Any]]) -> Dict[str, Any]: | ||
res = {} | ||
for k in ['pixel_values', 'image_bound', 'tgt_sizes']: | ||
res[k] = self.gather_list(batch, k) | ||
res.update(super()._data_collator(batch, padding_to=padding_to)) | ||
res.update(super()._data_collator_mm_data(batch)) | ||
return res |
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 refactoring from _data_collator
to _data_collator_mm_data
is a good improvement for modularity. However, it reveals a potential issue in MiniCPMV2_6Template._encode
.
The gather_list
function expects the values for keys like 'pixel_values' and 'tgt_sizes' to be lists. However, MiniCPMV2_6Template._encode
(at lines 220-221) returns these as raw tensors, not lists of tensors. This will cause a TypeError
inside gather_list
when it tries to concatenate a list with a tensor (res += tensor
).
To fix this, MiniCPMV2_6Template._encode
should be modified to wrap pixel_values
and tgt_sizes
in lists before returning them. For example:
# in MiniCPMV2_6Template._encode
encoded = {
...
'pixel_values': [image_inputs['pixel_values']],
'tgt_sizes': [image_inputs['tgt_sizes']]
}
This will ensure compatibility with gather_list
and prevent runtime errors.
No description provided.