Repository navigation
Description
Found on main @ 4b65923, Radeon AI PRO R9700 (ROCm 10.1, torch 2.16 dev, free-threaded Python 3.14t).
What is wrong
#4526 (fix for #4459) made exclude_attention_sinks decide per sample from the calibration input_ids. The decision reads the batch row from the processor:
gptqmodel/looper/gptq_processor.py:649-697 (_compute_attention_sink_bos_mask)
dataset = getattr(self, "calibration_dataset", None)
row = None
if dataset:
try:
row = dataset[batch_index]
...
if not isinstance(row, Mapping):
return self._attention_sink_skip(batch_size, "no_metadata", ...)In a real model.quantize() run that attribute is always gone by then. ModuleLooper deletes it on every processor right after the input cache is built and before the first layer's forward hooks run (gptqmodel/looper/module_looper.py:2034-2036, processor.release_calibration_dataset() → del self.calibration_dataset, loop_processor.py:1450). So dataset is None for every batch, every batch takes the no_metadata skip, and no row is ever dropped.
The result is that GPTQConfig(exclude_attention_sinks=True) is a silent no-op on every model, including the BOS tokenizers it exists for (Llama-3.x, #4393). Users only get a one-time warning, the calibration batch has no metadata. That is misleading: the batch had BOS metadata, and the processor had already deleted it. The docs (docs/quantization-guide.md:170-187, "On Llama-3.2-1B this option lowered wikitext-2 perplexity from 23.21 to 19.51") and the tests/models/test_llama3_2.py baselines (EXCLUDE_ATTENTION_SINKS = True, refreshed in #4444) describe behaviour that main no longer has.
The new unit tests in tests/test_gptq.py set processor.calibration_dataset = [...] by hand, so they never exercise the looper lifecycle.
Related, same root cause: a per-module dynamic={"+:.*down_proj.*": {"exclude_attention_sinks": True}} (made to apply by #4525) also never masks. The hook gates the BOS lookup on the global self.qcfg.exclude_attention_sinks (gptq_processor.py:726-733), so with global False the module task gets sink_bos_mask=None and GPTQ._attention_sink_row_keep warns calibration token ids are unavailable. tests/test_attention_sink_config_coverage_4447.py::test_dynamic_exclude_attention_sinks_override_is_applied was written before #4526 and now fails on main (assert 8 == (2 * 3); 36 passed, 1 failed on CPU).
Repro (end to end, Llama-3.2-1B-Instruct, 16 C4 rows, batch_size=1)
import gzip, json, torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import config as C
from gptqmodel.quantization.gptq import GPTQ
rec = []
orig = GPTQ.quantize
def q(self, *a, **k):
rec.append((self.name, int(self.nsamples), int(getattr(self, "attention_sink_dropped_rows", 0))))
return orig(self, *a, **k)
GPTQ.quantize = q
texts = []
with gzip.open("c4-train.00000-of-01024.json.gz", "rt") as f:
for line in f:
t = json.loads(line)["text"]
if len(t) >= 400:
texts.append(t[:1500])
if len(texts) >= 16: break
m = GPTQModel.load("meta-llama/Llama-3.2-1B-Instruct",
C.GPTQConfig(bits=4, group_size=128, exclude_attention_sinks=True), dtype=torch.float16)
m.quantize(texts, batch_size=1)
print(set((n, s, d) for n, s, d in rec))main @ 4b65923:
WARN GPTQ: `exclude_attention_sinks` is enabled but the calibration batch has no metadata; position 0 is kept in the calibration Hessian.
{('self_attn.q_proj', 4095, 0), ('mlp.down_proj', 4095, 0), ...} # all 112 modules: 4095 rows, 0 dropped
Same script at ede121c (parent of #4526):
all 112 modules: 4079 rows # 16 rows = one BOS per calibration sample dropped
A debug hook in _compute_attention_sink_bos_mask shows type(self.calibration_dataset) is NoneType for every batch.
PPL impact. Llama-3.2-1B-Instruct, GPTQConfig(bits=4, group_size=128, act_group_aware=False, exclude_attention_sinks=True), 128 C4 calibration rows, fp16, wikitext-2 with 80 x 512 BOS-prefixed windows, quantize -> save -> reload:
| commit | wikitext-2 PPL |
|---|---|
| ede121c (before #4526, sink masked) | 22.44 |
| main 4b65923 (flag set, nothing masked) | 34.82 |
| RTN 4-bit g128 (reference, same eval) | 24.49 |
With the flag set, main is now worse than plain RTN, which is the #4393 failure the option was added to fix.
Suggested fix
Do not depend on calibration_dataset surviving into the layer loop. Compute the per-batch BOS flags once, while the dataset still exists, for example in cache_inputs/receive_input_cache or before release_calibration_dataset(). Store them (one small bool tensor per batch) on the processor or in the InputCache, and look them up by batch index in the hook. Gate the lookup on "any module task has exclude_attention_sinks", not on the global flag, so dynamic overrides work too. Once dynamic masking works, also add exclude_attention_sinks to GPTQProcessor._hessian_accumulation_settings. Otherwise a follower in a q/k/v shared-input group with a different per-module setting adopts the leader's masked or unmasked Hessian. Update the stale #4447 test to pass sink_bos_mask.
Tests that should have caught it
- An end-to-end tiny-model quantize with a BOS tokenizer and
exclude_attention_sinks=Truethat assertsattention_sink_rows_dropped > 0in the quant log. The current unit tests injectcalibration_datasetby hand. tests/test_attention_sink_config_coverage_4447.py::test_dynamic_exclude_attention_sinks_override_is_appliedfails on main today.
Severity
High for users of the option. It is the documented fix for #4393 (GPTQ worse than RTN on Llama-3.2), and since #4526 it silently does nothing. The only signal is a warning whose text points at the calibration data rather than the looper.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Control run on the same setup (Llama-3.2-1B-Instruct, GPTQ 4-bit g128 sym
act_group_aware=False, 128 C4 rows, wikitext-2 80 x 512):exclude_attention_sinks=Trueexclude_attention_sinks=FalseThe PPL with the flag on and off is identical to every printed digit, so the option has no effect on main. Before #4526 (ede121c) the flag gave 22.44.
🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Claimed by an AI agent. Will reproduce on CPU, fix, add a focused regression test, and open a PR.
fix(gptq): capture attention-sink BOS flags before dataset release (#…
feat(calibration): exclude attention sinks in the shared calibration …
feat(calibration): exclude attention sinks in the shared calibration …