Skip to content

[RL] support weight reload for low-bit rollout#9650

Merged
AniZpZ merged 41 commits intosgl-project:mainfrom
AniZpZ:quant_rollout
Dec 10, 2025
Merged

[RL] support weight reload for low-bit rollout#9650
AniZpZ merged 41 commits intosgl-project:mainfrom
AniZpZ:quant_rollout

Conversation

@AniZpZ
Copy link
Collaborator

@AniZpZ AniZpZ commented Aug 26, 2025

Motivation

add support for weight reload and quantization on the fly to support low-bit rollout
easy access to Flash-RL with sglang as rollout engine

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

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.

Summary of Changes

Hello @AniZpZ, 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 significant enhancements to the model loading mechanism, primarily to support dynamic weight reloading and on-the-fly quantization, specifically for low-bit (e.g., FP8) rollout strategies. It provides fine-grained control at the loader level to manage when and how weights are processed after loading, allowing for efficient incremental quantization and forced re-quantization without redundant operations.

Highlights

  • Enhanced Weight Reloading Control: Implemented new static methods in DefaultModelLoader (load_weights_and_postprocess, reset_model_weights_state, rebinding_and_load_weights) to manage the lifecycle of model weights, including preventing duplicate post-processing (like quantization) and enabling explicit re-quantization.
  • Support for Incremental FP8 Quantization: Facilitates scenarios where models are initially loaded in a higher precision (e.g., BF16) and then incrementally quantized to lower precision (e.g., FP8) online, allowing for efficient weight updates without re-running the full quantization process unnecessarily.
  • Robust State Management: The loader now intelligently records and restores original weight states and associated weight loaders, ensuring proper parameter handling during complex reloading operations and allowing for a clean reset when re-quantization is desired.
  • Comprehensive Documentation: Added a detailed "FP8 Rollout" section to the quantization.md documentation, explaining the motivation, new APIs, typical usage patterns, and advanced rebinding scenarios with clear Python code examples.
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

  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 support for weight reloading for low-bit rollout, adding new APIs to DefaultModelLoader and corresponding documentation. The changes are a good step towards more flexible quantization workflows. However, my review identified a few significant issues in the implementation. There is a critical bug related to incorrect data structure unpacking and a high-severity bug from incorrect API usage, both of which would lead to runtime errors. I've also pointed out a minor style issue regarding an misplaced import. The new documentation contains code examples that are affected by the implementation bugs, which I've also commented on.


# 2) Reload weights later without re-quantization (fast path)
new_weights = ... # obtain your weights dict/iterator
DefaultModelLoader.load_weights_and_postprocess(model, new_weights, target_device=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Passing target_device=None will cause a runtime error as the underlying device_loading_context function expects a torch.device object and does not handle None. You should retrieve the device from the model's parameters before calling this function.

For example:

# Before line 192
target_device = next(model.parameters()).device
# Then on line 192
DefaultModelLoader.load_weights_and_postprocess(model, new_weights, target_device)

This issue also applies to lines 197 and 219.

@AniZpZ AniZpZ changed the title [WIP]support weight reload for low-bit rollout [WIP][RL] support weight reload for low-bit rollout Aug 26, 2025
@AniZpZ AniZpZ changed the title [WIP][RL] support weight reload for low-bit rollout [RL] support weight reload for low-bit rollout Sep 1, 2025
@github-actions github-actions bot added documentation Improvements or additions to documentation quant LLM Quantization labels Nov 6, 2025
@github-actions github-actions bot added deepseek hicache Hierarchical Caching for SGLang sgl-kernel blackwell SM100/SM120 npu diffusion SGLang Diffusion model-gateway labels Dec 8, 2025
@AniZpZ AniZpZ removed documentation Improvements or additions to documentation amd dependencies Pull requests that update a dependency file lora Multi-modal multi-modal language model deepseek hicache Hierarchical Caching for SGLang sgl-kernel blackwell SM100/SM120 npu diffusion SGLang Diffusion model-gateway labels Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants