Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jintao-Huang
Copy link
Collaborator

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 use text_config for multimodal models when converting HuggingFace configurations to Megatron.
  • Improved Argument Passing: Ensures essential model metadata (model_info and model_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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Comment on lines +18 to +19
def get_input_embeds(self, input_embeds):
self()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The implementation of get_input_embeds seems incorrect.

  1. It calls self(), which will invoke the forward method without any arguments. The forward method then calls self.model(), which will likely fail due to missing required arguments for the visual model's forward pass.
  2. The input_embeds argument is unused.
  3. 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.

Suggested change
def get_input_embeds(self, input_embeds):
self()
def get_input_embeds(self):
return self.model.patch_embed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant