Skip to content

feat(calibration): exclude attention sinks in the shared calibration mask (#4393) - #4663

Merged
Qubitium merged 2 commits into
mainfrom
feat/calibration-attention-sinks
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
feat/calibration-attention-sinks

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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)

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).

Coverage

LoopProcessor.calibration_keep_mask applies 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.

Method Behaviour
GPTQ, GPTAQ/FOEM (H and dXXT), native capture apply the rule
QQQ, MACaQ, EXL3 capture apply the rule
AWQ (features, token-row structure) applies the rule
calibrated FP8 GSQ applies the rule
VPTQ rejects it (measured PPL 4.5–4.7× worse on Llama-3.2-1B and -Instruct)
ParoQuant, staged GSQ reject it

Measured effect: neutral to slightly negative on test_llama3_2 (Llama-3.2-1B-Instruct, GPTQ 4-bit, concat 2048, current main)

slow mode, same tree sinks off sinks excluded (this rule)
gsm8k_platinum_cot acc,num 0.3871 0.3871
arc_challenge acc 0.3183 0.3114 (−2.2%)
arc_challenge acc_norm 0.3524 0.3498 (−0.7%)
  • With concatenated 2048-token windows, most windows start mid-document. Only document-boundary BOS tokens are dropped, so the effect is small here.
  • Earlier wikitext-PPL runs showed large gains only for Llama-3.2-1B-Instruct GPTQ/QQQ/FOEM, and losses on base Llama and Qwen for most methods. Keep it off by default and enable it per model only after validating.
  • This PR keeps test_llama3_2's EXCLUDE_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 to False with 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:
    • the rule: left/right padding, mid-row BOS, no BOS, no-BOS tokenizer, misaligned VLM;
    • token counts;
    • per-family retained-row Hessian vs an fp64 oracle (GPTQ, GPTAQ/FOEM H and dXXT, QQQ, VPTQ rejection, MACaQ, EXL3 capture, GSQ mask, AWQ features and replay structure);
    • the off path returning the same objects;
    • the old kwarg raising;
    • the quantize() kwarg and meta round trip.
  • The fix(gptq): add opt-in attention-sink masking for the calibration Hessian (#4393) #4440 tests in tests/test_gptq.py and tests/test_attention_sink_config_coverage_4447.py are removed with the API they tested.
  • Off-path bitwise check: Qwen2.5-0.5B gptq4/awq4/qqq4/gptaq4 and Llama-3.2-1B-Instruct gptq4 checkpoints have 0 differing tensors vs main.
  • 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%).
  • Related suites (calibration, gptq, gptaq/foem, qqq, vptq, macaq, exl3, awq) fail in the same places on the branch and on main.
  • Docs: new docs/calibration-attention-sinks.md; updated docs/quantization-guide.md, docs/README.md and docs/awq-calibration-aggregation.md.

🤖 Generated with Claude Code

Comment thread gptqmodel/quantization/gptq.py Resolved
…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
Qubitium force-pushed the feat/calibration-attention-sinks branch from 820d513 to 25ab7c3 Compare November 17, 2026 10:13
@Qubitium
Qubitium merged commit f5dfa09 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the feat/calibration-attention-sinks branch November 17, 2026 10:22
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant