-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[RL] add post process method for low precision rl weight update #24657
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3518,6 +3518,50 @@ def update_weights_from_ipc(self, recv_req): | |
| logger.error(f"IPC weight update failed: {e}") | ||
| return False, str(e) | ||
|
|
||
| def post_process_weights(self, recv_req): | ||
|
Collaborator
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. todo: not sure whether this is the best impl
Contributor
Author
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. post_process_weights only calls once after all update_weights_from_xxx finished and once before. I am not sure whether there is a better way to improve the design. Do you have any suggestion? |
||
| """ | ||
| Execute post-processing logic for model weights, such as Marlin quantization format conversion | ||
| and model-specific post_load_weights hooks (e.g., DeepSeek MLA kv_b_proj decomposition). | ||
| """ | ||
| from sglang.srt.model_loader.loader import device_loading_context | ||
|
|
||
| target_device = torch.device("cuda", torch.cuda.current_device()) | ||
|
|
||
| if recv_req.post_load_weights: | ||
| # Call model.post_load_weights() if available (e.g., for DeepSeek MLA | ||
| # models that need to decompose kv_b_proj.weight into w_kc/w_vc tensors | ||
| # after RDMA weight transfer) | ||
| if hasattr(self.model, "post_load_weights"): | ||
| self.model.post_load_weights() | ||
|
|
||
| if recv_req.restore_weights_before_load: | ||
| for _, module in self.model.named_modules(): | ||
| quant_method = getattr(module, "quant_method", None) | ||
|
|
||
| # Check if the module supports restoring weights | ||
| if quant_method is not None and hasattr( | ||
| quant_method, "restore_weights_before_loading" | ||
| ): | ||
|
|
||
| with device_loading_context(module, target_device): | ||
| quant_method.restore_weights_before_loading(module) | ||
|
|
||
| if recv_req.post_process_quantization: | ||
| # Iterate through all modules to apply specific post-loading processing | ||
| for _, module in self.model.named_modules(): | ||
| quant_method = getattr(module, "quant_method", None) | ||
|
|
||
| # Check if the module supports quantization post-processing | ||
| if quant_method is not None and hasattr( | ||
| quant_method, "process_weights_after_loading" | ||
| ): | ||
|
|
||
| # Apply the post-processing (e.g., repacking weights for Marlin kernel) | ||
| with device_loading_context(module, target_device): | ||
| quant_method.process_weights_after_loading(module) | ||
|
|
||
| return True, "Success" | ||
|
|
||
| def prealloc_symmetric_memory_pool(self): | ||
| # PyTorch mempools never de-fragment memory in OOM scenarios, so we need to pre-allocate a large chunk of memory to limit fragmentation. | ||
| if ( | ||
|
|
||
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.
nit: is this a bit improveable
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for the review. Do you think we should combine the logic of post_process_weights into update_weights_from_xxx?