AWQ smooth layer quantization (v2) [not for land]#2431
AWQ smooth layer quantization (v2) [not for land]#2431
Conversation
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
Signed-off-by: Ramshankar07 <picographer0214@gmail.com>
…n scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
👋 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, 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 significantly advances AWQ quantization by integrating and refining smooth layer quantization capabilities. It introduces a dedicated option within the AWQ modifier to account for smooth layers during scale determination, supported by a unified and robust rescaling mechanism. The changes are thoroughly demonstrated through new example scripts covering a wide array of quantization schemes and MoE models, ensuring broad applicability and ease of use. Furthermore, the PR includes new tools for streamlined evaluation and consistent naming conventions, enhancing the overall testing and deployment workflow for AWQ-quantized models. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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
|
|
The quality checks have failed. Please run |
There was a problem hiding this comment.
Code Review
This pull request introduces support for smooth layer quantization in AWQ, including updates to the core AWQModifier logic and the addition of numerous example scripts for various models and quantization schemes. The save directory naming conventions in existing examples have also been standardized. The changes are well-structured, and the new feature is supported by comprehensive examples and testing scripts. I've identified a minor issue in one of the new test scripts where save directory names are hardcoded incorrectly, which could cause confusion.
| awq_time_smooth: float | None = None | ||
|
|
||
| if args.without_smooth or args.both: | ||
| save_baseline = "qwen3-0.6b-w4a16-awq-baseline" |
There was a problem hiding this comment.
The save_baseline directory is hardcoded to a name that doesn't reflect the MODEL_ID being used (meta-llama/Meta-Llama-3-8B-Instruct). This can be confusing and is likely a copy-paste error. It's better to derive the save directory name from the MODEL_ID for clarity and consistency.
| save_baseline = "qwen3-0.6b-w4a16-awq-baseline" | |
| save_baseline = f"{MODEL_ID.split('/')[-1]}-w4a16-awq-baseline" |
| print(f"Baseline metrics: {m}") | ||
|
|
||
| if args.with_smooth or args.both: | ||
| save_smooth = "qwen3-0.6b-w4a16-awq-with-smooth" |
There was a problem hiding this comment.
Similar to save_baseline, the save_smooth directory is hardcoded with a name that doesn't match the MODEL_ID. This should also be derived from MODEL_ID to avoid confusion.
| save_smooth = "qwen3-0.6b-w4a16-awq-with-smooth" | |
| save_smooth = f"{MODEL_ID.split('/')[-1]}-w4a16-awq-with-smooth" |
| w_qscheme, | ||
| ) | ||
| if is_smooth_layer: | ||
| layer.weight.data = quantized.to(weight_dtype) |
There was a problem hiding this comment.
Hi! While reviewing the also_quantize_smooth_layers logic in _rescale_and_fake_quantize_layer, I noticed a potential math issue.
Because of this specific check:
if is_smooth_layer:
layer.weight.data = quantized.to(weight_dtype)
else:
layer.weight.data = (quantized / scales_view).to(weight_dtype)The smooth layer doesn't divide by its scales_view (_run_samples):
-
Smooth Layer: Since the weight is fixed to
$Q(W_{sm}/s)$ , its physical output activation is scaled down to$\approx s^{-1} \cdot X$ . -
Balance Layer: It receives
$s^{-1} \cdot X$ from the smooth layer, but it also artificially scales down its own weights by$s$ (via theelsebranch). -
Combined Effect: The final output of the block becomes
$(s^{-1} \cdot X) \cdot (\frac{Q(W_{bal} \cdot s)}{s})^T = \mathbf{s^{-2}} \cdot \mathbf{X} \cdot Q(W_{bal} \cdot s)^T$ .
i added different evaluation code along the same lines as what we used previously, didn't want to clutter the other PR so made a new one