Repository navigation
fix(awq): stage and pack every module at its own width - #3563
Merged
Merged
Conversation
`AWQConfig` accepts a per-module width through `dynamic` (e.g. W8 on one layer of a W4 run). `create_quant_module` applied that override when it built the module, but the staging pass, the clip search and the scale search all read `qcfg.bits` directly. A W8 module therefore staged 4-bit codes and packed them into an 8-bit container. Measured on upstream before this change: a module whose config says `bits: 8` staged codes in the 4-bit range (widest code 7.0, where W8 allows 127), i.e. it was quantized as W4 and mislabelled as W8. Resolve the width once in `_module_bits` (falling back to the global width for an excluded module or a rule that only sets another key -- neither is a width, and coercing them to 0 was wrong too) and thread it through: - `pseudo_quantize_tensor` / `_pseudo_quantize_tensor_into` - `_search_best_scale` / `_compute_best_scale` (clip + scale search) - the GSQ refine step - the packing `create_quant_module` call A scaling group shares one activation scale, so its first member's width drives the search; `apply_quant` re-quantizes each module at its own width afterwards. The CUDA GEMM/GEMV kernels unpack 4-bit codes only, so a non-4-bit module now routes to the portable `AwqTorchLinear` (2-8 bits) instead of being handed to a kernel that cannot represent it.
Resolve widths in scale search and use each linear\x27s quantizer for every candidate shared scale. Add independent scale and quantization oracles plus real packing, reload, dispatch and repeated-forward coverage. Validation: 82 targeted tests passed on CPU and NVIDIA GB10 (Torch 2.11.0+cu130). AWQ weight-mean, clip and lifecycle suites: 138 passed, 1 skipped; the MoE policy failure reproduces on the untouched PR head. Ruff and git diff --check passed.
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.
Bug
AWQConfigaccepts a per-module width throughdynamic:create_quant_modulehonours that override when it builds the module. Butpseudo_quantize_tensor, the clip search and the scale search all readself.qcfg.bitsdirectly, so a W8 module staged 4-bit codes and packed theminto an 8-bit container.
Demonstrated on
upstream/main:The result is a checkpoint whose
config.jsonmisdescribes its own tensors.Second bug, same root
dynamic_getreturns the raw override, which isFalsefor an excluded module(
-model.layers.0.mlp.up_proj) andNonefor a rule that only sets another key(
{"group_size": 64}). Treating these sentinel values as widths can select width 0 (False) or raise a type error (None).Fix
Resolve the width once in
_module_bits()and thread it through every stage:pseudo_quantize_tensor/_pseudo_quantize_tensor_into— code range_search_best_scale/_compute_best_scale— clip + scale searchcreate_quant_modulecall_module_bitsfalls back to the global width forFalseorNone.A scaling group shares one activation scale, but each member is evaluated at its own configured width for every candidate scale. This keeps the reconstruction-loss objective consistent with the final mixed-width checkpoint.
For GEMM checkpoints, W8 modules route to the portable
AwqTorchLinear; the CUDA GEMM kernel only supports W4. GEMV formats retain their existing W4 restriction.Validation
tests/test_awq_per_module_bits.py: 82 passed on CPU and NVIDIA GB10, Torch 2.11.0+cu130.tests/test_awq_weight_mean.py,tests/test_awq_clip_consistency.py, andtests/test_awq_gptq_lifecycle.py: 138 passed, 1 skipped, 1 pre-existing failure. The MoE policy testtest_public_moe_model_policies_enable_pointwise_roots_and_childrenalso fails on the untouched PR head7fb3b5ee.7fb3b5eeand passes with this fix. It covers W4/W8 in both orders, symmetric/asymmetric quantization, and chunked/eager activation replay on CPU and CUDA.rtol=atol=1e-6; discrete codes match exactly.apply_quant→pack_module→ state-dict reload → repeated forward tests cover W4/W8, symmetric/asymmetric quantization, FP16/BF16, and CPU/CUDA. All packed weight and zero-point words match the independent packing oracle exactly. Inference matches independently reconstructed weights atrtol=atol=2e-3.git diff --checkpass.