Skip to content

Conversation

ojeda-e
Copy link
Contributor

@ojeda-e ojeda-e commented Oct 20, 2025

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 types
  • src/llmcompressor/modifiers/quantization/gptq/gptq_quantize.py - GPTQ logic
  • src/llmcompressor/modifiers/pruning/sparsegpt/sgpt_base.py - SparseGPT logic

make test, make style and pytest 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 in src/llmcompressor/pipelines/cache.py.

@github-actions
Copy link

👋 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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 | syntax and refactoring conditional logic that checks for object types into structural pattern matching statements. These updates enhance code readability and maintainability by leveraging newer Python capabilities.

Highlights

  • Type Hint Modernization: Updated type hints across multiple files to use the more concise X | Y syntax instead of Union[X, Y] and Optional[X].
  • Structural Pattern Matching Adoption: Replaced numerous isinstance checks with Python's structural pattern matching (match/case statements) for improved readability and conciseness, particularly in handling different data types and module types.
  • Unnecessary Import Removal: Removed TYPE_CHECKING imports, as the author noted they are not necessary given all imports are runtime required.
  • Code Clarity: Added comments to clarify the necessity and usage of case _: in src/llmcompressor/pipelines/cache.py.
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.

@ojeda-e ojeda-e force-pushed the issue-1927-pattern-matching branch from 341b87d to 7b24bdd Compare October 20, 2025 15:02
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 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.

@ojeda-e ojeda-e force-pushed the issue-1927-pattern-matching branch 2 times, most recently from 206c9ad to 8b4069e Compare October 20, 2025 15:14
Copy link
Collaborator

@brian-dellabetta brian-dellabetta left a 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

@ojeda-e ojeda-e force-pushed the issue-1927-pattern-matching branch from 0089e68 to bbb11d3 Compare October 20, 2025 22:02
@ojeda-e
Copy link
Contributor Author

ojeda-e commented Oct 20, 2025

Thanks @brian-dellabetta I addressed your comments in the last commit.

ojeda-e and others added 4 commits October 20, 2025 17:18
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]>
@ojeda-e ojeda-e force-pushed the issue-1927-pattern-matching branch from 1336e1e to 7f62ec0 Compare October 20, 2025 23:19
kylesayrs
kylesayrs previously approved these changes Oct 21, 2025
Copy link
Collaborator

@kylesayrs kylesayrs left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@brian-dellabetta brian-dellabetta added the ready When a PR is ready for review label Oct 21, 2025
@brian-dellabetta brian-dellabetta enabled auto-merge (squash) October 21, 2025 16:19
@brian-dellabetta brian-dellabetta merged commit 100cc26 into vllm-project:main Oct 21, 2025
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready When a PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants