-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[model] Support MiniCPM-V 4.5 #9610
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?
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 @tc-mb, 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 comprehensive support for the MiniCPM-V 4.5 model, focusing on its enhanced performance capabilities compared to previous versions. It integrates a new resampler designed to handle temporal data and updates the underlying language model component to Qwen3, ensuring compatibility and leveraging the latest model advancements.
Highlights
- MiniCPM-V 4.5 Model Integration: Adds full support for the new MiniCPM-V 4.5 model, which emphasizes performance improvements.
- Advanced Temporal Resampler: Implements Resampler4_5 to enable sophisticated processing of temporal data, including 1D sincos position embeddings.
- Qwen3 LLM Integration: Updates the language model backend for MiniCPM-V 4.5 to Qwen3, along with necessary method patching for compatibility.
- Generalized LLM Initialization: Refactors the init_llm method to accept a more generic PretrainedConfig, improving flexibility for future model integrations.
- Expanded Version Support: Extends the system to recognize and support MiniCPM-V versions 4.0 and 4.5, with improved error handling for unsupported versions.
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 support for MiniCPM-V 4.5. The changes include adding new model classes for versions 4.0 and 4.5, a new resampler implementation, and updating the model dispatch logic. The code is generally well-structured, but there are a few areas for improvement regarding code duplication, correctness, and maintainability. I've identified a critical issue with an undefined name that will cause a runtime error, as well as several medium-severity issues related to code clarity and redundancy. Please see my detailed comments below.
|
|
||
|
|
||
| _SUPPORT_VERSION = {(2, 6): MiniCPMV2_6} | ||
| class MiniCPMV4_0(MiniCPMBaseModel): |
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.
There is significant code duplication between MiniCPMV2_6, MiniCPMV4_0, and MiniCPMV4_5. Many methods (init_vision_module, get_vision_embedding, get_image_feature, pad_input_ids) and class attributes (packed_modules_mapping, supported_lora_modules, etc.) are identical across these classes.
To improve maintainability and reduce redundancy, consider creating a new base class that inherits from MiniCPMBaseModel and contains this common logic. The version-specific classes can then inherit from this new base class and only implement the methods that differ (e.g., __init__, init_llm, init_resampler).
For example:
class MiniCPMIdefics2VisionBase(MiniCPMBaseModel):
# Common attributes
packed_modules_mapping = { ... }
supported_lora_modules = [ ... ]
# ... other common attributes
# Common methods
def init_vision_module(self, ...): ...
def get_vision_embedding(self, ...): ...
def get_image_feature(self, ...): ...
def pad_input_ids(self, ...): ...
class MiniCPMV4_0(MiniCPMIdefics2VisionBase):
def __init__(self, ...):
super().__init__(...)
assert self.version == (4, 0)
def init_llm(self, ...): ...
def init_resampler(self, ...): ...
# Similar for MiniCPMV2_6 and MiniCPMV4_5|
No Chinese in code, Thanks |
Got it, I'll change it asap. |
Signed-off-by: tc-mb <caitianchi@modelbest.cn>
Signed-off-by: tc-mb <caitianchi@modelbest.cn>
|
@JustinTong0323 Could you please retry the failed CI again? |
I’m bringing MiniCPM-V 4.5 in this PR.
Compared to the recently released MiniCPM-V 4.0, this new version puts more emphasis on performance metrics.