Skip to content

fix(awq): keep the batch centre, not row 0, for single-row token quotas (#5265) - #5289

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-token-row-stratified-5265
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-token-row-stratified-5265

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5265.

Problem

AWQProcessor._compute_token_row_quotas pinned row 0 for every single-row
quota (the quota == 1 branch and the retained_tokens < batch_count branch).
Position 0 is the BOS/attention-sink token, whose hidden state is identical for
every document, so a calibration set with many short rows at batch_size=1
collapsed the whole AWQ sample onto one vector. With 512 C4 rows of 300-600
chars that is 100% of the kept rows, and Llama-3.2-1B AWQ PPL goes 21.8 -> 91.7
(plain RTN 24.5).

Change

_stratified_token_row(quota, length) returns the centre of quota equal-width
bins, floor((i + 0.5) * L / q). Both single-row branches use it, so a batch
that contributes one row contributes its middle position instead of the BOS.
Multi-row quotas keep the existing endpoint spacing
(arange(q) * (L-1) // (q-1)), which the issue asks to preserve because bin
centres regressed slightly in the 128-long-document regime (#4176).

_compute_token_row_quotas feeds both the bounded plan
(_token_row_plan_for_module) and _pack_token_rows, so both paths are fixed.

Tests

New tests/test_awq_token_row_position_5265.py:

  • test_single_row_quota_takes_the_batch_centre -- 64 x 40 tokens, budget 64:
    every batch keeps row 20, not row 0 (the issue's case).
  • test_budget_below_batch_count_takes_centres -- budget 2 over 3 batches keeps
    the centre of the selected batches.
  • test_multi_row_quotas_keep_the_even_spacing /
    test_full_length_quota_keeps_every_row -- the unchanged rules (pass before
    and after).
  • test_no_single_row_batch_contributes_position_zero -- sweep over lengths and
    budgets; no single-row quota may select position 0.

6 of the 9 fail on main. test_awq_token_row_quotas_skip_empty_batches now
expects the batch centre. The related AWQ/capture suites still pass: 57 passed
(test_awq_deepseek_v4_hash_moe_4880, test_awq_gpt_neo_packed_replay_5085,
test_awq_hash_moe_kept_rows_5015, test_awq_hybrid_recurrent_mask_4671,
test_awq_moe_root_capture_4697, test_awq_reservoir_incremental_5233,
test_calibration_attention_sinks), plus the token-row files.

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

Labels

None yet

Projects

None yet

1 participant