Skip to content

refactor(awq): restructure AWQModifier to be similar to SmoothQuantCl…#2402

Open
vishnuprasanth-j wants to merge 2 commits intovllm-project:mainfrom
vishnuprasanth-j:awq
Open

refactor(awq): restructure AWQModifier to be similar to SmoothQuantCl…#2402
vishnuprasanth-j wants to merge 2 commits intovllm-project:mainfrom
vishnuprasanth-j:awq

Conversation

@vishnuprasanth-j
Copy link

SUMMARY:

This PR restructures and simplifies AWQModifier to be similar to SmoothQuant. This is PR for: #2327

Solution:

This refactoring removes the quantization code from AWQModifier, making it perform smoothing only. AWQModifier now inherits from Modifier and HooksMixin (instead of QuantizationMixin), and must be stacked with a separate quantization modifier (QuantizationModifier, GPTQModifier, or QuIPModifier) to produce a quantized model. The changes include: (1) Removing QuantizationMixin inheritance and related code, (2) Adding recipe validation to ensure AWQ comes before quantization modifiers in the recipe, (3) Adding a warning when AWQ is used standalone without a subsequent quantization modifier, (4) All existing AWQ examples updated to use the new stacked pattern.

All existing AWQ examples updated and tested with new stacked pattern.

@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 @vishnuprasanth-j, 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 refactors the AWQModifier by separating its smoothing functionality from the actual quantization process. This change enhances modularity and clarity, positioning AWQModifier as a dedicated smoothing component that must be combined with a distinct quantization modifier to produce a fully quantized model. The update includes robust recipe validation and user warnings to guide proper implementation, along with comprehensive updates to all relevant examples.

Highlights

  • AWQModifier Refactoring: The AWQModifier has been restructured to focus solely on activation smoothing, removing its direct quantization responsibilities.
  • Modifier Inheritance Change: AWQModifier now inherits from Modifier and HooksMixin, no longer from QuantizationMixin, reflecting its specialized role.
  • Decoupled Quantization: Quantization logic previously within AWQModifier has been moved, requiring AWQModifier to be stacked with a separate quantization modifier (e.g., QuantizationModifier, GPTQModifier) to achieve a quantized model.
  • Recipe Validation: New validation has been added to the recipe processing to ensure that AWQModifier is placed before any quantization modifiers in the recipe stack.
  • Standalone AWQ Warning: A warning mechanism has been implemented to alert users if AWQModifier is used without a subsequent quantization modifier, indicating that weights will be smoothed but not quantized.
  • Example Updates: All existing AWQ examples have been updated to demonstrate the new stacked modifier pattern, ensuring compatibility and correct usage.

🧠 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
  • examples/awq/fp8_block_llama_example.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
    • Updated the save directory name to reflect FP8 block quantization.
  • examples/awq/fp8_dynamic_llama_example.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
    • Updated the save directory name to reflect FP8 dynamic quantization.
  • examples/awq/llama_example.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
  • examples/awq/llama_example_with_masking.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
  • examples/awq/qwen3_coder_moe_example.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
  • examples/awq/qwen3_moe_example.py
    • Imported QuantizationModifier.
    • Added QuantizationModifier to the recipe after AWQModifier.
  • src/llmcompressor/modifiers/awq/base.py
    • Removed imports related to quantization calibration and QuantizationMixin.
    • Changed AWQModifier's inheritance from QuantizationMixin to HooksMixin.
    • Updated docstrings to clarify AWQModifier's role as a smoothing-only modifier and its requirement for a subsequent quantization modifier.
    • Modified example recipe in docstring to include a stacked QuantizationModifier.
    • Removed calls to QuantizationMixin.initialize_quantization and QuantizationMixin.start_calibration.
    • Added a new private helper method _get_resolved_targets.
    • Implemented a new private helper method _warn_if_standalone to check for standalone AWQModifier usage.
    • Removed weight global scale and zero-point update logic from on_end, delegating it to subsequent quantization modifiers.
    • Simplified comments and removed redundant code related to activation caching and weight mean calculation.
  • src/llmcompressor/recipe/recipe.py
    • Added _validate_modifier_ordering function to enforce correct sequencing of AWQModifier and quantization modifiers.
    • Introduced _validate_awq_config_match, _extract_weight_params, and _compare_weight_params for consistent configuration validation.
    • Integrated modifier ordering validation into Recipe.from_modifiers and Recipe.from_dict methods.
  • tests/llmcompressor/modifiers/awq/test_base.py
    • Imported QuantizationModifier and Recipe for testing.
    • Added unit tests for AWQModifier._get_resolved_targets.
    • Included unit tests for _validate_modifier_ordering to verify correct and incorrect modifier sequences.
    • Added unit tests for Recipe.from_modifiers to confirm proper handling of AWQ and QuantizationModifier stacking.
Activity
  • The pull request author, vishnuprasanth-j, initiated this refactoring to simplify the AWQModifier by separating smoothing from quantization.
  • The author provided a detailed summary outlining the problem and the proposed solution.
  • All existing AWQ examples were updated and tested to ensure compatibility with the new stacked modifier pattern.
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.

@mergify mergify bot added the documentation Improvements or additions to documentation label Feb 24, 2026
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 refactors the AWQModifier to be a smoothing-only modifier, separating it from the quantization process. This is a significant architectural change that aligns it more closely with SmoothQuant and requires it to be stacked with a dedicated quantization modifier. The changes are well-reflected across the updated examples and the core modifier logic. I've identified a couple of areas for improvement: one concerning the accuracy of the grid search simulation for TENSOR_GROUP quantization, and another regarding the robustness of the new recipe validation logic when multiple configuration groups are used.

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.

Hi @vishnuprasanth-j , thanks for the contribution. I think this implementation is preferable to my draft PR #2206 to add a disable_quantization option to AWQModifier

We originally wanted AWQ to also quantize due to user feedback, but I think it complicates things more than it's worth, and we can always dynamically append a QuantizationModifier during recipe.validate if AWQ is found without an accompanying QuantizationModifier.

I will discuss with the team

@dsikka dsikka added the ready When a PR is ready for review label Mar 2, 2026
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.

Hi @vishnuprasanth-j , thanks for taking a stab at this. Ultimately we want to move to this, but your diff has a lot of unnecessary changes and I don't think it will work. But we can iterate over this if you'd like. I've left some comments for now

Comment on lines -224 to -225
# For non-MoE models, convert sentinel to None
# (no offloading by default)
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's hard to read through the changes to your diff because you're making a lot of changes that are unrelated to the restructure. please revert so the diff is clean and scoped to your PR changes


# Allow arbitrary types because AWQMapping has fields of type torch.nn.Module
model_config: ConfigDict = ConfigDict(arbitrary_types_allowed=True)
model_config: ConfigDict = ConfigDict(arbitrary_types_allowed=True, extra="allow")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is extra="allow" needed?


# apply config to model and prepare calibration hooks
if QuantizationMixin.has_config(self):
QuantizationMixin.initialize_quantization(self, state.model)
Copy link
Collaborator

Choose a reason for hiding this comment

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

removing this logic means apply_quantization_config is never run on the model, so no quantization_scheme is ever set on the targeted modules. I don't think your current implementation will work. Have you run this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ready When a PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants