Skip to content

update disk offload#589

Merged
gushiqiao merged 2 commits intomainfrom
gsq/gradio
Dec 9, 2025
Merged

update disk offload#589
gushiqiao merged 2 commits intomainfrom
gsq/gradio

Conversation

@gushiqiao
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gushiqiao, 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 refines the model loading process by introducing more robust handling for lazy-loaded Safetensors files, accommodating different file structures. It also improves the maintainability of the Gradio user interface by restructuring how CSS is applied and adjusts the default quantization operation priority for specific GPU configurations.

Highlights

  • Improved Lazy Loading Logic: The mechanism for lazy loading model weights from Safetensors files has been enhanced to correctly identify and load from either a single Safetensors file or a directory containing block files, providing greater flexibility in model storage.
  • Gradio CSS Refactoring: The CSS styling for the Gradio demo has been refactored. The CSS string is now defined separately and applied dynamically using gr.HTML, which improves code organization and potentially allows for more flexible styling.
  • Quantization Operation Priority Adjustment: The default priority order for quantization operations on non-Ada architecture GPUs has been updated, now prioritizing vllm over sgl.
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 updates the disk offloading mechanism to support lazy loading from a single file, in addition to the existing directory-based loading. This is achieved by using pathlib.Path to check if lazy_load_file is a file. The changes are consistently applied across several modules, including mm_weight.py, layer_norm_weight.py, rms_norm_weight.py, tensor.py, and model.py. While the new functionality is correct, it has introduced significant code duplication. My review primarily focuses on suggesting refactoring to centralize the path resolution logic into helper methods, which would improve code maintainability. The pull request also includes some minor but positive refactoring in the Gradio UI code.

Comment on lines +134 to +137
if Path(self.lazy_load_file).is_file():
lazy_load_file_path = self.lazy_load_file
else:
lazy_load_file_path = os.path.join(self.lazy_load_file, f"block_{source_name.split('.')[1]}.safetensors")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to determine lazy_load_file_path is duplicated in several places in this file (e.g., lines 157-160, 220-223, 306-309, 349-352, 371-374, 694-697) and across other files in this PR. To improve maintainability, consider refactoring this into a helper method that takes a block identifier and returns the correct path.

Comment on lines +59 to +62
if Path(self.lazy_load_file).is_file():
lazy_load_file_path = self.lazy_load_file
else:
lazy_load_file_path = os.path.join(self.lazy_load_file, f"block_{name.split('.')[1]}.safetensors")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to determine lazy_load_file_path is duplicated in load_state_dict_from_disk within this file (lines 162-165 and 177-180). To improve maintainability and reduce code duplication, consider extracting this logic into a helper method. This pattern is also repeated in other files in this pull request.

Comment on lines +52 to +55
if Path(self.lazy_load_file).is_file():
lazy_load_file_path = self.lazy_load_file
else:
lazy_load_file_path = os.path.join(self.lazy_load_file, f"block_{self.weight_name.split('.')[1]}.safetensors")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to determine lazy_load_file_path is duplicated in load_state_dict_from_disk within this file (lines 118-121). To improve maintainability and reduce code duplication, consider extracting this logic into a helper method. This pattern is also repeated in other files in this pull request.

Comment on lines +45 to +48
if Path(self.lazy_load_file).is_file():
lazy_load_file_path = self.lazy_load_file
else:
lazy_load_file_path = os.path.join(self.lazy_load_file, f"block_{self.tensor_name.split('.')[1]}.safetensors")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to determine lazy_load_file_path is duplicated in load_state_dict_from_disk within this file (lines 103-106). To improve maintainability and reduce code duplication, consider extracting this logic into a helper method. This pattern is also repeated in other files in this pull request.

Comment on lines 170 to 183
if os.path.isdir(safetensors_path):
safetensors_files = glob.glob(os.path.join(safetensors_path, "*.safetensors"))
if self.lazy_load:
self.lazy_load_path = safetensors_path
non_block_file = os.path.join(safetensors_path, "non_block.safetensors")
if os.path.exists(non_block_file):
safetensors_files = [non_block_file]
else:
raise ValueError(f"Non-block file not found in {safetensors_path}. Please check the model path.")
else:
safetensors_files = glob.glob(os.path.join(safetensors_path, "*.safetensors"))
else:
if self.lazy_load:
self.lazy_load_path = safetensors_path
safetensors_files = [safetensors_path]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for determining safetensors_files is nearly identical to the logic in _load_quant_ckpt (lines 214-228). To improve maintainability and reduce code duplication, consider extracting this into a helper method. The helper could take safetensors_path and a boolean flag indicating if it's for a quantized checkpoint to handle the minor difference in logic (i.e., safetensors_path = os.path.dirname(safetensors_path)).

@gushiqiao gushiqiao merged commit 2620398 into main Dec 9, 2025
2 checks passed
@gushiqiao gushiqiao deleted the gsq/gradio branch December 11, 2025 10:26
helloyongyang pushed a commit that referenced this pull request Mar 6, 2026
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