Repository navigation
fix(gptq): add opt-in attention-sink masking for the calibration Hessian (#4393) - #4440
Merged
Merged
Conversation
…4393) Tokenizers that prepend BOS make the leading position an attention sink: on Llama-3.2-1B its activation norm at layers.1.mlp.down_proj is ~337-680x the median row norm, so that single row contributes 99.0-99.97% of the input Hessian Frobenius norm. GPTQ then optimizes almost entirely for it. Add GPTQConfig.exclude_attention_sinks (default False). When enabled, process_batch drops the first token of every 3-D linear/Conv1D calibration sequence before accumulating H, and the sample count is reduced to match. Flattened routed-expert batches have no sequence axis and are untouched. The flag is serialized in checkpoint meta and round-trips through from_quant_config. QQQConfig rejects it because QQQ has its own capture path. Measured on wikitext-2 (40 articles, one BOS each, 512-token rows): Llama-3.2-1B-Instruct GPTQ off 23.21 -> on 19.51 (RTN 22.06, fp16 18.21). Dropping the last token instead (control) stays at 23.22, so the gain is specific to the attention sink. Default is unchanged because base Llama-3.2-1B (13.39 -> 14.32) and SmolLM2-135M (27.60 -> 28.22) regress slightly; both remain better than RTN. Unit tests assert the masked Hessian equals a float64 X^T X oracle over the retained rows, and that the default and flattened-input paths keep the historical accumulation.
GPTAQ and FOEM override process_batch with their own Hessian/dXXT accumulation, so exclude_attention_sinks would be silently ignored. Reject the combination in GPTQConfig.validate() and cover it with a test.
Qubitium
added a commit
that referenced
this pull request
Nov 16, 2026
…4393) (#4444) Llama-3.2-1B-Instruct's BOS row is an attention sink that holds ~99% of the calibration Hessian (#4393). With the opt-in from #4440 enabled, the slow model test improves on both metrics and passes against its own baselines instead of failing or relying on the stale-baseline native fallback: slow mode, GPTQ 4-bit g128 native bf16 sinks kept sinks excluded gsm8k_platinum_cot acc,num 0.4797 0.4078 0.4127 arc_challenge acc 0.3183 0.3038 0.3063 arc_challenge acc_norm 0.3456 0.3456 0.3456 The previous slow baselines (0.3987 / 0.3234 / 0.3643) no longer matched this eval setup: even the native model scores 0.3183 / 0.3456 on ARC. With sinks kept, arc acc was 93.9% of the stored value (fail) and 95.4% of native. - model_test: add EXCLUDE_ATTENTION_SINKS (default False); forwarded to the quantize config only when True, so other methods never see the field. - test_llama3_2: enable it and set the slow baselines to the measured sink-excluded quantized scores. Co-authored-by: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…mask (#4393) Move the attention-sink opt-in from `GPTQConfig.exclude_attention_sinks` to the calibration config, `quantize(..., calibration_exclude_attention_sinks=True)` (`CalibrationConfig.exclude_attention_sinks`), and apply it once, in the shared calibration keep-mask, so every calibration method drops the same rows. Rule: every attended BOS token is excluded (the leading one, after left or right padding, and each document-boundary BOS of concatenated calibration). Nothing else is: a tokenizer without a BOS token (Qwen2/2.5/3) keeps every row and its checkpoint is bitwise identical to the default run (#4459). - `LoopProcessor.calibration_keep_mask` edits the padding mask per batch; `_mask_tls.padding_value` keeps the padding-only mask for forward-visible consumers (MoE padding zeroing, NVFP4 amax, EXL3/DeepSeek-V4 router evidence). Token totals and the zero-sample threshold use the retained rows. - Consumers: GPTQ/GPTAQ/FOEM/native capture, QQQ, MACaQ, EXL3 capture, AWQ features and token-row structure, calibrated FP8 GSQ. Natively routed experts and VLM batches whose sequence cannot be placed keep their rows. - VPTQ rejects the option (PPL 4.5-4.7x worse on Llama-3.2-1B/-Instruct); ParoQuant and staged GSQ reject it; `quantize()` rejects a `dynamic[...].exclude_attention_sinks` rule. - Remove the GPTQConfig field and its per-method plumbing from #4440, #4525, #4526 and #4610 (`attention_sink_mask_supported`, factory/dynamic/load sanitizers, `GPTQ._attention_sink_row_keep`, `attention_sink_bos_flags`). `GPTQConfig(exclude_attention_sinks=...)` now raises `TypeError`. - Supersede the GPTQ-only #4568 fix (#4610): the BOS positions are resolved from the prepared `input_ids` and `tokenizer.bos_token_id` when the processor is built, before `release_calibration_dataset()`, for every calibration method; #4610's per-batch decision cache in `GPTQProcessor`, its dynamic gating and its Hessian-share signature field are removed. - Provenance: `meta.calibration_exclude_attention_sinks: true` only when on. - test_llama3_2: forward the switch through the new kwarg and re-baseline the slow metrics for the new rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…mask (#4393) (#4663) * feat(calibration): exclude attention sinks in the shared calibration mask (#4393) Move the attention-sink opt-in from `GPTQConfig.exclude_attention_sinks` to the calibration config, `quantize(..., calibration_exclude_attention_sinks=True)` (`CalibrationConfig.exclude_attention_sinks`), and apply it once, in the shared calibration keep-mask, so every calibration method drops the same rows. Rule: every attended BOS token is excluded (the leading one, after left or right padding, and each document-boundary BOS of concatenated calibration). Nothing else is: a tokenizer without a BOS token (Qwen2/2.5/3) keeps every row and its checkpoint is bitwise identical to the default run (#4459). - `LoopProcessor.calibration_keep_mask` edits the padding mask per batch; `_mask_tls.padding_value` keeps the padding-only mask for forward-visible consumers (MoE padding zeroing, NVFP4 amax, EXL3/DeepSeek-V4 router evidence). Token totals and the zero-sample threshold use the retained rows. - Consumers: GPTQ/GPTAQ/FOEM/native capture, QQQ, MACaQ, EXL3 capture, AWQ features and token-row structure, calibrated FP8 GSQ. Natively routed experts and VLM batches whose sequence cannot be placed keep their rows. - VPTQ rejects the option (PPL 4.5-4.7x worse on Llama-3.2-1B/-Instruct); ParoQuant and staged GSQ reject it; `quantize()` rejects a `dynamic[...].exclude_attention_sinks` rule. - Remove the GPTQConfig field and its per-method plumbing from #4440, #4525, #4526 and #4610 (`attention_sink_mask_supported`, factory/dynamic/load sanitizers, `GPTQ._attention_sink_row_keep`, `attention_sink_bos_flags`). `GPTQConfig(exclude_attention_sinks=...)` now raises `TypeError`. - Supersede the GPTQ-only #4568 fix (#4610): the BOS positions are resolved from the prepared `input_ids` and `tokenizer.bos_token_id` when the processor is built, before `release_calibration_dataset()`, for every calibration method; #4610's per-batch decision cache in `GPTQProcessor`, its dynamic gating and its Hessian-share signature field are removed. - Provenance: `meta.calibration_exclude_attention_sinks: true` only when on. - test_llama3_2: forward the switch through the new kwarg and re-baseline the slow metrics for the new rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(gptq): keep process_batch signature compatible with its overrides --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Calibration rows that begin with a BOS token make position 0 an attention sink: on Llama-3.2-1B the leading activation norm at
layers.1.mlp.down_projis ~337-680x the median row norm, so that single row contributes 99.0-99.97% of the input Hessian Frobenius norm. GPTQ then optimizes almost entirely for the sink row and gets worse than RTN on ordinary tokens (issue #4393).This adds an explicit, opt-in
GPTQConfig.exclude_attention_sinksthat drops the first token of every 3-D calibration sequence before accumulatingH, soHandnsamplesdescribe the same rows. Flattened routed-expert batches have no sequence axis and are left untouched. Default is unchanged.Addresses #4393.
What Changed
config.py: newexclude_attention_sinks: bool = False(help text, bool validation,metaserialization + factory reload).QQQConfigrejects it (QQQ has its own capture path), andGPTQConfig.validate()rejects it together withgptaq/foembecause those methods overrideprocess_batchand would silently ignore it.gptq.py:_attention_sink_row_keep()builds a(batch, seq)keep-mask fornn.Linear/Conv1D3-D inputs;process_batch()applies it before the Hessian GEMM.docs/quantization-guide.md: documents the field, the default, and the measured effect.tests/test_gptq.py: maskedHequals a float64X^T Xoracle over retained rows; the default and flattened-input paths keep the historical accumulation; the GPTAQ/FOEM and QQQ combinations are rejected.Measured evidence
Per-token Hessian at
layers.1.mlp.down_proj(32 wikitext-2 train articles, 512 tokens, one BOS each):Wikitext-2 ppl (40 test articles, one BOS each, 512-token rows, 17,566 predicted tokens):
Control on Instruct: enabling the flag but dropping the last token instead stays at 23.22, so the 16% gain is specific to the leading sink, not to removing an arbitrary row. With the flag on, GPTQ <= RTN on all three models.
Default stays off: base Llama and SmolLM2 regress slightly (both still beat RTN), so default-on is not strictly better and the historical Hessian is preserved.
Tests
PYTHONPATH=/root/work-4393 /root/venv/bin/python -m pytest tests/test_gptq.py -q 72 passed, 3 skipped PYTHONPATH=/root/work-4393 /root/venv/bin/python -m pytest tests/test_hessian_fallback_contracts.py -q 13 passed PYTHONPATH=/root/work-4393 /root/venv/bin/python -m pytest \ tests/test_config_serialization_roundtrip_4201.py tests/test_qqq_config.py -q 32 passed /root/venv/bin/python -m ruff check gptqmodel/quantization/config.py gptqmodel/quantization/gptq.py tests/test_gptq.py All checks passed!Not executed: the issue's exact 63.09-vs-15.90 gap did not reproduce on current main (base GPTQ off measured 13.39, already better than RTN 15.75), though the 99.97% BOS Hessian dominance does. Gated
meta-llama/*checkpoints were not downloadable (no HF token);unsloth/Llama-3.2-1B{,-Instruct}and cached SmolLM2-135M were used. Reload usedbackend="gptq_torch"because Marlin JIT needsCUDA_HOME(unset here).Logic Flow Documentation
The new flag is a calibration-only opt-in with a single decision point (
_attention_sink_row_keep) and an unchanged default path; the mechanism, the rejected combinations and the measured effect are documented indocs/quantization-guide.md. No existing decision mechanism or selection order changed.Review Requirements