-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[model] support XiaomiMiMo/MiMo-V2.5 #9273
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
Jintao-Huang
wants to merge
1
commit into
modelscope:main
Choose a base branch
from
Jintao-Huang:support_mimo_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,6 +505,50 @@ class Qwen2_5VLTemplate(Qwen2VLTemplate): | |
| default_system='You are MiMo, an AI assistant developed by Xiaomi.')) | ||
|
|
||
|
|
||
| class MiMoV2Template(Qwen2_5VLTemplate): | ||
| """Template for XiaomiMiMo/MiMo-V2.5. | ||
|
|
||
| Differences from Qwen2_5VLTemplate: | ||
| - MiMo-V2.5 does not use 3D rope position IDs (no get_rope_index). | ||
| - Video key is named 'video_pixel_values' instead of 'pixel_values_videos'. | ||
| - Supports thinking mode with <think>...</think> tags. | ||
| """ | ||
|
|
||
| def _get_position_ids(self, inputs: Dict[str, Any]): | ||
| # MiMo-V2.5 uses standard rotary position embeddings, | ||
| # not 3D rope like Qwen2VL. No special position IDs needed. | ||
| return {} | ||
|
|
||
| def forward_context(self, model, inputs): | ||
| # Skip Qwen2VL-specific flash attention patching | ||
| return Template.forward_context(self, model, inputs) | ||
|
|
||
| def _post_encode(self, model, inputs: Dict[str, Any]) -> Dict[str, Any]: | ||
| if not self.is_training: | ||
| # During inference, rename key to match MiMo-V2.5 forward signature | ||
| if 'pixel_values_videos' in inputs: | ||
| inputs['video_pixel_values'] = inputs.pop('pixel_values_videos') | ||
| return inputs | ||
| # For training, compute embeddings manually | ||
| input_ids = inputs['input_ids'] | ||
| base_model = self.get_base_model(model) | ||
| inputs_embeds = base_model.model.embed_tokens(input_ids) | ||
| inputs_embeds = self._get_inputs_embeds_hf(inputs_embeds, inputs, model.visual, self.processor, model.config) | ||
| return {'inputs_embeds': inputs_embeds} | ||
|
Comment on lines
+526
to
+537
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
def _post_encode(self, model, inputs: Dict[str, Any]) -> Dict[str, Any]:
if not self.is_training:
# During inference, rename key to match MiMo-V2.5 forward signature
if 'pixel_values_videos' in inputs:
inputs['video_pixel_values'] = inputs.pop('pixel_values_videos')
return inputs
# For training, compute embeddings manually
input_ids = inputs['input_ids']
base_model = self.get_base_model(model)
if hasattr(base_model.model, 'embed_tokens'):
inputs_embeds = base_model.model.embed_tokens(input_ids)
else:
inputs_embeds = base_model.model.language_model.embed_tokens(input_ids)
inputs_embeds = self._get_inputs_embeds_hf(inputs_embeds, inputs, model.visual, self.processor, model.config)
inputs['inputs_embeds'] = inputs_embeds
inputs.pop('input_ids', None)
return inputs |
||
|
|
||
|
|
||
| register_template( | ||
| QwenTemplateMeta( | ||
| MLLMTemplateType.mimo_v2, | ||
| template_cls=MiMoV2Template, | ||
| default_system='You are MiMo, a helpful AI assistant engineered by Xiaomi.', | ||
| is_thinking=True, | ||
| thinking_prefix='<think>\n', | ||
| non_thinking_prefix='<think>\n</think>\n\n', | ||
| history_thinking_prefix='<think>\n</think>\n\n', | ||
| )) | ||
|
|
||
|
|
||
| class Qwen3VLTemplate(Qwen2VLTemplate): | ||
| version = 'v3' | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 current implementation of
get_modelforMiMoV2Loaderbypasses the logic inQwen2VLLoader.get_modelto avoid the hardcodedauto_model_cls, but it also misses the necessary check for AWQ-wrapped models. When a model is quantized with AWQ, the actual model components are often nested under a.modelattribute. It is safer to replicate thebase_modellogic to ensurepatch_get_input_embeddingsis applied to the correct module.