Skip to content

fix update_weights_from_tensor#8150

Closed
SuperCB wants to merge 1 commit intosgl-project:mainfrom
SuperCB:fix_update
Closed

fix update_weights_from_tensor#8150
SuperCB wants to merge 1 commit intosgl-project:mainfrom
SuperCB:fix_update

Conversation

@SuperCB
Copy link
Copy Markdown

@SuperCB SuperCB commented Jul 18, 2025

Motivation

Modifications

Checklist

Copy link
Copy Markdown
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 @SuperCB, 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 a critical fix to the update_weights_from_tensor functionality by applying a specific PyTorch patch. The monkey_patch_torch_reductions call ensures that tensor operations, particularly reductions, behave as expected during weight updates, which is vital for the stability and correctness of the model in a distributed environment.

Highlights

  • Weight Update Robustness: A call to monkey_patch_torch_reductions() has been added at the beginning of the update_weights_from_tensor method within tp_worker.py. This change is intended to apply necessary PyTorch patches, likely to ensure correct behavior of tensor reduction operations during model weight updates, especially in a distributed or tensor-parallel context.
  • New Dependency Import: The monkey_patch_torch_reductions function is now imported from sglang.srt.patch_torch to support the new patching logic in the weight update process.
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 is currently in preview and 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 to provide feedback.

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
Copy Markdown
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 PR fixes a bug in update_weights_from_tensor by applying a monkey patch for correct tensor deserialization across processes. The change is correct and necessary. I've added one comment with a suggestion to improve the code structure by moving the patch call to the worker's initialization, which would make the change more robust and maintainable.

return success, message

def update_weights_from_tensor(self, recv_req: UpdateWeightsFromTensorReqInput):
monkey_patch_torch_reductions()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Applying monkey_patch_torch_reductions() here fixes deserialization issues. However, consider applying this patch once during TpModelWorker.__init__ instead, to ensure it's applied at worker initialization and avoid potential repeated calls. This centralizes process-level patches and clarifies the patch as a fundamental requirement for the worker.

@hebiao064
Copy link
Copy Markdown
Collaborator

@SuperCB can you share more details in the PR Description?

FYI @zhaochenyang20

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