add: GQA support to AWQ - #2818
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAWQModifier now detects and supports Grouped Query Attention patterns by extracting optional head dimension from model config, updating layer compatibility checks to return GQA metadata, storing this metadata in ResolvedMapping, and applying conditional scale compression during smoothing. ChangesGQA Support in AWQ Modifier
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsLinked repositories: Your configuration references 1 linked repositories, but your current plan allows 0. Analyzed ``, skipped Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
👋 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. |
There was a problem hiding this comment.
Code Review
This pull request adds support for Grouped Query Attention (GQA) in the AWQ modifier by extracting the head dimension from the model configuration, validating GQA ratios during compatibility checks, and compressing scales across GQA repeat groups during smoothing. Unit tests are also added to verify these changes. The review feedback highlights opportunities to improve robustness by replacing .view() with .reshape() to avoid RuntimeError on non-contiguous tensors, and adding a check to prevent a potential ZeroDivisionError if head_dim is zero.
0ebdc75 to
b268e18
Compare
Merge Protections🔴 2 of 2 protections blocking · waiting on 👀 reviews
🔴 Require one maintainer reviewWaiting for
This rule is failing.All PRs must have at least one approving review from a maintainer before merging.
🔴 Require two reviewsWaiting for
This rule is failing.PRs labelled "two-reviews" must have at least two approving reviews before merging.
|
|
Ran a quick perplexity check on Llama 3.2 1B (wikitext-2-raw-v1, 2048 token window, 32 calibration samples):
The results seem to be comparable, but with a 1B model, its not saying too much, will get a deployment running on h200s to test a larger model, but a 1.5% variance seems convincing. |
Results (
|
| Model | GQA Ratio | Config | arc_easy | hellaswag | piqa | winogrande |
|---|---|---|---|---|---|---|
| Llama 3.1 8B | 4:1 | FP16 | 0.825 | 0.793 | 0.812 | 0.745 |
| AWQ (upstream) | 0.789 | 0.783 | 0.801 | 0.726 | ||
| AWQ + GQA smooth | 0.790 | 0.787 | 0.796 | 0.710 | ||
| Mistral 7B v0.3 | 4:1 | FP16 | 0.802 | 0.807 | 0.821 | 0.741 |
| AWQ (upstream) | 0.789 | 0.799 | 0.813 | 0.729 | ||
| AWQ + GQA smooth | 0.789 | 0.802 | 0.819 | 0.731 | ||
| Gemma 2 9B | 2:1 | FP16 | 0.878 | 0.800 | 0.829 | 0.741 |
| AWQ (upstream) | 0.871 | 0.789 | 0.826 | 0.747 | ||
| AWQ + GQA smooth | 0.873 | 0.793 | 0.826 | 0.740 |
Summary
The implemented GQA smoothing strategy seems appears to be quality-neutral across all three architectures and both GQA ratios (4:1 and 2:1).
All differences between upstream and GQA smooth are within a good range of eachother. The new v_proj->o_proj smoothing path does not degrade model quality.
soyr-redhat
left a comment
There was a problem hiding this comment.
Reviewed Gemini Code Review
b30d468 to
c83dd4b
Compare
brian-dellabetta
left a comment
There was a problem hiding this comment.
Hi @soyr-redhat , thanks for setting this up. The changes make sense, lemme get @HDCharles 's thoughts on the complexity vs improvement tradeoff here.
You expect this to be generally applicable to any GQA model, yes?
|
Hey @brian-dellabetta! Thanks for taking a look. I personally do expect this to be generally applicable, as I ran some tests across a couple different architectures/ratios. At least as far as I'm aware, this should be agnostic since we're directly deriving the ratio from the model config! |
51a9e79 to
169b52f
Compare
|
|
||
| if self.duo_scaling: | ||
| w_mean = self._compute_layer_means(mapping.balance_layers).to(device) | ||
|
|
There was a problem hiding this comment.
i think you do the GQA adjustment right here, check for smooth_layer.out vs balance_layer.in get GQA factor, then take x_mean and/or w_mean and do the average + expand thing. Then all your scales will be defined correctly going forward
There was a problem hiding this comment.
Now compressing x_mean and w_mean to kv_dim right here. The grid search runs at kv_dim granularity, expanding to hidden_dim inside the loop for W*s on o_proj.
so e.g. when you go to compute the scales for the grid search, you have to check for GQA and then do the average+expand thing when necessary.
|
7c664c3 to
c7efe2b
Compare
1419b83 to
5ec58ec
Compare
4c8ef43 to
add6bfb
Compare
|
@HDCharles Latest round has been addressed! Would appreciate another look if you had any availability. Thank you! |
add6bfb to
ca3cd37
Compare
ca3cd37 to
1fbc999
Compare
Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
- simplify _check_layers_are_compatible to pure shape check - compress x_mean/w_mean to kv_dim before grid search - remove GQA compression from _smooth Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
Signed-off-by: Sawyer Bowerman <sbowerma@redhat.com>
1fbc999 to
fe081e7
Compare
SUMMARY:
Addresses #2808
AWQ currently skips v_proj -> o_proj smoothing for GQA models because _check_layers_are_compatible() rejects mappings where
v_proj.out_features != o_proj.in_features. In GQA models (Llama 3, Mistral, Qwen2, etc.), this mismatch is expected, KV heads are repeated via repeat_kv before feeding into o_proj.This PR adds GQA support by:
Fused qkv_proj with GQA is still lacking support. I'm unsure as to if this can be addressed by just knowing model dimensions.
Currently with runs, the logger outputs:
For every GQA layer.
TEST PLAN: