Repository navigation
fix(awq): drop calibration padding rows from routed-expert captures (#5337) - #5346
Merged
Merged
Conversation
This was referenced Nov 19, 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 #5337.
Problem
At
batch_size > 1AWQ's routed-expert captures kept the calibration padding rows. #4035 fixed that for GPTQ only:GPTQProcessor.register_moe_root_capture_hookzeroes the padded positions of the MoE input, and its expert hook drops the all-zero rows.AWQProcessorhad neither, and_apply_active_keep_mask_to_featurecannot filter a[routed_rows, H]capture because its row count is unrelated to the keep mask.Padding is not spread evenly: the router sends pad-token activations to a few experts. In the issue's DeepSeek-V4-Flash hash-layer run,
tid2eid[pad_id]sent every pad row to the same six experts per layer, making padding 58-75% of those experts' AWQ sample.Fix
AWQProcessor.register_moe_root_capture_hooknow also registers the GPTQ-style MoE-block pre-hook that multiplieshidden_statesbyactive_padding_mask(padding only, so BOS sinks stay). It is a no-op when the batch has no padding, and it is registered even when the module has no root-capture policy. Hash routers select byinput_ids, so zeroing does not change their routing.AWQProcessor._drop_padding_only_rowsremoves the zeroed rows from a routed-expert capture before it reaches the reservoir,raw_tokensor the token-row plan.The drop is deliberately narrow: a capture is treated as a routed subset only when its row count matches neither
keep_mask.numel()(the raw[B*S, H]grid, filtered by the mask itself) norkeep_mask.sum()(the all-expert path, which already stores exactly the kept rows). The row count decides; the zero check only finds the rows. That matters because a real activation can be all-zero: an earlier draft dropped on zeros alone and broketests/test_awq_hash_moe_kept_rows_5015.py::test_packed_input_ids_follow_the_padded_kept_grid(252/888hash_moetokens routed with another token's id, because the packedinput_idsgrid still counted the dropped rows).Tests
New
tests/test_awq_moe_padding_rows_5337.py:test_routed_expert_capture_drops_zeroed_padding_rows[5, H]routed capture with two zeroed pad rows stores the three real rows; fails onmain(keeps all five)test_routed_expert_capture_keeps_rows_without_paddingtest_moe_root_hook_zeroes_padded_positionstest_moe_root_hook_is_a_no_op_without_paddingRan
tests/test_moe_padding_rows.py,test_awq_gptq_lifecycle.py,test_awq_hash_moe_kept_rows_5015.py,test_awq_deepseek_v4_hash_moe_4880.py,test_awq_capture_perf_5284.py,test_awq_reservoir_incremental_5233.py,test_awq_reservoir_sibling_rows_5267.py,test_awq_token_row_position_5265.py,test_awq_token_rows_bounded_capture_5137.py,test_awq_moe_root_capture_4697.py,test_awq_moe_quant_speed_5284.py: 70 passed, plus 3 failures intest_awq_capture_perf_5284.pythat also fail on cleanmain(left by #5327; tracked by the closed #5324).bash format/check.shpasses.I did not re-run the issue's OLMoE / DeepSeek-V4-Flash measurements: the models are not available in this container. The new unit nodes pin the capture shape the native router produces, and the
#5015end-to-end node proves the drop does not disturb the packedinput_idsgrid.Docs:
docs/moe-awq-calibration.mdnow documents the AWQ side of the row-ownership contract.