Skip to content

fix(gptq): mask attention-sink position only for a real BOS token (#4459) - #4526

Merged
Qubitium merged 1 commit into
mainfrom
fix/sink-bos-check-4459
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/sink-bos-check-4459

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4459. exclude_attention_sinks unconditionally dropped position 0, so on BOS-less tokenizers (Qwen2.5/Qwen3) it removed a real text token and could make GPTQ worse than RTN.

Position 0 is now masked only when it is actually the tokenizer's BOS token, resolved per sample from the prepared calibration batch's input_ids/attention_mask:

Case Position 0 Warning
BOS present dropped for those samples only none
BOS absent (no BOS id, or row starts with text) kept one-time warning when the tokenizer has no BOS id
ids/metadata unknown kept one-time warning naming the reason
flag off kept (historical path) none

The per-sample flags are threaded through the capture hook into GPTQ.add_batch/process_batch; the keyword is only passed when a mask exists so GPTAQ/FOEM override signatures are unaffected. Docs updated.

Validation

  • pytest tests/test_gptq.py tests/models/model_test.py -q → 82 passed, 3 skipped
  • attention-sink/BOS subset → 12 passed
  • ruff check clean

Residual: no new PPL matrix was measured here (the doc's Llama-3.2-1B numbers are pre-existing from #4393); integration model tests requiring downloads/GPU were not run.

Resolves #4459.

)

`exclude_attention_sinks` dropped position 0 of every calibration sequence
unconditionally. Qwen2.5/Qwen3 tokenizers add no BOS, so that removed the
first real text token and could make GPTQ worse than RTN.

Resolve the decision from the prepared calibration `input_ids`: drop position
0 only when the sample's first unpadded token is the tokenizer's BOS id. When
the tokenizer has no BOS, the batch has no usable ids, or the shape is
unusable, keep every row and emit a one-time warning naming the reason. The
hook now passes the per-sample flags (aligned with the batch keep mask) down
to `GPTQ.add_batch`/`process_batch`, and per-module telemetry reports the
number of rows actually dropped and batches skipped. Flag-off behavior is
unchanged: no mask is computed and `process_batch` keeps its historical call
shape.
@Qubitium
Qubitium merged commit d82fd9e into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/sink-bos-check-4459 branch November 17, 2026 01:00
Qubitium added a commit that referenced this pull request Nov 17, 2026
…4568) (#4610)

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