Skip to content

fix(gptq): retain BOS sink decisions after the calibration dataset is released (#4568) - #4610

Merged
Qubitium merged 1 commit into
mainfrom
fix/attention-sink-bos-lifetime-4568
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/attention-sink-bos-lifetime-4568

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4568 — a regression from my #4526. exclude_attention_sinks became a silent no-op because the BOS lookup read processor.calibration_dataset, which the looper deletes before the layer loop.

  • The processor now captures the per-sample BOS decisions in a release_calibration_dataset() override before the dataset is deleted and looks them up by batch index in the hook.
  • Gating is per module (g.qcfg) plus _attention_sink_requested() scanning the global flag / tasks / dynamic rules, so a dynamic-only override still captures.
  • exclude_attention_sinks is now part of _hessian_accumulation_settings.

Validation

CPU repro (2 samples × 3 tokens, BOS id 1, releasing the dataset first):

before after
flag-off nsamples 6, dropped 0 same
flag-on, released (looper lifecycle) nsamples 6, dropped 0 — H == flag-off nsamples 4, dropped 2; H != flag-off, equals the BOS-masked oracle
flag-on, dataset retained nsamples 4, dropped 2 same
  • pytest tests/test_gptq.py -k attention_sink tests/test_attention_sink_config_coverage_4447.py -q → 53 passed (including the previously failing dynamic-override test)
  • pytest tests/test_gptq.py tests/test_shared_input_hessian_dedup.py -q → 122 passed, 3 skipped
  • ruff check gptqmodel docs/eora tests setup.py clean

Residual: end-to-end Llama-3.2-1B PPL was not measured here (CPU-only); the fix restores the pre-#4526 decision data.

Resolves #4568.

…4568)

ModuleLooper deletes processor.calibration_dataset before the layer loop,
so the #4526 hook-time BOS lookup always saw a deleted attribute and
exclude_attention_sinks masked nothing.

Resolve one decision per calibration batch in release_calibration_dataset
(while the dataset still exists) and look it up by batch index in the
hook. Gate the lookup on any per-module task/dynamic rule, not only the
global flag, so dynamic overrides mask too. Add exclude_attention_sinks
to the shared-Hessian accumulation signature so a follower with a
different per-module setting does not adopt the leader's Hessian.

Flag-off stays bit-identical, and BOS-less tokenizers still keep their
first real token (#4459). Add regression tests that run the release
lifecycle and assert nsamples/Hessian differ from the flag-off control
and match the BOS-masked reference.
@Qubitium
Qubitium merged commit 5fbaf1e into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/attention-sink-bos-lifetime-4568 branch November 17, 2026 02:29
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant