Repository navigation
fix(awq): size scale-search replay by sequence rows and inherit fallback threshold (#4087) - #4089
Merged
Merged
Conversation
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.
Fixes #4087
TL;DR
Two localized defects, one per issue item:
AWQProcessor._scale_search_replay_batch_sizesized a 3-D capture by its hidden width instead of one leading-dimension row, so[128, 2048, H]captures returned0("one forward over everything") and 7-8B AWQ OOMed.fallback=given as a dict defaulted the threshold to1.0%instead of theFallbackdataclass's0.5%, silently moving modules from GPTQ to RTN.Net diff: 7 files, +259/-8 (two source files, one override-path unification, two test files,
README.md, and a new reference page).1. The problem
1a. Replay sizing ignored the sequence dimension
AWQProcessor._scale_search_replay_batch_size(gptqmodel/looper/awq_processor.py:2992on1de03752d;:3010on701e58b) did:A 3-D capture is
[batches, seq, hidden]; one leading-dimension row isseq * hiddenelements. For[128, 2048, 4096]the estimate was 24 KiB/row instead of 48 MiB/row, sobudget_rows >= rowsand the helper returned0. The MLP group then ran 262,144 tokens in one forward: 2 GiB input and a 7 GiBLlamaMLPoutput.1b. A dict
fallback=doubled the threshold_normalize_fallback(gptqmodel/quantization/config.py:3533on1de03752d) usedfallback.get("threshold", "1.0%"), whileFallback.threshold(:1474) anddocs/quantization_protocol.mdsay0.5%. A dict that only setstrategyorsmooththerefore got1.0%. The decision inAWQProcessor._should_fallback_group/GPTQcompares observed calibration tokens against that percentage, so the doubled default moved 428 more Qwen3-30B-A3B experts from GPTQ to RTN (issue measurement: 1458 -> 1886).2. The fix
2a. Size a row from the leading dimension
rowsis stillx.shape[0]; the per-row element count isnumel // rows, so the sequence dimension is included for any rank. A zero-element capture returnsNone(one forward over nothing) instead of dividing by an empty row; a 1-D input has one element per row;rows <= 1returnsNonebecause one row is the minimum chunk.2b. One threshold default
The dict path now defaults to
Fallback.threshold.gptqmodel/utils/fallback.py:normalize_fallback(the per-module override path used byGPTQProcessor,AWQProcessor,VPTQProcessor,QQQProcessor, andParoQuantProcessor) merges its override onto the config default and delegates construction to the same_normalize_fallback, so the two entry points cannot drift again.3. Flow
Replay sizing
flowchart TD A["_search_best_scale: captured inp"] --> B["_scale_search_replay_batch_size"] B --> C{"x.dim == 0 or<br/>rows <= 1?"} C -- yes --> D["return None<br/>one forward"] C -- no --> E{"x.numel == 0?"} E -- yes --> D E -- no --> F["rows = x.shape[0]<br/>elements_per_row = x.numel // rows"] F --> G["bytes_per_row = elements_per_row<br/>* element_size * 3"] G --> H{"budget_rows = max_chunk_memory // bytes_per_row<br/>budget_rows >= rows?"} H -- yes --> I["return 0<br/>whole replay fits"] H -- no --> J["return max(quant_batch_size, budget_rows)<br/>chunked replay"] J --> K["_iter_prepared_forward_outputs<br/>torch.split(x, batch_size, dim=0)"]Fallback normalization
flowchart TD A["GPTQConfig / AWQConfig / EXL3Config<br/>__post_init__"] --> B["_normalize_fallback"] C["per-module override:<br/>utils.fallback.normalize_fallback"] --> B B --> D{"fallback type"} D -- "None" --> E["None"] D -- "Fallback" --> F["validate strategy + smooth"] D -- "str, int, float" --> G["Fallback(strategy=RTN, threshold=value)"] D -- "dict" --> H["threshold = fallback.get(<br/>'threshold', Fallback.threshold)"] H --> I["Fallback(strategy, threshold, smooth)"] I --> F4. Helper before / after
[128, 2048, 4096]fp160(one 6.44 GiB chunk)21(1.06 GiB chunk)[128, 2048, 14336]fp160(one 22.5 GiB chunk)6(1.06 GiB chunk)[262144, 4096]fp164369043690(unchanged)[4, 0, 8]0None[N]00Config thresholds:
GPTQConfig(...).fallback.threshold0.5%0.5%GPTQConfig(..., fallback={"strategy": "rtn"})1.0%0.5%GPTQConfig(..., fallback={"smooth": "mad"})1.0%0.5%AWQConfig(..., fallback={"strategy": "rtn"})1.0%0.5%EXL3Config(..., fallback={"strategy": "rtn"})1.0%0.5%fallback={"threshold": "2.0%"}2.0%2.0%5. Real-model before / after
Hardware: RTX 4090 (48 GiB),
CUDA_VISIBLE_DEVICES=GPU-d458708b-c760-bbf1-08fb-8b8803a2157d. The RTX 5090 was never used. Calibration: 128 x 2048 C4 token windows, AWQ 4-bit group size 128,batch_size=1.Llama-3.1-8B-Instruct, 32 GiB allocator cap
Before (
1de03752d, 3-D batch capture):After:
The after run passed the layer where the before run OOMed; it was stopped manually for time. The same 8B model with the default token-row aggregation completed AWQ end to end under the same 32 GiB cap (
PEAK_ALLOC_GIB: 5.33,PEAK_RESERVED_GIB: 31.96, 2 allocator retries).Llama-3.2-1B-Instruct, 12 GiB allocator cap
Before (
1de03752d):After:
The after-fix 1B quantize is still running; the trace above is from that run and it passed the first MLP group that OOMed before. I will update this section with its final peak/PPL when it completes.
Note on the current default path
Current
main's defaultawq_input_feature_aggregationtoken-row policy caps a dense capture at one largest-batch equivalent (2048 tokens for 128 x 2048), so the 3-D[batches, seq, hidden]shape is only reached when a model selectsmode=batch(or a model without the policy). The harness pins that mode to exercise the exact capture shape from the issue; the shipped sizing helper and forward are unchanged.6. Tests
Regression tests added:
tests/test_awq_scale_search_memory.py::test_scale_search_replay_batch_size_accounts_for_the_sequence_dimension— 3-D[128, 2048, 4096]returns> 0andbatch_size * per_row_bytes <= budget.tests/test_awq_scale_search_memory.py::test_scale_search_replay_batch_size_keeps_the_2d_row_size— 2-D behavior unchanged.tests/test_awq_scale_search_memory.py::test_scale_search_replay_batch_size_handles_empty_and_1d_inputs— 0-element ->None, 1-D -> one element per row.tests/test_fallback.py::test_dict_fallback_keeps_the_dataclass_threshold_default— plain, dict-strategy, and dict-smooth forms for GPTQ + AWQ, explicit threshold still wins, per-module override path shares the default.Before the fix (source reverted, tests kept): 3 failed, 1 passed.
After the fix: 4 passed.
Commands run after merging
origin/main(d3b5e0b7a):ruff check gptqmodel docs/eora tests setup.py->All checks passed!pytest -q tests/test_awq_scale_search_memory.py tests/test_fallback.py -k "replay_batch_size or dict_fallback_keeps or should_use_fallback"->20 passed, 68 deselectedHIP_VISIBLE_DEVICES=2): same selection ->20 passed, 108 deselectedtests/test_awq_weight_mean.py -k "coalesces_cpu_activation_replay or disable_chunked_activation_streaming"could not collect on the CUDA venv (pre-existing missingparameterized); it collects and runs on the ROCm venv.7. Reviewer notes / limitations
mode=batchaggregation and for any other caller of the helper. The fix is rank-robust rather than specific to the batch path.