Repository navigation
fix(awq): validate group size against the packing kernel (#4095) - #4104
Merged
Merged
Conversation
- ask the resolved kernel's validate(in_features, out_features, group_size) instead of duplicating a partial in_features check - retune Phi-tiny-MoE expert gate/up (4096 -> 448) from 128 to 64 before calibration instead of failing in create_quant_module - use per-channel -1 only when it validates; leave unpackable modules such as the non-quantized PhiMoE router untouched - docs/awq-dynamic-group-size.md: new decision flow and measured Phi run Part of #4095 (item 3)
…-size-out-features
Qubitium
added a commit
that referenced
this pull request
Nov 15, 2026
…tions (#4091) (#4110) * fix(awq): replay packed calibration rows with their own mask and positions (#4091) - carry per-row provenance out of token-row packing - build a per-document block-diagonal attention mask and original position ids - fixes the batch_size>1 TypeError and cross-document attention in scale search - docs/awq-calibration-aggregation.md: replay flow and measured A/B table Part of #4091 (item 1) * test(awq): keep the shape-only kernel stub out of the kernel registry The merged #4104 test helper subclassed AwqGEMMLinear, so it registered a second AWQ_GEMM/GEMM kernel. Collecting the PPL test file and the group-size test file in one process made get_kernel_for_backend reject the real kernel as ambiguous. Use a non-subclass stub that delegates to AwqGEMMLinear._validate.
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4095 (item 3)
TL;DR
Phi-tiny-MoE AWQ with the default
group_size=128failed while packing theexpert
gate_proj/up_proj(out_features=448). The pre-calibration groupretune only checked the input axis. It now asks the resolved kernel's own
validate(in_features, out_features, group_size), so those 1024 expert modulesretune to 64 before calibration and the quantize completes.
Root cause
AWQProcessor._ensure_group_size_divisibilityandAWQProcessor._largest_supported_group_divisor(
gptqmodel/looper/awq_processor.py:513-600before this change) required onlyin_features % group_size == 0.AwqGEMMLinear._validate(
gptqmodel/nn_modules/qlinear/gemm_awq.py:209-229) additionally requiresout_features % group_size == 0.#4084already retuned the 512 expertdown_projmodules(
in_features=448) from 128 to 64. The expertgate_proj/up_proj(
in_features=4096,out_features=448) divided 128 on the input axis, so theykept 128 and failed in
create_quant_moduleafter the entire calibration pass:A duplicated partial predicate is exactly how this drifted from the kernel.
The fix
AWQProcessor._kernel_group_size_supportedcalls the resolved kernel'svalidate(bits=..., group_size=..., in_features=..., out_features=..., pack_dtype=..., dtype=...). No predicate is re-implemented in the looper._ensure_group_size_divisibilityretunes a module when its configured sizefails that validation, and
_largest_supported_group_divisorpicks thelargest
SUPPORTS_GROUP_SIZEvalue that validates.-1(per-channel) is used only when it validates. When even per-channel doesnot pack the shape, the configured size is left untouched and no override is
recorded, so a non-quantized module such as the
router:!PhiMoE router isnot rewritten with an invalid group size.
dtypeis passed from the module weight;deviceis left tocreate_quant_modulebecause this runs in the processor constructor beforeper-module placement is resolved.
Before / after (same 4096 -> 448 expert projection)
origin/main:This branch:
Full model,
Phi-tiny-MoE-instruct, bf16,AWQConfig(bits=4, group_size=128, sym=True, format=GEMM), 32 C4 documents,batch_size=1:The attention projections keep 128; only the expert matrices retune. The
non-quantized router no longer receives a
-1override.Flow
flowchart TD A["AWQProcessor._ensure_group_size_divisibility"] --> B["AWQProcessor._kernel_group_size_supported"] B --> C["resolved kernel validate<br/>in_features, out_features, group_size"] C -- valid --> D["keep configured group size"] C -- invalid --> E["AWQProcessor._largest_supported_group_divisor"] E --> F{"any supported size validates?"} F -- Yes --> G["record +:^module$ dynamic group_size override"] F -- No --> H{"per-channel -1 validates?"} H -- Yes --> I["record per-channel -1"] H -- No --> J["leave configured size, no override"] G --> K["_search_best_scale / pack_module"] I --> K J --> K D --> K classDef failure fill:#fdd,stroke:#c33 class J failureBefore/after of the decision mechanism:
in_features % group_size == 0validate(in_features, out_features, group_size)gate_proj/up_proj4096 -> 448create_quant_module-1-1only when it validates, otherwise no overrideThe same flow is committed to
docs/awq-dynamic-group-size.md(already linkedfrom
README.md).Tests
tests/test_awq_dynamic_group_size.py::test_awq_retunes_group_size_for_non_divisible_out_features(new) fails on
origin/main(AttributeError: AWQProcessor has no attribute _resolve_module_kernel) and passes here.tests/test_awq_dynamic_group_size.py::test_awq_leaves_unpackable_module_untouched(new) pins the no-override path for the 4096 -> 16 router shape.
448 -> 4096down_proj shape (fp16) instead of an un-packable448 -> 8.test_dynamic_group_size_selects_compatible_kernel_and_packswas missing its_module_formatstub binding onmainand failed there; it is bound now.Commands and results:
CUDA_VISIBLE_DEVICES=GPU-1ece7ec2-... pytest -q tests/test_awq_dynamic_group_size.pyHIP_VISIBLE_DEVICES=1 pytest -q tests/test_awq_dynamic_group_size.pyruff check gptqmodel docs/eora tests setup.pyHardware: RTX 4090 (
GPU-1ece7ec2-d88d-9284-93c8-d2578d90ad7e), CUDA 13.0 /torch 2.16.0.dev; AMD R9700 (gfx1201) via
HIP_VISIBLE_DEVICES=1, ROCm 10.1 /torch 2.16.0.dev for the unit tests.
Relation to #4100
#4100 (
Prajwal7-2002) targets the same defect with a differentawq_processor.pypatch. This PR supersedes it: it covers every case #4100covers (input-axis retune, output-axis retune, the kernel-owned predicate, and
the same missing
_module_formatstub fix in the test file) and adds theper-channel/no-override contract, the
docs/awq-dynamic-group-size.mdflowupdate, and a CUDA + ROCm test run.