Skip to content

Conversation

@Jintao-Huang
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

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 primarily addresses a bug in the Minimax M2 model related to tensor parallelism, ensuring that query and key layernorm weights are correctly sized and distributed across devices. It also updates the model's capabilities by removing a previous restriction on training for the minimax-text-01 model and refines its internal configuration for better maintainability.

Highlights

  • Tensor Parallelism Fix: Corrected the hidden_size calculation for query and key layernorms (q_norm and k_norm) in the Minimax M2 model to properly account for tensor parallelism, ensuring accurate sizing across distributed devices.
  • Explicit TP Split Definition: Introduced a new method _get_tp_split_dim within the MinimaxM2Bridge to explicitly define how q_norm.weight and k_norm.weight should be split along dimension 0 for tensor parallelism.
  • Model Training Support Update: Removed a warning indicating that the minimax-text-01 model does not support training, suggesting that this model may now be capable of training.
  • Code Refinement: Streamlined the _set_qk_layernorm method by removing redundant conditional logic for key determination and cleaned up model loading configuration by removing an explicit MinimaxTextLoader reference.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 introduces a bugfix for tensor parallelism (TP) in the Minimax M2 model. The changes correctly adjust the hidden size for QK layernorms to account for TP sharding and ensure their weights are split correctly. While the core fix for TP appears correct, I have a couple of concerns. Firstly, a change in the model bridge reduces flexibility by hardcoding weight key names, which might break compatibility with some model variants. Secondly, the removal of MinimaxTextLoader for the minimax_m2 model could be a regression for users running it on multiple GPUs without Megatron, as it removes custom device mapping logic. My review includes suggestions to address these points.

Model('MiniMax/MiniMax-M2.1', 'MiniMaxAI/MiniMax-M2.1')
]),
],
MinimaxTextLoader,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Removing MinimaxTextLoader from the minimax_m2 model registration will cause it to fall back to the default ModelLoader. The MinimaxTextLoader contains specific logic for device mapping in multi-GPU setups. This change may break or degrade performance for users running minimax_m2 on multiple GPUs in non-Megatron environments. Please clarify if this is intended. If so, it might be worth documenting this change in behavior.

@Jintao-Huang
Copy link
Collaborator Author

/gemini review

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 addresses a bug in the tensor parallelism (TP) implementation for the Minimax model. The changes in swift/megatron/model/gpts/minimax_m2.py correctly implement gathering and scattering of tensors around the QK normalization to ensure correctness under tensor parallelism. Additionally, the code for loading weights is simplified. The modifications in swift/model/models/minimax.py remove a custom loader for minimax_m2, which is appropriate as it avoids conflicts with Megatron's own parallelism management. The changes are logical and effectively resolve the bug. I have one minor suggestion to improve code readability.

Comment on lines +52 to 66
args = get_args()
query, key, value = super().get_query_key_value_tensors(*_args, **kwargs)
query = query.reshape(*query.shape[:-2], -1)
key = key.reshape(*key.shape[:-2], -1)
if args.tensor_model_parallel_size > 1:
query = gather_from_tensor_model_parallel_region(query)
key = gather_from_tensor_model_parallel_region(key)
query = self.q_norm(query)
key = self.k_norm(key)
if args.tensor_model_parallel_size > 1:
query = scatter_to_tensor_model_parallel_region(query)
key = scatter_to_tensor_model_parallel_region(key)
query = query.view(*query.shape[:2], -1, self.hidden_size_per_attention_head)
key = key.view(*key.shape[:2], -1, self.hidden_size_per_attention_head)
return query, key, value
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and avoid re-evaluating the same condition twice, you could store the result of args.tensor_model_parallel_size > 1 in a boolean variable. This makes the code's intent clearer and is slightly more efficient.

Suggested change
args = get_args()
query, key, value = super().get_query_key_value_tensors(*_args, **kwargs)
query = query.reshape(*query.shape[:-2], -1)
key = key.reshape(*key.shape[:-2], -1)
if args.tensor_model_parallel_size > 1:
query = gather_from_tensor_model_parallel_region(query)
key = gather_from_tensor_model_parallel_region(key)
query = self.q_norm(query)
key = self.k_norm(key)
if args.tensor_model_parallel_size > 1:
query = scatter_to_tensor_model_parallel_region(query)
key = scatter_to_tensor_model_parallel_region(key)
query = query.view(*query.shape[:2], -1, self.hidden_size_per_attention_head)
key = key.view(*key.shape[:2], -1, self.hidden_size_per_attention_head)
return query, key, value
args = get_args()
query, key, value = super().get_query_key_value_tensors(*_args, **kwargs)
query = query.reshape(*query.shape[:-2], -1)
key = key.reshape(*key.shape[:-2], -1)
use_tp = args.tensor_model_parallel_size > 1
if use_tp:
query = gather_from_tensor_model_parallel_region(query)
key = gather_from_tensor_model_parallel_region(key)
query = self.q_norm(query)
key = self.k_norm(key)
if use_tp:
query = scatter_to_tensor_model_parallel_region(query)
key = scatter_to_tensor_model_parallel_region(key)
query = query.view(*query.shape[:2], -1, self.hidden_size_per_attention_head)
key = key.view(*key.shape[:2], -1, self.hidden_size_per_attention_head)
return query, key, value

@Jintao-Huang Jintao-Huang merged commit baaa18d into modelscope:main Jan 18, 2026
1 of 3 checks passed
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.

3 participants