Skip to content

Conversation

@hjh0119
Copy link
Collaborator

@hjh0119 hjh0119 commented Nov 18, 2025

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hjh0119, 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 addresses a bug in the Megatron GRPO trainer's server mode concerning weight synchronization. The changes refine the logic for how model weights are loaded and synchronized across distributed processes. By adjusting the conditions for initiating weight loading and performing synchronization, the PR ensures that all processes correctly participate in the weight management phase while centralizing the critical synchronization step to the main process, thereby preventing potential inconsistencies in the model's state during training or inference.

Highlights

  • Corrected Weight Loading Initiation: The _load_weights_to_server_in_buckets method, responsible for handling weight loading in server mode, is now initiated by all processes when vllm_mode is set to 'server', rather than being restricted solely to the main process.
  • Refined Weight Synchronization Scope: The _sync_bucket_to_server method, which performs the actual synchronization of weight buckets to the server, now explicitly includes a check to ensure that this operation is executed only by the main process, centralizing the synchronization step.
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 attempts to fix an issue with weight synchronization in the Megatron GRPO server mode. While the changes correctly involve all processes in the weight export step, which likely resolves a process hang, they inadvertently introduce a critical bug. The modifications cause only the weights from the main process to be synchronized, while weights from all other processes are discarded. This leads to an incomplete model update on the vLLM server. I have provided a detailed review comment explaining the issue and suggesting a path to resolution.

bucket_params: List of (name, tensor) tuples to sync
"""
if not bucket_params:
if not bucket_params or not self.is_main_process:
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change, combined with the modification at line 248, appears to introduce a critical bug. The change at line 248 causes _load_weights_to_server_in_buckets to be called on all processes, which is likely correct if export_weights is a collective operation. However, adding or not self.is_main_process here makes _sync_bucket_to_server return immediately on non-main processes. As a result, only the weights from the main process's weight_iterator are synchronized with the vLLM server, while weights from all other processes are silently ignored. This will lead to an incompletely updated model on the server.

To fix this, you should gather bucket_params from all processes onto the main process before syncing. This would likely require changes in the calling function, _load_weights_to_server_in_buckets, to orchestrate the gathering of buckets from all ranks before the main rank performs the synchronization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The complete weights have already been gathered in the upper _load_weights_to_server_in_buckets method, ignore.

@hjh0119 hjh0119 merged commit 5d8eb60 into modelscope:main Nov 18, 2025
1 of 2 checks passed
@hjh0119 hjh0119 deleted the fix-mg-server branch November 18, 2025 08:24
vx120 pushed a commit to vx120/ms-swift that referenced this pull request Nov 19, 2025
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.

2 participants