Repository navigation
fix(awq): keep the batch centre, not row 0, for single-row token quotas (#5265) - #5289
Merged
Merged
Conversation
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5265.
Problem
AWQProcessor._compute_token_row_quotaspinned row 0 for every single-rowquota (the
quota == 1branch and theretained_tokens < batch_countbranch).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=1collapsed 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 ofquotaequal-widthbins,
floor((i + 0.5) * L / q). Both single-row branches use it, so a batchthat 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 bincentres regressed slightly in the 128-long-document regime (#4176).
_compute_token_row_quotasfeeds 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 keepsthe centre of the selected batches.
test_multi_row_quotas_keep_the_even_spacing/test_full_length_quota_keeps_every_row-- the unchanged rules (pass beforeand after).
test_no_single_row_batch_contributes_position_zero-- sweep over lengths andbudgets; no single-row quota may select position 0.
6 of the 9 fail on
main.test_awq_token_row_quotas_skip_empty_batchesnowexpects 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.