Repository navigation
fix(awq): aggregate variable-length calibration for every module (#4063) - #4071
Merged
Merged
Conversation
AWQ declared token-row packing only for MoE modules, so every dense module fell back to the latest capture when calibration batches had different sequence lengths. Calibration is sorted by length descending, so that was the shortest sample (32 of 55,091 tokens on Qwen2.5-0.5B) and AWQ measured no better than RTN. Make token_rows the default policy for every module (MoE roots keep the shared pre-router capture), and evaluate fallback coverage per layer instead of summing retained tokens over the group's siblings. Wikitext-2 PPL, 4-bit g128, 128 C4 calibration docs, save+reload: Llama-3.2-1B asym: 24.15 -> 21.23 (RTN 24.03) Qwen2.5-0.5B asym: 22.79 -> 22.23 (RTN 22.77) Qwen2.5-0.5B sym: 26.21 -> 24.92 (RTN 24.84) Add a variable-length AWQ-vs-RTN perplexity regression test, unit coverage for the default policy and per-layer fallback, and the calibration aggregation reference page.
This was referenced Nov 14, 2026
Merged
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 #4063
TL;DR
AWQ declared token-row calibration packing only for MoE modules. Every dense module therefore kept only the last variable-length capture, which is the shortest sample because calibration is sorted by length descending. AWQ scale search saw 32 of 55,091 tokens on Qwen2.5-0.5B and measured no better than RTN. This makes token rows the default for every module and checks fallback coverage per layer. Llama-3.2-1B AWQ drops from 24.15 to 21.23 PPL (RTN 24.03).
1. Root cause
BaseQModel.awq_input_feature_aggregation(gptqmodel/models/base.py:4785-4802atad0525cca) returned{"mode": "token_rows"}only for MoE roots and their children, andNonefor every dense module.AWQProcessor._layer_input_features(gptqmodel/looper/awq_processor.py:1355-1370) then fell through to_can_concat_batch_tensors; variable-length captures such as[1, 423, H]and[1, 36, H]cannot be concatenated, so theelsebranch kepttensors[-1](awq_processor.py:1357). Withbatch_size=1andcalibration_sort="desc"that is the shortest document.Second effect:
_should_fallback_group(awq_processor.py:1535-1561) summedretained_tokensover the group's siblings. q/k/v (3x) and gate/up (2x) passed the percentage threshold while a lonedown_projfell below it and silently became RTN.flowchart TD A["BaseQModel.awq_input_feature_aggregation(name)"] --> B{"name under a MoE root?"} B -- yes --> C["mode token_rows<br/>capture_root for the root"] B -- no --> D["None"] D --> E["AWQProcessor._layer_input_features"] C --> E E --> F{"_can_concat_batch_tensors?"} F -- yes --> G["batch concat<br/>all rows"] F -- no --> H["features[name] = tensors[-1]<br/>mode latest_batch"] H --> I["_should_fallback_group<br/>sums retained_tokens over siblings"] I --> J["q/k/v and gate/up pass by sum<br/>lone down_proj falls to RTN"] style H fill:#ffd6d6,stroke:#cc0000 style J fill:#ffd6d6,stroke:#cc0000file:lineat ad0525cgptqmodel/models/base.py:4785-4802{"mode": "token_rows"}for every module; MoE roots keepcapture_rootgptqmodel/looper/awq_processor.py:1357_pack_token_rowsover every capturegptqmodel/looper/awq_processor.py:1546-1554should_use_fallback2. New flow
flowchart TD A["BaseQModel.awq_input_feature_aggregation(name)"] --> B{"name is a MoE root?"} B -- yes --> C["mode token_rows<br/>capture_root = True"] B -- no --> D["mode token_rows"] C --> E["AWQProcessor._layer_input_features"] D --> E E --> F["_token_row_budget<br/>max of largest batch rows and batch count"] F --> G["_pack_token_rows<br/>deterministic bounded sample<br/>every non-empty batch contributes"] G --> H["feature_stats<br/>mode token_rows, raw_tokens, retained_tokens, batches"] H --> I["_should_fallback_group"] I --> J{"every layer individually covered?"} J -- yes --> K["AWQ scale search on packed rows"] J -- no --> L["RTN fallback for the whole group"] style L fill:#ffe9b3,stroke:#b38600AWQProcessor._feature_aggregation_policystill asks the model class, so a definition can narrow the policy; returningNonerestores the legacy latest-capture path and the per-layer fallback check then applies. The MoE shared pre-router capture (capture_root) and the router/padding fixes from #3036/#4035/#4060 are unchanged.3. Memory bound
AWQProcessor._token_row_budget(awq_processor.py:807) is:For
batch_size=1that is one longest-sample equivalent: 5,405 rows on Qwen2.5-0.5B (of 55,091) and 5,384 on Llama-3.2-1B (of 54,302). It is independent of corpus size, so the replay tensor does not grow with the number of calibration documents; the raw per-batch captures are released by_finalize_quantized_layer. Peak allocated VRAM for the Qwen AWQ run rose from 0.423 GB to 0.498 GB.4. Measured PPL
Wikitext-2 PPL, 4-bit,
group_size=128,batch_size=1, first 128 C4 documents, 80 x 512-token chunks, save then reload, RTX 4090. fp16 baselines use the same harness.Before the fix AWQ was tied with or worse than RTN. After it AWQ is 2.80 PPL better than RTN on Llama-3.2-1B and 0.54 better on Qwen2.5-0.5B (asymmetric). The symmetric Qwen case improves by 1.29 PPL but stays 0.08 PPL above RTN at the default bound. Raising the budget to 20,000 rows on the same corpus measures 24.68 PPL, so the residual is the bounded replay sample, not a lost capture; the default bound is kept for 70B memory safety.
5. Fail-before / pass-after
Regression test:
tests/test_awq_variable_length_ppl.py(gpu + slow; 128 C4 docs, 80 x 512 wikitext chunks, save+reload, asserts AWQ PPL is at least 0.5% below RTN).Before, on
ad0525cca(test file copied into a clean worktree):After, on this branch:
ROCm:
Unit-level fail-before (same file copied to the main worktree):
test_public_moe_model_policies_enable_pointwise_roots_and_children,test_awq_dense_variable_length_packs_every_batch_by_default, andtest_awq_fallback_group_checks_each_layer_independentlyall fail onad0525cca; all pass here.6. Other tests
The real MoE test now records attention as
token_rows(raw 101 / retained 53 / 3 batches) while expert telemetry and themlpscale feature are unchanged. Fulltests/test_awq_weight_mean.pyon ROCm reports 70 passed, 1 skipped, 6 failed. Five of the six also fail onad0525cca; the sixth (test_awq_weight_mean_matches_legacy_impl_0_cpu_gs32) is the same CPU-timing assertion family (streaming mean within 5% of the legacy loop) and flips under the current machine load (load average > 100). None of them touch aggregation.Ruff (pinned 0.14.2):
ruff check gptqmodel docs/eora tests setup.py->All checks passed!7. Docs
Committed
docs/awq-calibration-aggregation.md(old/new flow, per-layer fallback contract, memory bound, measured table) and linked it fromREADME.mdnext to the other AWQ calibration pages.8. Reviewer notes