Repository navigation
Description
Found on main @ c03416c, RTX 4090 (CUDA 13.2, torch 2.15), bf16.
What is wrong
#5289 (fix of #5265) changed the single-row token quota in AWQProcessor._compute_token_row_quotas (gptqmodel/looper/awq_processor.py:2036 and :2075, via _stratified_token_row at :1984). A batch that keeps one row now always keeps its centre row instead of row 0. That fixes the Llama case from #5265 (91.7 -> 22.5). It moves the collapse to the other end for Qwen2.5 (no BOS token), which #5265's own follow-up comment reported (68.86 at bs=1 vs 24.79 at bs=4):
- In the many-short-documents regime (
batch_size=1, number of documents >= longest document), every batch getsquota == 1. The kept sample now contains zero position-0 (attention-sink) rows, where it used to contain only those rows. - Qwen2.5's first-token activation has the large outlier channels. With no sink row in the sample, the AWQ scale search never sees those channels and picks scales that hurt them. The result is still worse than plain RTN.
The new tests (tests/test_awq_token_row_position_5265.py) only assert that no single-row batch keeps position 0, and the PR checked only Llama end to end.
Measurements
Same harness for every row: AWQConfig(bits=4, group_size=128), bf16, quantize -> save -> reload -> wikitext-2 PPL (80 x 512 windows). Calibration is 512 C4 documents >= 300 chars, each cut to 600 chars (~80-170 tokens), the same set as #5265. "Sink rows" are the kept rows at document position 0 (layer 0, self_attn.q_proj provenance).
| model | calibration / row rule | sink rows kept | PPL |
|---|---|---|---|
| Qwen2.5-0.5B-Instruct | bs=1, main (centre row) | 0 / 512 | 28.01 |
| Qwen2.5-0.5B-Instruct | bs=1, quota-1 row = random row >= 1 (patched) | 0 / 512 | 27.05 |
| Qwen2.5-0.5B-Instruct | bs=1, quota-1 row = random row incl. 0 (patched) | ~4 / 512 | 25.71 |
| Qwen2.5-0.5B-Instruct | bs=1, row 0 for every 8th quota-1 batch, else centre (patched) | 64 / 512 | 24.02 |
| Qwen2.5-0.5B-Instruct | bs=4, main | 24.92 | |
| Qwen2.5-0.5B-Instruct | RTN 4-bit g128 (reference) | 24.82 | |
| Qwen2.5-0.5B-Instruct | bs=1, before #5289 (ROCm, from #5265) | 512 / 512 | 68.86 |
| Llama-3.2-1B-Instruct | bs=1, main (centre row) | 0 / 512 | 22.48 |
| Llama-3.2-1B-Instruct | bs=1, row 0 for every 8th quota-1 batch (patched) | 64 / 512 | 21.98 |
| Llama-3.2-1B-Instruct | bs=4, main | 21.89 |
Both extremes are bad on Qwen: all sink rows (68.9) and no sink rows (28.0). A sample with about the corpus's own share of sink rows (bs=4 keeps row 0 of each 4-document batch, about 19%; the default 128 long-document run keeps 15%, which #4176 accepted) is at or below RTN. The random-row variants show that the gap is not about positional diversity: a random non-zero row is as bad as the centre row (27.05 vs 28.01).
Repro
import gzip, json, torch
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization.config import AWQConfig
texts = []
for line in gzip.open("c4-train.00000-of-01024.json.gz", "rt"):
t = json.loads(line)["text"]
if len(t) >= 300:
texts.append(t[:600])
if len(texts) == 512:
break
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", AWQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=texts, batch_size=1))
m.save("out") # reload + wikitext-2 PPL: 28.01 (bs=4: 24.92, RTN: 24.82)The patched rows replace AWQProcessor._stratified_token_row for quota == 1 only. For example, "every 8th" is:
def _st(quota, length): # called once per quota-1 batch, in batch order
cnt[0] += 1
return torch.tensor([0 if cnt[0] % 8 == 1 else length // 2])Suggested fix
Do not decide all-or-nothing on the sink row. Options:
- In the
quota == 1andretained_tokens < batch_countbranches, keep row 0 for a deterministic fraction of batches (about1 / mean_length, or a fixed 1/8 as measured above) and the bin centre for the rest. - Or raise the budget floor to
2 * contributing_batchesso that single-row quotas disappear. Thequota >= 2rule (row 0 plus evenly spaced rows) behaves well: Llama with 45% sink rows at quota 2 measured 21.80, against 22.13 for bin centres everywhere.
Test that should have caught it
tests/test_awq_token_row_position_5265.py::test_no_single_row_batch_contributes_position_zero encodes "never row 0", which is the regression. A test should bound the sink share from both sides (for example, between 1% and 50% of kept rows) on a many-short-batches plan. An end-to-end check should include a BOS-less model (Qwen2.5) at batch_size=1, since #5265's comment already measured it.
Severity
Medium [QUALITY]: silent, and worse than RTN (+13% PPL vs bs=4) on a default AWQConfig with batch_size=1 and many short calibration rows, for Qwen-family models. Llama is only mildly affected.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 19, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5315
Restore a bounded sink share: keep row 0 for 1 in 8 single-row quotas and the bin centre for the rest, in both quota-1 branches, and bound the sink share in the token-row tests.
fix(awq): keep one in eight single-row quotas at the sink position (#…
Port every supported model onto the Transformers 5.23 ABI; never patc…