Repository navigation
feat(calibration): exclude attention sinks in the shared calibration mask (#4393) - #4663
Merged
Merged
Conversation
…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
force-pushed
the
feat/calibration-attention-sinks
branch
from
November 17, 2026 10:13
820d513 to
25ab7c3
Compare
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…tion kwargs (#4393) (#4724) `quantize()`, `requantize()` and `GPTQModel.adapter.generate()` take every calibration choice in one frozen `CalibrationConfig`, now the public class in `gptqmodel/quantization/config.py` (exported from `gptqmodel` and `gptqmodel.quantization`). The looper processors use the same class; the internal copy in `looper/loop_processor.py` is gone. No backward-compatibility path: a bare dataset, any removed keyword, or an old positional call raises `TypeError`. quantize(self, calibration: Optional[CalibrationConfig] = None, *, tokenizer=None, backend=BACKEND.AUTO, adapter=None, embed_quant_config=None, embed_quant_mode=None, checkpoint=None, fuse=None) - Fields and defaults (the previous quantize() defaults): dataset=None, concat_size=None, sort="desc", batch_size=1, min_length=10, concat_separator=None, exclude_attention_sinks=False, adapter_dataset=None. `__post_init__` validates types and values (sort in asc/desc/shuffle/None, positive ints, non-negative min_length, bool sink switch, no bare string). - Removed kwargs: calibration_concat_size, calibration_sort, batch_size, calibration_data_min_length, calibration_concat_separator, calibration_exclude_attention_sinks, adapter_calibration_dataset (quantize/ requantize) and calibration_dataset* / batch_size / calibration_concat_separator (adapter.generate). Everything after `calibration` is keyword-only. - `adapter_dataset` is a field, not a second config: the EoRA pass has always reused the main pass's preparation policy and fell back to the main samples. It now fails closed without a Lora adapter instead of being ignored. - `tokenizer=` stays a quantize() argument: it replaces the model tokenizer that save() writes and generate() uses, not only calibration tokenization. - `prepare_dataset` is an init=False field set only by `CalibrationConfig.bind()`; `LoopProcessor` forwards `min_length` itself, replacing the functools.partial and `BaseQModel._build_calibration_config`. quantize() rejects a pre-bound config. - Staged GSQ, norm tuning and post-quantization EoRA read the same object and reject the fields they cannot apply. Provenance (`meta.calibration_exclude_ attention_sinks`) is unchanged, now sourced from the dataclass. - adapter.generate() now defaults to sort="desc" like quantize() (was None). - concat_size=0 is rejected; None disables packing (call sites updated). - GPTQ/GPTAQ/FOEM `process_batch(inp, batch_index=None) -> Tuple[int, Optional[Tensor], device]` share one signature; GPTQ.add_batch forwards batch_index (code-quality review on #4663). - Update every caller: package, scripts, optimize/, tests, README and docs; add docs/calibration-config.md (flow, before/after, failure paths). - Test stubs for `ModuleLooper._set_processor_mask` accept the `padding_mask` argument the sink change added (forward-executor parallel/shared-KV and stage-module tests failed on it). Tests: tests/test_calibration_config.py (validation, signatures, TypeError for every removed kwarg and a bare dataset, tiny-Llama quantize that records the exact prepare_dataset arguments, sink provenance through save/reload, EoRA adapter samples, weight-only without calibration); tests/test_gptaq_foem_multigpu.py (process_batch signature parity, GPTQ add_batch Hessian vs float64 oracle). Includes the GPTQ/GPTAQ/FOEM process_batch signature fix from the #4663 review (discussion_r4597507445). 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.
Moves attention-sink exclusion (#4393) from a GPTQ-only config field to the calibration config, and applies it once in the shared calibration keep-mask so every calibration-based method drops the same rows. Default stays off. With the option off, checkpoints are bitwise identical to main.
API (no compatibility layer)
quantize(..., calibration_exclude_attention_sinks=True)→CalibrationConfig.exclude_attention_sinks.GPTQConfig.exclude_attention_sinksand its per-method plumbing from fix(gptq): add opt-in attention-sink masking for the calibration Hessian (#4393) #4440 / fix(config): reject exclude_attention_sinks on paths that ignore it (#4447) #4525 / fix(gptq): mask attention-sink position only for a real BOS token (#4459) #4526 / fix(gptq): retain BOS sink decisions after the calibration dataset is released (#4568) #4610 (attention_sink_mask_supported, factory/dynamic/load sanitizers,GPTQ._attention_sink_row_keep,attention_sink_bos_flags).GPTQConfig(exclude_attention_sinks=...)now raisesTypeError, and adynamic[...].exclude_attention_sinksrule is rejected.meta.calibration_exclude_attention_sinks: trueis written only when the option is on.Rule
Every attended BOS token is excluded: the leading one after left or right padding, and every document-boundary BOS inside concatenated calibration windows. Nothing else is excluded, so a tokenizer without a BOS token (Qwen2/2.5/3) keeps every row and its checkpoint is bitwise identical to the default (#4459).
input_idsandtokenizer.bos_token_idwhen the processor is built, not in a hook after the looper has released the dataset. That supersedes the [BUG] exclude_attention_sinks is a silent no-op since #4526: BOS lookup reads processor.calibration_dataset, which the looper deletes before the layer loop (Llama-3.2-1B PPL 22.44 -> 34.82) #4568/fix(gptq): retain BOS sink decisions after the calibration dataset is released (#4568) #4610 lookup.input_idskeep their rows.Coverage
LoopProcessor.calibration_keep_maskapplies the rule per batch. Forward-visible consumers keep a padding-only mask (_mask_tls.padding_value) and are unaffected: MoE padding zeroing, NVFP4 amax, and EXL3/DeepSeek-V4 router evidence. Token totals and the zero-sample threshold count only retained rows.Measured effect: neutral to slightly negative on
test_llama3_2(Llama-3.2-1B-Instruct, GPTQ 4-bit, concat 2048, current main)test_llama3_2'sEXCLUDE_ATTENTION_SINKS = True(from test(llama3_2): exclude attention sinks and refresh slow baselines (#4393) #4444) and re-baselines the slow metrics to the measured sinks-excluded values. Given the table above, setting it back toFalsewith the sinks-off baselines (0.3871 / 0.3183 / 0.3524) is the better choice for this test. Happy to switch it in this PR.Validation (RTX 4090)
tests/test_calibration_attention_sinks.py(new): 29 passed. Covers:quantize()kwarg and meta round trip.tests/test_gptq.pyandtests/test_attention_sink_config_coverage_4447.pyare removed with the API they tested.test_llama3_2, sinks on: slow passed (100.0% / 100.0% / 100.0% of the new baselines, no native-baseline fallback); fast passed (100.7% / 100.3% / 100.0%).docs/calibration-attention-sinks.md; updateddocs/quantization-guide.md,docs/README.mdanddocs/awq-calibration-aggregation.md.🤖 Generated with Claude Code