Skip to content

[BUG][AWQ] Default token-row aggregation samples ~2% of calibration tokens; replay ignores per-layer attention type, Bloom ALiBi and real positions #4176

Closed

Description

@Qubitium

Severity: medium — measurable PPL loss on every AWQ run; wrong replay context on some architectures
Version: 7.11.0 @ 6c3421c. token_rows is the default for every module (models/base.py:~4946).

1. Token budget is tiny and noisy

  • Where: looper/awq_processor.py:1110-1137 (_token_row_budget) returns min(raw_tokens, max(largest_batch, n_batches)); _pack_token_rows is at :1258-1266.
  • Example: 128 C4 docs (≤1024 tokens, bs=1) keep 1024 of 45,112 rows (logged raw_tokens=45112 retained_tokens=1024). Those rows drive x_mean, the scale grid, the replay loss and the clip search.
  • Sampling bias: even spacing always takes row 0 (BOS) and the last row of each document. BOS ends up as 12.5% of retained rows vs 0.28% of the corpus. Layer-1 down_proj channel x_mean is 145 on packed rows vs 3.3 on the full data, and searched scales differ by up to 4×.

Llama-3.2-1B-Instruct, W4 g128 asym GEMM, wikitext-2 PPL, single runs:

Run PPL
FP16 12.634
RTN 15.882
AutoAWQ reference checkpoint (different calibration set) 13.790
HEAD default 14.064
HEAD, budget raised to 8192 rows 13.890
HEAD, same 1024 budget, bin-centre sampling 14.398

Suggested fix: raise the default budget substantially (or make it a config field with a sensible floor, e.g. ≥8k rows), and stratify sampling so BOS / document ends aren't over-represented. Alternatively compute x_mean on all rows and subsample only for the replay loss.

2. Mixed sliding/full attention models replay every layer with layer 0's mask type

  • _token_row_replay_kwargs (awq_processor.py:1548-1673) reads only inputs_cache.attention_masks. It never uses _gptqmodel_layer_type_replay_kwargs, unlike the forward executor (base.py:~3850).
  • On gemma-3-1b-it, layer 5 (full_attention) has a scale-search mask with 0 allowed pairs at distance ≥512, identical to the sliding layers.
  • The same applies to OLMo 3 and other mixed-attention models.

3. Bloom attention never gets AWQ with variable-length calibration

  • definitions/bloom.py:56-67 requires a captured alibi of shape (batch*heads, 1, seq). The packed [1, N, H] replay only matches by coincidence, and in that case a stale ALiBi is accepted silently.
  • With default fallback it logs using configured plain-quantization fallback for ['self_attention.query_key_value'] ... alibi.
  • With fallback=None, quantize() raises _AWQScaleGroupError.
  • The existing CPU test passes only because both of its samples are length 8.

4. Packed replay uses synthetic positions for rotary

  • For attention modules that take position_embeddings but not position_ids (HF Llama / Qwen3 / Gemma), _sanitize_kwargs (:~3943) drops position_ids, and _prepare_module_forward (:3519-3533) rebuilds rotary from torch.arange(N).
  • The retained rows' real positions were [0, 51, 102, ...].
  • This contradicts docs/awq-calibration-aggregation.md ("evaluated at the real positions"). PPL impact on Llama-1B is within noise (14.12 with a fix).

5. All-NaN loss grid raises a bare Exception()

At awq_processor.py:3348-3351, a bare Exception with no message bypasses the _AWQScaleGroupError fallback contract, so one fp16 NaN replay aborts the whole run.

Also noted (low)

  • quantization/awq/.../scale.py:330-336: the offset-gain renormalisation scales / peak reaches 7.6e-7 on Gemma3. It is fine in bf16 but can underflow in fp16 (not run).
  • looper/gsq_training_awq.py:44,63 hard-codes arange // qcfg.group_size. Per-module dynamic group sizes are ignored, and group_size=-1 gives negative ids.

Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions