Repository navigation
fix(gptq): cap sink-row Hessian contributions when desc_act disables act_group_aware (#4742) - #4909
Merged
Merged
Conversation
…act_group_aware (#4742) `desc_act=True` switches `act_group_aware` off, and with it the per-group scale protection that keeps a handful of massive-activation ("attention sink") calibration rows from dominating `X^T X`. On Llama-3.1-8B the BOS and leading-delimiter rows then own the largest Hessian diagonal, `desc_act` quantizes those columns first with a tiny `Hinv[i, i]`, and the error saturates every column correlated with the sink: `layers.1.mlp.down_proj` columns come out at rel err ~5 and 10/160 wikitext windows reach PPL 800-12000 (PPL 11.62 vs RTN 10.22). Cap each calibration row's norm at `min(p99.9, N x median)` before `X^T X`, with `N = HessianConfig.sink_row_cap_median_multiple` (default 4.0, 0/None disables). The cap keeps the sink direction but bounds its weight, so the columns correlated with it are no longer ordered first against a degenerate `Hinv[i, i]`. It applies only when `desc_act` has disabled `act_group_aware`; the default GPTQ path keeps the existing fast path and is bit-for-bit unchanged. The setting is part of the serialized Hessian meta and of the shared-input Hessian capture signature. Also document the mechanism and the cap in the quantization guide, expand the auto-disable warning to name the sink risk, `exclude_attention_sinks` and the new knob, and re-anchor the contract refs shifted by the new code. Tests: tests/test_descact_sink_4742.py (7 new CPU-only tests) fail 7/7 on main and pass 7/7 here.
This was referenced Nov 17, 2026
sLaffey
pushed a commit
to sLaffey/GPTQModel
that referenced
this pull request
Nov 18, 2026
ModelCloud#4976) `resolve_sink_row_cap_scale` ran on every `add_batch` of every module when `desc_act=True`, and it read the host four times per call: `bool(isfinite(norms).all())`, `bool(isfinite(threshold))`, `float(threshold)` and `bool((scale >= 1).all())`. `add_batch` runs inside the layer forward hooks, so each read drained the CUDA queue mid-calibration. When a cap applied it also left the single fp32 `X^T X` GEMM for the leased chunk-workspace path (`chunk_size = rows`). Compute the whole cap decision with tensor ops and fold the per-row scale into the existing fp32 fast path: * `resolve_sink_row_cap_threshold` derives `min(p99.9, N x median)` from one device sort of the row norms and turns a non-finite/non-positive threshold (where the old code returned `None`) into `+inf` through `torch.where`; * `_sink_row_cap_scale_from_threshold` builds the per-row clamp on device; * `compute_hessian_xtx` multiplies the fp32 staging copy by the scale instead of switching to the chunk lease, so a capped batch keeps the single-GEMM path. The multiply is out of place when the input is already fp32, because `matrix.to(float32)` then returns the caller's (possibly shared) tensor. The cap is still decided per batch, so the Hessian is bitwise identical to the pre-ModelCloud#4950 formula for one batch and for a batch sequence. Caching the threshold on the first batch was tried and rejected: it changed the quantized Qwen2.5-0.5B checkpoint (wikitext PPL 20.78 vs 20.32). `test_descact_cap_sync_4950.py` pins the absence of per-`add_batch` host reads, the fast-path choice, the first-batch cap and the bitwise H. It fails on `main` (16 host reads for 4 batches, no device-only threshold resolver, one chunk lease per capped batch) and passes here. Qwen2.5-0.5B-Instruct, 4-bit/gs128/desc_act, 128 C4 rows, fp16, shared PG506 (two runs each, the box is 80-92 GiB of 98 GiB busy): region "Forward" over 21504 calls 12.2-23.1 s -> 8.5-8.7 s, `quantize()` 79.9-174.8 s -> 45.7-60.2 s, wikitext-2 PPL unchanged at 20.319 (pre-ModelCloud#4909: Forward 2.53 s, PPL 20.278).
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.
Summary
GPTQConfig(bits=4, group_size=128, desc_act=True)on Llama-3.1-8B is worsethan RTN (PPL 11.62 vs 10.22) and 10/160 wikitext windows blow up to PPL
800-12000 whenever the first token after BOS is a delimiter.
desc_act=Trueturns
act_group_awareoff, so the BOS/delimiter sink rows dominate theHessian, the sink columns are ordered first with a tiny
Hinv[i, i], andtheir error is amplified into every correlated column
(
layers.1.mlp.down_projrel err ~5).This caps each calibration row's norm before
X^T Xwhendesc_acthasdisabled
act_group_aware, per the issue's suggested fix. The cap keeps thesink direction but bounds its weight in the Hessian. It is off for the default
act_group_awarepath, which stays bit-for-bit identical.What Changed
HessianConfig.sink_row_cap_median_multiple(default4.0,0/Nonedisables): cap each calibration row's norm at
min(p99.9, N x median)before
X^T X.GPTQ.resolve_sink_row_cap_scale()computes the per-row clamp scalechunk-by-chunk in fp32 (whole-batch threshold, so independent of
HessianConfig.chunk_size);compute_hessian_xtx()applies it only whendesc_act=Trueandact_group_aware=False. The uncapped fast path isuntouched.
meta.hessian(so a reload does not silentlyrestore the default) and included in the shared-input Hessian capture
signature.
desc_act=True automatically disables act_group_awarewarningto name the Llama-3 sink risk,
exclude_attention_sinks, and the new knob.exclude_attention_sinksalternative in
docs/quantization-guide.md; re-anchored the contract refsshifted by the new code.
tests/test_descact_sink_4742.py(7 CPU-only tests, synthetic Hessian).API/behavior: new optional
HessianConfigfield, default on fordesc_act=True. Default GPTQ is unchanged. Not addressed here: enablingdesc_actordering together with group-aware scales (the issue's optionalthird suggestion) and the 8B end-to-end PPL rerun (the checkpoint is not
cached in this environment).
Tests
New regression test, red on
main(6ec93e632-era base) and green on thebranch:
Synthetic Hessian (256 cols, 2 sink rows at 700x, 64 rows) worst column rel
err: uncapped
0.783, capped (default 4x)0.388; dropping the sink rowsentirely is ~
0.31, so the cap recovers most of the protection withoutremoving calibration data.
Real-model check on cached
HuggingFaceTB/SmolLM2-135M(1577 calibrationtokens, first token after BOS forced to
" and "), per-column rel err ofthree
mlp.down_projlayers (worst column; rows clamped by the cap):Mean column error moves <1% and output-relative error is unchanged or lower.
SmolLM2's sink is mild, so this only shows the cap is a no-op-ish, monotone
improvement there; the 8B checkpoint is not cached, so the PPL table above is
from the issue.
Regression runs (CUDA device 5):
The failures are pre-existing and unrelated:
tests/test_quantize_in_session_4381.py::test_rehome_qqq_initializes_torch_cache_after_class_switchfails identically on the base worktree at
origin/main(missingQQQTorchLinear._torch_dropped_checkpoint, [MEM] QQQ on CPU (AUTO QQQTorchLinear) keeps a second packed copy of every weight in _torch_packed_cache next to the unused checkpoint B: QQQ-Llama-3-8B +3.5 GiB host RAM (5.4 -> 9.0 GiB tensors, RSS 4.2 -> 11.2 GB) after the first forward #4805 area).tests/test_serialization.py::TestSerialization::{test_gptq_v1_serialization,test_save_keeps_live_model_inference}fail at
import flash_attn(undefined symbol: c10_cuda_check_implementation) in this environment before any assertion.Lint:
ruff check gptqmodel/quantization/gptq.py gptqmodel/quantization/config.py gptqmodel/looper/gptq_processor.py tests/test_descact_sink_4742.py— all checks passed.Model Support / Module Plan
Not applicable: no model definitions,
MODEL_MAPentries, or module planschange.
Logic Flow Documentation
The change adds a bounded preconditioning step to an existing flow
(
compute_hessian_xtx) rather than replacing a decision mechanism ortensor lifecycle. No new failure/ambiguity contract is introduced: a
non-finite norm, a zero threshold, or an all-ones scale falls back to the
existing uncapped path, and the default configuration keeps the existing
fast path.
docs/quantization-guide.mddocuments the new knob and when itapplies; no new reference page is warranted.
Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, fusion, or packed-storage change. The Hessian math
stays in the existing fp32
quant_blas_backendGEMM; only row scaling isadded, and the new test checks the capped Hessian against a float64
X^T Xof the row-clamped activations.Notes
The cap is a mitigation, not a guarantee; the docs still say to validate a
checkpoint per model, and
CalibrationConfig(exclude_attention_sinks=True)remains available. The 8B PPL rerun from the issue could not be repeated here
because that checkpoint is not in the local HF cache (16 GB download).