Skip to content

Conversation

eldarkurtic
Copy link
Collaborator

@eldarkurtic eldarkurtic commented Sep 2, 2025

This PR adds stuff needed for per-attention-head attention/KV-cache quantization.
Should be reviewed along with the corresponding PR in compressed-tensors: neuralmagic/compressed-tensors#442

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.

Summary of Changes

Hello @eldarkurtic, 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 quantization capabilities by introducing support for per-attention-head quantization. This allows for more fine-grained control over the quantization process, particularly for attention mechanisms and KV-caches, which can lead to improved model efficiency or performance.

Highlights

  • Per-head Attention Quantization Support: Introduced a new QuantizationStrategy.ATTN_HEAD to enable per-attention-head quantization for attention and KV-cache, allowing for more granular control over the quantization process.
  • Quantization Parameter Calculation: Implemented logic within the get_qparams function to calculate quantization scales and zero-points along dimension 1 (per KV head) when the ATTN_HEAD strategy is active, specifically tested for GQA models.
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

  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.

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 introduces support for per-attention-head quantization by adding a new ATTN_HEAD strategy. The implementation correctly computes quantization parameters along the attention head dimension. However, a comment in the code indicates that this feature has only been tested with GQA models, which could lead to issues with other attention mechanisms. I've suggested adding a runtime warning to make this limitation clear to users.

@@ -249,6 +249,14 @@ def get_qparams(
self._scale[i, j] = scale_bp
self._zero_point[i, j] = zp_bp

elif self.quantization_args.strategy == QuantizationStrategy.ATTN_HEAD:
# observed.shape = [batch, num_kv_heads, tokens, head_dim]
# tested only for GQA models, add support for others as needed
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment on this line indicates a significant limitation: this implementation has only been tested for GQA models. This could lead to silent failures or incorrect behavior with other attention types like MHA or MQA. To make this limitation more explicit and prevent potential misuse, it's better to log a warning that will be visible at runtime instead of just having a comment.

                logger.bind(log_once=True).warning(
                    "ATTN_HEAD quantization strategy has only been tested for GQA "
                    "models. Use with other model types at your own risk."
                )

Copy link

github-actions bot commented Sep 2, 2025

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

Copy link
Collaborator

@dsikka dsikka left a comment

Choose a reason for hiding this comment

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

See CT PR comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants