-
Notifications
You must be signed in to change notification settings - Fork 264
Modernize structural pattern matching #1951
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
Modernize structural pattern matching #1951
Conversation
👋 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 @ojeda-e, 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 modernizing the Python codebase by adopting contemporary language features. The primary changes involve updating type hints to the more recent Highlights
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
|
341b87d
to
7b24bdd
Compare
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 effectively modernizes the codebase by replacing older type hint syntax with the newer |
operator for unions and if/isinstance
chains with structural pattern matching (match...case
). The changes are applied consistently across the modified files, leading to more readable and modern Python code. My review includes one suggestion to correct a misplaced comment in src/llmcompressor/pipelines/cache.py
to improve code clarity and maintainability.
206c9ad
to
8b4069e
Compare
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 contribution! Few change requests but looks good for the most part
0089e68
to
bbb11d3
Compare
Thanks @brian-dellabetta I addressed your comments in the last commit. |
Signed-off-by: ojeda-e <[email protected]>
fix comment in the `_offload_value` method. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: ojeda-e <[email protected]>
Signed-off-by: ojeda-e <[email protected]>
Signed-off-by: ojeda-e <[email protected]>
1336e1e
to
7f62ec0
Compare
Signed-off-by: ojeda-e <[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.
Looks good, thanks!
Part of #1927
This PR includes changes to modernize type hints and structural pattern matching in:
src/llmcompressor/pipelines/cache.py
- Cache system with recursive typessrc/llmcompressor/modifiers/quantization/gptq/gptq_quantize.py
- GPTQ logicsrc/llmcompressor/modifiers/pruning/sparsegpt/sgpt_base.py
- SparseGPT logicmake test
,make style
andpytest tests -m smoke
passing locally.Please correct me if I am wrong here, but IMO
TYPE_CHECKING
is not necessary in any of these files. Since all imports are runtime required (torch, transformers, etc),TYPE_CHECKING
would only add runtime overhead.Added some comments to clarify why
case _:
is necessary insrc/llmcompressor/pipelines/cache.py
.