-
Notifications
You must be signed in to change notification settings - Fork 0
Update convert_weights_for_gaudi2.py #22
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?
Conversation
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.
Summary of Changes
Hello @yiliu30, 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 enhances the convert_weights_for_gaudi2.py script by introducing a new option to handle quantized MLP gate projection weights, making the conversion process more adaptable for different model configurations. It also improves the script's logging to provide clearer visibility into the weight conversion steps.
Highlights
- New Command-Line Argument: Introduced
--quant_mlp_gateto control the quantization of MLP gate projection weights, providing more flexibility for specific model architectures. - Extended Functionality: The
convert_files_per_tensorandconvert_filesfunctions now accept anargsobject, allowing them to utilize the new quantization flag and other potential future arguments. - Conditional Quantization Logic: The script now supports conditional quantization of
mlp.gateweights within theconvert_filesfunction, activated by the new--quant_mlp_gateargument. - Improved Logging: Added print statements to provide more detailed feedback during the weight conversion process, showing which weights are being updated and their resulting data types.
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
-
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. ↩
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.
Code Review
This pull request updates the weight conversion script to add support for quantizing MLP gate projection weights, controlled by a new command-line argument. The changes are functional, but there are a few areas for improvement regarding code clarity and maintainability. I've pointed out an unused function parameter and some potentially verbose print statements that could be refined.
|
|
||
| # Use Case: Hunyuan_V1 Dense and MOE models | ||
| def convert_files_per_tensor(input_path, output_path): | ||
| def convert_files_per_tensor(input_path, output_path, args): |
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.
The args parameter is added to the function signature but is not used within the convert_files_per_tensor function. To improve code clarity and maintainability, unused parameters should be removed. The corresponding call at line 151 should also be updated.
| def convert_files_per_tensor(input_path, output_path, args): | |
| def convert_files_per_tensor(input_path, output_path): |
| weight_nv = tensor_file.get_tensor(weight_name).float() | ||
| weight_fp32 = weight_scale_nv * weight_nv | ||
| weight_fp8, scale = quant_per_tensor(weight_fp32) | ||
| print(f"Update weight {weight_name} and scale {k}") |
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.
This print statement is inside a loop that iterates over all tensor keys. For models with many tensors, this will produce a large amount of output, which can make the script's progress hard to follow. It would be better to use the logging module for such diagnostic messages, allowing users to control the verbosity level.
| raise NotImplementedError(f"Cannot covert {k}") | ||
| else: | ||
| print(f"skip {k}.") | ||
| print(f"update {k} to dtype {tensor.dtype}") |
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.
| copy_other_files(input_path, output_path) | ||
| if per_tensor: | ||
| convert_files_per_tensor(input_path, output_path) | ||
| convert_files_per_tensor(input_path, output_path, args) |
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.
The args parameter is passed to convert_files_per_tensor here, but it is not used within that function. This argument should be removed from the function call to align with the suggested change at line 43 and improve code clarity.
| convert_files_per_tensor(input_path, output_path, args) | |
| convert_files_per_tensor(input_path, output_path) |
No description provided.