Skip to content

[QUALITY] AWQ token-row sampling always takes row 0 of each batch: with many short calibration rows (batches >= longest row) 100% of kept rows are the BOS token - Llama-3.2-1B AWQ PPL 21.8 -> 91.7 (RTN 24.5) #5265

Description

@Qubitium

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 the retained_tokens < batch_count branch 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: 512

Suggested fix

  • Never pin row 0. Pick stratified rows inside each batch, for example bin centres floor((i + 0.5) * L / q) (the middle row when q == 1), or a deterministic seeded offset per batch. Apply this to both the quota == 1 and retained_tokens < batch_count branches.
  • 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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Two more data points from the same setup (ROCm, bf16, wikitext-2 80 x 512, quantize -> save -> reload):

    model / calibration PPL
    Qwen2.5-0.5B-Instruct (no BOS token), 512 C4 docs 300-600 chars, bs=1, default 68.86
    same model and docs, batch_size=4 24.79
    Qwen2.5-0.5B-Instruct RTN 4-bit g128 (reference) 24.82
    Llama-3.2-1B-Instruct, 128 docs <= 2500 chars, bs=1, default rule 21.80
    same, bin-centre rows for every quota 22.60

    🤖 Generated with Claude Code

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-fb5145b84190 finished 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions