-
Notifications
You must be signed in to change notification settings - Fork 482
[AWQ] Restructure AWQModifier as smoothing-only, decouple from Quanti… #2511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.awq import AWQModifier | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| # Select model and load it. | ||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
@@ -49,10 +50,13 @@ def tokenize(sample): | |
|
|
||
|
|
||
| # Configure the quantization algorithm to run. | ||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||
| _ignore = ["lm_head"] | ||
| _scheme = "FP8_BLOCK" | ||
| _targets = ["Linear"] | ||
| recipe = [ | ||
| AWQModifier( | ||
| ignore=["lm_head"], scheme="FP8_BLOCK", targets=["Linear"], duo_scaling="both" | ||
| ), | ||
| AWQModifier(ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"), | ||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| ] | ||
|
Comment on lines
57
to
60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between _ignore = ["lm_head"]
_scheme = "FP8_BLOCK"
_targets = ["Linear"]
recipe = [
AWQModifier(
ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"
),
QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets),
] |
||
|
|
||
| # Apply algorithms. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.awq import AWQModifier | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| # Select model and load it. | ||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
@@ -49,10 +50,13 @@ def tokenize(sample): | |
|
|
||
|
|
||
| # Configure the quantization algorithm to run. | ||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||
| _ignore = ["lm_head"] | ||
| _scheme = "FP8_DYNAMIC" | ||
| _targets = ["Linear"] | ||
| recipe = [ | ||
| AWQModifier( | ||
| ignore=["lm_head"], scheme="FP8_DYNAMIC", targets=["Linear"], duo_scaling="both" | ||
| ), | ||
| AWQModifier(ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"), | ||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| ] | ||
|
Comment on lines
57
to
60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between _ignore = ["lm_head"]
_scheme = "FP8_DYNAMIC"
_targets = ["Linear"]
recipe = [
AWQModifier(
ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"
),
QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets),
] |
||
|
|
||
| # Apply algorithms. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.awq import AWQModifier | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| # Select model and load it. | ||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
@@ -49,10 +50,13 @@ def tokenize(sample): | |
|
|
||
|
|
||
| # Configure the quantization algorithm to run. | ||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||
| _ignore = ["lm_head"] | ||
| _scheme = "W4A16_ASYM" | ||
| _targets = ["Linear"] | ||
| recipe = [ | ||
| AWQModifier( | ||
| ignore=["lm_head"], scheme="W4A16_ASYM", targets=["Linear"], duo_scaling="both" | ||
| ), | ||
| AWQModifier(ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"), | ||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| ] | ||
|
Comment on lines
57
to
60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between _ignore = ["lm_head"]
_scheme = "W4A16_ASYM"
_targets = ["Linear"]
recipe = [
AWQModifier(
ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling="both"
),
QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets),
] |
||
|
|
||
| # Apply algorithms. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,18 +4,19 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from llmcompressor import oneshot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from llmcompressor.modifiers.awq import AWQModifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MODEL_ID = "Qwen/Qwen3-Coder-30B-A3B-Instruct" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SAVE_DIR = MODEL_ID.split("/")[-1] + "-W4A16-awq" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Configure the quantization algorithm to run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ignore = ["lm_head", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _scheme = "W4A16" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _targets = ["Linear"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| recipe = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AWQModifier( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| duo_scaling=False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ignore=["lm_head", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scheme="W4A16", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targets=["Linear"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AWQModifier(duo_scaling=False, ignore=_ignore, scheme=_scheme, targets=_targets), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
17
to
20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Select calibration dataset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.awq import AWQModifier | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| # Select model and load it. | ||
| MODEL_ID = "Qwen/Qwen3-30B-A3B" | ||
|
|
@@ -50,12 +51,13 @@ def tokenize(sample): | |
|
|
||
| # Configure the quantization algorithm to run. | ||
| # NOTE: vllm currently does not support asym MoE, using symmetric here | ||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||
| _ignore = ["lm_head", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"] | ||
| _scheme = "W4A16" | ||
| _targets = ["Linear"] | ||
| recipe = [ | ||
| AWQModifier( | ||
| ignore=["lm_head", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"], | ||
| scheme="W4A16", | ||
| targets=["Linear"], | ||
| ), | ||
| AWQModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| ] | ||
|
Comment on lines
58
to
61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between _ignore = ["lm_head", "re:.*mlp.gate$", "re:.*mlp.shared_expert_gate$"]
_scheme = "W4A16"
_targets = ["Linear"]
recipe = [
AWQModifier(
ignore=_ignore,
scheme=_scheme,
targets=_targets,
),
QuantizationModifier(
ignore=_ignore,
scheme=_scheme,
targets=_targets,
),
] |
||
|
|
||
| # Apply algorithms. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.awq import AWQModifier | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| # Select model and load it. | ||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
@@ -39,13 +40,13 @@ def preprocess(example): | |
| # Configure the quantization algorithm to run. | ||
| # W4AFP8 scheme: 4-bit integer weights (group 128) + FP8 dynamic per-token activations | ||
| # AWQ smooths the weights before quantization to reduce quantization error. | ||
| # AWQModifier applies smoothing, then QuantizationModifier finalizes quantization. | ||
| _ignore = ["lm_head"] | ||
| _scheme = "W4AFP8" | ||
| _targets = ["Linear"] | ||
| recipe = [ | ||
| AWQModifier( | ||
| ignore=["lm_head"], | ||
| scheme="W4AFP8", | ||
| targets=["Linear"], | ||
| duo_scaling=True, | ||
| ), | ||
| AWQModifier(ignore=_ignore, scheme=_scheme, targets=_targets, duo_scaling=True), | ||
| QuantizationModifier(ignore=_ignore, scheme=_scheme, targets=_targets), | ||
| ] | ||
|
Comment on lines
47
to
50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve maintainability and avoid duplicating parameters between _ignore = ["lm_head"]
_scheme = "W4AFP8"
_targets = ["Linear"]
recipe = [
AWQModifier(
ignore=_ignore,
scheme=_scheme,
targets=_targets,
duo_scaling=True,
),
QuantizationModifier(
ignore=_ignore,
scheme=_scheme,
targets=_targets,
),
] |
||
|
|
||
| # Apply algorithms. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than requiring user to set this explicitly, and to retain backward compatibility, i propose we append this when the recipe is parsed. if a user provides AWQ without a follow-on modifier that quantizes, we should append it with the same ignore,scheme,targets,config_groups