-
Notifications
You must be signed in to change notification settings - Fork 347
[TorchOffloader] Code Cleanup #2147
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
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Summary of ChangesHello @kylesayrs, 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 focuses on a significant code cleanup by removing deprecated Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
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 focuses on code cleanup by removing the dependency on accelerate for offloading and refactoring the modifier lifecycle. The changes are generally good, moving model-dependent initializations to the on_start hook for better consistency. However, I've identified a couple of issues. A potential bug in fuse.py omits casting tensors back to their original data type, which could lead to issues. Additionally, the removal of XPU support in the sequential pipeline is a regression that should be addressed. My detailed comments and suggestions are provided below.
| weight = embedding.weight.to(PRECISION) | ||
| weight = weight - weight.mean(dim=-1, keepdim=True) | ||
| update_offload_parameter(embedding, "weight", weight) |
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 weight tensor is not cast back to its original data type after the centering operation. It remains as PRECISION (torch.float64), which could lead to increased memory usage and potential dtype mismatches in subsequent operations. It's recommended to restore the casting back to the original dtype before updating the parameter.
| weight = embedding.weight.to(PRECISION) | |
| weight = weight - weight.mean(dim=-1, keepdim=True) | |
| update_offload_parameter(embedding, "weight", weight) | |
| weight_dtype = embedding.weight.dtype | |
| weight = embedding.weight.to(PRECISION) | |
| weight = weight - weight.mean(dim=-1, keepdim=True) | |
| update_offload_parameter(embedding, "weight", weight.to(weight_dtype)) |
| linear_weight = linear.weight.to(PRECISION) * norm.weight.to(PRECISION) | ||
| update_offload_parameter(linear, "weight", linear_weight) |
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.
Similar to the center_embeddings function, the linear_weight is calculated using PRECISION (torch.float64) but is not cast back to the original linear.weight.dtype. This could lead to unintended dtype changes, increased memory usage, and potential errors. The weight should be cast back to its original data type.
| linear_weight = linear.weight.to(PRECISION) * norm.weight.to(PRECISION) | |
| update_offload_parameter(linear, "weight", linear_weight) | |
| weight_dtype = linear.weight.dtype | |
| linear_weight = linear.weight.to(PRECISION) * norm.weight.to(PRECISION) | |
| update_offload_parameter(linear, "weight", linear_weight.to(weight_dtype)) |
| model_device = "cuda" if torch.cuda.is_available() else "cpu" | ||
| dispatch_model(model, model_device) |
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 previous implementation in dispatch_for_sequential included a check for torch.xpu.is_available() to support Intel XPU devices. This change removes that check, which is a regression in functionality. It would be beneficial to reintroduce XPU support to maintain broader hardware compatibility.
| model_device = "cuda" if torch.cuda.is_available() else "cpu" | |
| dispatch_model(model, model_device) | |
| if torch.cuda.is_available(): | |
| model_device = "cuda" | |
| elif hasattr(torch, "xpu") and torch.xpu.is_available(): | |
| model_device = "xpu" | |
| else: | |
| model_device = "cpu" | |
| dispatch_model(model, model_device) |
Purpose