Repository navigation
fix(awq): preserve the captured mask form and fallback precedence (#4121, #4125) - #4131
Merged
Merged
Conversation
) - AWQ token-row replay rebuilds the packed mask in the captured form: additive grids stay additive, HF bool keep grids stay bool, and masked_fill bool grids (TeleChat2) stay bool with True = masked - derive the keep set from the grid diagonal so a real padded batch_size>1 mask recovers the document structure instead of falling back - merge the processor fallback under a per-module dynamic override in GPTQ, MACaQ, QQQ and VPTQ; the last three never applied it at all - normalize_fallback merges every field, including smooth Part of #4121 (items 1, 4, 5) Part of #4125 (item 4)
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 #4121 (items 1, 4, 5)
Part of #4125 (item 4)
TL;DR
every captured attention grid with
dim >= 3into an additive float mask.TeleChat2's attention calls
masked_fill, sotests/test_telechat2_coverage.pyfailed on
main. The replay now rebuilds the mask in the captured form andpolarity: additive stays additive, a Hugging Face bool keep grid stays bool,
and a
masked_fillbool grid (TeleChat2triu(1)) stays bool withTrue= masked.allowed_grid.any(dim=-1).A real Hugging Face bool mask keeps padding keys masked but a padding
query row still sees the real keys, so every padding row counted as a real
token, the
!= row_countcheck failed, and the per-document mask was neverbuilt for real padded
batch_size>1captures. It now comes from the griddiagonal.
dynamicfallbackoverride wasapplied and then overwritten by the processor-level fallback in GPTQ, MACaQ,
QQQ and VPTQ (the last three never applied it at all), and
normalize_fallbackdroppedsmooth.1. The problem
1a.
masked_fillconsumers got a float mask (#4121 item 1)AWQProcessor._token_row_replay_kwargs(gptqmodel/looper/awq_processor.py:1439)decided the replay mask's form from the captured rank alone:
TeleChat2QModel.awq_module_replay_inputs(
gptqmodel/models/definitions/telechat2.py:37) only supplies its own mask whenkwargs.get("attention_mask") is None, so the float grid went straight into theremote attention's
masked_fill:The captured grid for that model is a bool
[1, 1, S, S]whoseTruemarks amasked key (
torch.ones(S, S).triu(1), sumS*(S-1)/2), i.e. the oppositeof the Hugging Face keep convention. So the form and the polarity both have to
be preserved.
1b. Real padded masks never recovered the document grid (#4125 item 4)
For a real right-padded Hugging Face bool mask, a padding query row still
attends to the real keys (only padding keys are masked), so
any(dim=-1)istrue for every row:
keep_sum = B * Swhile the capture holds only the realrows, the check at
awq_processor.py:1397fails, and_token_row_replay_kwargstakes the fallback at:1458— one causal sequenceacross the whole batch, with synthetic positions. The old unit test built a
hand-made mask with fully-masked padding rows, so it never saw this.
1c. Fallback precedence and
smooth(#4121 items 4 and 5)clone_gptq_config_for_moduleapplied the override and then overwrote it(
gptq_processor.py:182on main):The looper always passes
quantize_config.fallback(stage_subset.py:686->module_looper.py:2278), so the override never survived.MacaqProcessor(
macaq_processor.py:114),QQQProcessor(qqq_processor.py:141) andVPTQProcessor(vptq_processor.py:101) had the same line and never appliedthe override at all.
utils/fallback.py:26-31forwarded onlystrategyandthresholdto_normalize_fallback, so a dict override lost both its ownsmoothand theinherited one.
2. The fix
2a. Mask form and polarity
AWQProcessor._captured_mask_form(awq_processor.py:1354) classifies thecaptured grid and the replay rebuilds it in the same form:
[B, 1, S, S](eager)finfo.minon masked cellsTrue= attended (SDPA)True= attendedTrue= masked (TeleChat2)True= masked[B, S]keep mask[1, retained]keep maskThe polarity is read from the grid diagonal (
Trueon the diagonal = keepconvention), and
_align_module_kwargs_to_input(:1566) now leaves a maskthat already matches the packed length untouched instead of repacking it with
the keep convention.
2b. Keep set from the diagonal
_token_row_source_structure(:1377) normalizes the grid to "True = attended"using the form, then takes
allowed_grid.diagonal(-2, -1). A real token alwaysattends to itself; a padding query row does not. That recovers the document and
position grid for real padded masks.
flowchart TD A["AWQProcessor._token_row_replay_kwargs"] --> B["AWQProcessor._captured_mask_form"] B --> C{"captured form"} C -- additive --> D["float block grid, finfo.min masked"] C -- bool_keep --> E["bool block grid, True attended"] C -- bool_masked --> F["bool block grid, True masked"] C -- planar --> G["1, retained keep mask"] C -- none --> D B --> H["AWQProcessor._token_row_source_structure"] H --> I["keep from the grid diagonal"] I --> J["documents and original positions"] J --> D J --> E J --> F style G fill:#ffe9b3,stroke:#b386002c. Fallback precedence
The processor fallback is the run's default; the per-module override is the
narrowest layer and wins.
flowchart TD A["config fallback<br/>qcfg.fallback"] --> B["normalize_fallback(processor fallback, config)"] B --> C{"dynamic override for this module?"} C -- yes --> D["normalize_fallback(override, processor-under-config)"] C -- no --> E["processor-under-config"] D --> F["task fallback used by the quantizer"] E --> Fnormalize_fallbacknow merges every field, includingsmooth, and anoverride that names a smoother through a
smooth_*/clip_methodalias replacesthe inherited one.
The same diagrams are committed in
docs/awq-calibration-aggregation.mdanddocs/awq-scale-search-memory.md.3. Failure and ambiguity contract
masked_fillbool gridRuntimeErrorTrue= maskedbatch_size>1bool gridany(dim=-1), structure never recovered[B, S]captured maskdynamicfallback override in a real rundynamicfallback in QQQ/VPTQ/MACaQnormalize_fallback({...}, default)withsmoothsmoothdropped4. Validation
Item 1 — TeleChat2 (real quantize, tiny remote-code fixture, CPU)
Before (
origin/main13ee428f, pristine worktree):After:
Item 4 — the resolved fallback in a real quantize
tests/test_fallback.py::test_dynamic_fallback_override_survives_a_real_quantizequantizes a one-layer Llama on CPU with
dynamic={"+:.*\\.mlp\\.down_proj$": {"fallback": {"strategy": "median", "threshold": 1e9}}}and records what the looper actually passed to
preprocess:mainprocessor_arg=Fallback(RTN, '0.5%')->resolved=Fallback(RTN, '0.5%')processor_arg=Fallback(RTN, '0.5%')->resolved=Fallback(MEDIAN, 1000000000.0)Siblings (
gate_proj,q_proj, ...) keepFallback(RTN, '0.5%')on both.tests/test_fallback.py::test_processor_merges_the_processor_fallback_under_the_overridecovers GPTQ and QQQ at the
preprocess(..., fallback=...)boundary;test_vptq_and_macaq_apply_the_processor_fallback_without_dynamic_overridescovers the other two (their configs reject a per-module
fallbackkey, so onlythe processor fallback can apply).
Item 5 —
smoothtests/test_fallback.py::test_normalize_fallback_merges_every_field_including_smooth:inherited
SmoothMAD(k=2)survives a{"threshold": "3%"}override, anoverride's own
SmoothPercentilereplaces it, and asmooth_percentilealiasalso replaces it. Before:
smooth=Nonein all three cases.Tests run
pytest -q tests/test_telechat2_coverage.py tests/test_fallback.py(CUDA venv, CPU)pytest -q tests/test_awq_weight_mean.py tests/test_awq_scale_search_memory.py tests/test_dynamic.py::test_dynamic_overrides_apply_per_module(ROCm)GPTQMODEL_AWQ_PPL_WIKITEXT=... pytest -q tests/test_awq_variable_length_ppl.py(CUDA, RTX 4090)ruff check gptqmodel docs/eora tests setup.pyThe 12
tests/test_fallback.pyfailures aretest_fallback_near_dead_scale_survives_smoothing_and_packing, which #4121lists as failing on
mainfor everysym=Truenon-RTN case; the same 12 failon
mainin this environment. The 4tests/test_awq_weight_mean.pyfailures(
test_awq_early_layer_completion_releases_all_feature_statex2,test_awq_search_best_scale_coalesces_cpu_activation_replay, and the flakytest_awq_weight_mean_matches_legacy_impl_*timing assertion) also fail onmain.The AWQ
batch_size=4end-to-end PPL intests/test_awq_variable_length_ppl.pymoved from 25.52 to 25.13 onQwen2.5-0.5B (RTN 22.77,
batch_size=1AWQ 22.09 unchanged): the per-documentmask is now actually built for the real padded captures.
Hardware: RTX 4090 (
GPU-1ece7ec2-d88d-9284-93c8-d2578d90ad7e), CUDA 13.0 /torch 2.16.0.dev for the PPL runs; AMD R9700 (gfx1201) via
HIP_VISIBLE_DEVICES=1, ROCm 10.1 / torch 2.16.0.dev for the unit tests; CPUfor the TeleChat2 fixture and the tiny-Llama quantize.
5. Scope
Only
_captured_mask_form,_token_row_source_structure,_token_row_replay_kwargsand_align_module_kwargs_to_inputchanged inawq_processor.py;_get_root_rotaryand the rest of the rotary resolution areuntouched.
gptqmodel/models/loader.py,gptqmodel/utils/hf.py,gptqmodel/models/definitions/andgptqmodel/utils/cpu_features.pyare notmodified.