-
Notifications
You must be signed in to change notification settings - Fork 830
[WIP] [megatron] support multimodal model #5502
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
base: main
Are you sure you want to change the base?
[WIP] [megatron] support multimodal model #5502
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 introduces initial support for multimodal models within the Megatron framework. The primary goal is to enable the integration of vision components, specifically for models like Qwen2.5VL, and to ensure that model configurations are correctly handled during the conversion process from HuggingFace formats to Megatron. This lays the groundwork for training and deploying models that can process both text and visual data.
Highlights
- Multimodal Model Integration: Introduces a new
Qwen2_5VL_Vit
module to support Vision Transformer (ViT) components for multimodal models within the Megatron framework. - Configuration Handling for Multimodal Models: Enhances the model conversion utility (
convert.py
) to correctly extract and usetext_config
for multimodal models when converting HuggingFace configurations to Megatron. - Improved Argument Passing: Ensures essential model metadata (
model_info
andmodel_meta
) is passed as extra arguments during Megatron initialization, facilitating proper setup for multimodal architectures.
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 adds initial support for multimodal models within Megatron. The changes introduce a new Vision Transformer (ViT) model wrapper for Qwen2.5-VL and update the model conversion script to correctly handle multimodal configurations. My review focuses on the new ViT wrapper, where I've identified a couple of critical issues: a missing import that will cause a NameError
, and an incorrect implementation of the get_input_embeds
method that will lead to a runtime error. I've provided specific suggestions to address these problems. The other changes appear logical for the goal of adding multimodal capabilities.
super().__init__(config) | ||
args = get_args() | ||
model_dir = args.model_info.model_dir | ||
model, _ = get_model_tokenizer(model_dir, return_dummy_model=True) |
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.
The function get_model_tokenizer
is used here but it's not imported, which will cause a NameError
at runtime. You probably intended to use a model-specific loading function like get_model_tokenizer_qwen2_5_vl
from swift.llm.model.model.qwen
. Please correct the function call and add the required import. Note that the specific function might require more arguments like model_info
and model_kwargs
.
def get_input_embeds(self, input_embeds): | ||
self() |
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.
The implementation of get_input_embeds
seems incorrect.
- It calls
self()
, which will invoke theforward
method without any arguments. Theforward
method then callsself.model()
, which will likely fail due to missing required arguments for the visual model's forward pass. - The
input_embeds
argument is unused. - A method named
get_input_embeds
is typically expected to return the input embedding layer of the model, not to perform a forward pass.
Based on similar patterns in the codebase (e.g., swift/llm/model/model/qwen.py
where patch_get_input_embeddings
is used with 'patch_embed'
), this method should probably return the patch embedding layer of the vision model.
def get_input_embeds(self, input_embeds): | |
self() | |
def get_input_embeds(self): | |
return self.model.patch_embed |
No description provided.