-
Notifications
You must be signed in to change notification settings - Fork 75
refactor init of compressor #1339
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: n1ck-guo <[email protected]>
Signed-off-by: n1ck-guo <[email protected]>
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.
Pull request overview
This PR refactors the initialization logic of the compressor by introducing a _post_init method to handle operations that require delayed execution. The changes move various setup operations from __init__ to _post_init to prevent bugs caused by incorrect call ordering, particularly for operations that depend on the model being fully loaded or other initialization steps being complete.
Changes:
- Introduced a
_post_initmethod to handle delayed initialization logic including scheme parsing, device setup, seed setting, and torch compile adjustments - Moved output directory path calculation logic from
__main__.pyinto thequantize_and_savemethod - Simplified
__init__by deferring complex initialization steps that have dependencies on other attributes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| auto_round/compressors/base.py | Refactored initialization by moving delayed-execution logic (scheme parsing, device setup, seed setting, etc.) from __init__ to new _post_init method; added path calculation to quantize_and_save and save_quantized |
| auto_round/main.py | Simplified by removing output directory path calculation logic that was moved into the compressor class |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: n1ck-guo <[email protected]>
Signed-off-by: n1ck-guo <[email protected]>
…-round into hengguo/refactor_init
Signed-off-by: n1ck-guo <[email protected]>
| ValueError: If an unsupported format is specified. | ||
| """ | ||
| # post init | ||
| self._post_init() |
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.
How can developers know which initialization code belongs in post_init?
Signed-off-by: n1ck-guo <[email protected]>
Description
Move some functions that require delayed execution to
post_initto avoid bugs caused by incorrect call order.Type of Change
Related Issues
Fixes or relates to #
Checklist Before Submitting