Repository navigation
Description
Found on main @ c1807f8, ROCm GPU (torch 2.16 rocm), bf16; the sampling code is device-independent.
What is wrong
AWQProcessor._compute_token_row_quotas (gptqmodel/looper/awq_processor.py:1883-1963) chooses the token rows that every dense AWQ module uses for its scale search and clip search. Inside each batch it always takes row 0:
quota == 1->local_indices = torch.zeros(1)(:1955-1956), and theretained_tokens < batch_countbranch does the same (:1908-1920);quota > 1->arange(quota) * (length - 1) // (quota - 1), which always includes row 0 and the last row (:1958-1961).
The budget is max(largest_batch, contributing_batches) (:1823). One row is reserved per batch and only the rest is shared out by length. So when the number of calibration batches is close to or above the longest batch's token count, almost every batch gets quota == 1. The whole AWQ sample then collapses onto position 0 of each document, which is the BOS / attention-sink token.
At position 0 the hidden state is the same for every document (BOS attends only to itself). Every module of every layer therefore searches its scales and clip ranges on hundreds of copies of a single activation vector. Nothing warns about it, and the checkpoint saves and loads normally.
#4176 documented and accepted a moderate BOS over-representation (12.5% of rows on 128 long docs). This issue is the degenerate end of the same selection rule. It is reached with ordinary settings: many short samples at batch_size=1. Typical cases are nsamples >= max_length, or chat/instruction calibration sets of a few hundred short rows. The behaviour predates #5175: _pack_token_rows used the same row-0 rule.
Measured
I instrumented the provenance kept by _layer_input_features (layer 0, every dense module), on Llama-3.2-1B-Instruct with C4 rows:
| calibration | kept rows | kept rows at doc position 0 | corpus share of position 0 |
|---|---|---|---|
| 128 docs <= 2500 chars, bs=1 | 846 | 15.1% | 0.35% |
| 300 docs <= 1000 chars, bs=1 | 383 | 78.3% | 0.59% |
| 512 docs 300-600 chars, bs=1 | 512 | 100% (1 unique position) | 0.87% |
| 64 docs, bs=4, left pad | 2331 | 0.7% | 0.35% |
End to end on Llama-3.2-1B-Instruct, AWQConfig(bits=4, group_size=128), bf16: quantize -> save -> reload -> wikitext-2 PPL (80 x 512 windows; FP16 18.97, RTN 24.49):
| calibration | PPL |
|---|---|
| 128 C4 docs <= 2500 chars, bs=1 | 21.80 |
| 128 C4 docs 300-600 chars, bs=1 | 21.96 |
| 512 C4 docs 300-600 chars, bs=1 (default) | 91.66 |
| same 512 docs, batch_size=4 | 21.74 |
same 512 docs, bs=1, same quotas but bin-centre rows (floor((i + 0.5) * L / q), middle row when q == 1) |
22.46 |
Adding more (shorter) calibration documents makes AWQ about 4x worse than RTN. Changing only which row each batch contributes (the last row of the table) brings the PPL back to 22.46, so the row-0 choice causes the collapse, not the quota.
Repro
import torch
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization.config import AWQConfig
from gptqmodel.looper import awq_processor as AP
orig = AP.AWQProcessor._layer_input_features
def spy(self, state):
feats = orig(self, state)
e = self.tasks["self_attn.q_proj"]
rows = [r for _, r in e["provenance"]] # bs=1, no padding: row index == position
print("kept", len(rows), "at position 0:", sum(r == 0 for r in rows))
raise SystemExit
AP.AWQProcessor._layer_input_features = spy
texts = [t for t in c4_texts if len(t) >= 300][:512]
texts = [t[:600] for t in texts] # ~80-170 tokens each
m = GPTQModel.load("meta-llama/Llama-3.2-1B-Instruct", AWQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=texts, batch_size=1))
# -> kept 512 at position 0: 512Suggested fix
- Never pin row 0. Pick stratified rows inside each batch, for example bin centres
floor((i + 0.5) * L / q)(the middle row whenq == 1), or a deterministic seeded offset per batch. Apply this to both thequota == 1andretained_tokens < batch_countbranches. - Optionally raise the budget floor (for example
max(largest_batch, 2 * batches)) so that a run with many short documents does not drop to one row per document. - [BUG][AWQ] Default token-row aggregation samples ~2% of calibration tokens; replay ignores per-layer attention type, Bloom ALiBi and real positions #4176's measurement (bin-centre sampling at 128 long documents regressed slightly) could still hold for the moderate regime. If so, keep the current rule only when
quota >= 2, but row 0 must not be the only row a batch contributes.
Test that should have caught it
tests/test_awq_token_rows_bounded_capture_5137.py checks the bound and per-quarter proportionality, never the position of the kept rows. A test with 64 batches of length 40 (budget 64, quota 1 each) that asserts kept rows are not all at in-batch index 0 fails today.
Severity
High ([QUALITY]). The quality loss is silent and large (PPL 21.8 -> 91.7, far worse than RTN) on a plain dense model with default AWQConfig and batch_size=1. It triggers as soon as the number of calibration rows reaches the longest row's token count. batch_size>1 (larger per-batch rows) hides it.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Two more data points from the same setup (ROCm, bf16, wikitext-2 80 x 512, quantize -> save -> reload):
exclude_attention_sinks=Trueis not a workaround. That run (Llama, 512 short docs) crashes instead; I am filing it separately.quota == 1/retained_tokens < batch_countcase, or raise the budget floor, rather than change thequota >= 2rule.🤖 Generated with Claude Code
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5289
AWQ _compute_token_row_quotas: pick stratified bin-centre rows instead of pinning row 0, in the quota==1, retained<batch_count and quota>1 branches, plus a kept-position regression test.
fix(awq): keep the batch centre, not row 0, for single-row token quot…
Port every supported model onto the Transformers 5.23 ABI; never patc…