Skip to content

fix(awq): drop calibration padding rows from routed-expert captures (#5337) - #5346

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-moe-padding-5337
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-moe-padding-5337

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5337.

Problem

At batch_size > 1 AWQ's routed-expert captures kept the calibration padding rows. #4035 fixed that for GPTQ only: GPTQProcessor.register_moe_root_capture_hook zeroes the padded positions of the MoE input, and its expert hook drops the all-zero rows. AWQProcessor had neither, and _apply_active_keep_mask_to_feature cannot 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

  1. AWQProcessor.register_moe_root_capture_hook now also registers the GPTQ-style MoE-block pre-hook that multiplies hidden_states by active_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 by input_ids, so zeroing does not change their routing.
  2. New AWQProcessor._drop_padding_only_rows removes the zeroed rows from a routed-expert capture before it reaches the reservoir, raw_tokens or 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) nor keep_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 broke tests/test_awq_hash_moe_kept_rows_5015.py::test_packed_input_ids_follow_the_padded_kept_grid (252/888 hash_moe tokens routed with another token's id, because the packed input_ids grid still counted the dropped rows).

Tests

New tests/test_awq_moe_padding_rows_5337.py:

Node Guarantee
test_routed_expert_capture_drops_zeroed_padding_rows a [5, H] routed capture with two zeroed pad rows stores the three real rows; fails on main (keeps all five)
test_routed_expert_capture_keeps_rows_without_padding an unpadded batch keeps an all-zero row (it is a real activation)
test_moe_root_hook_zeroes_padded_positions the MoE block sees zeroed pad positions and untouched real rows; the hook registers even without a root-capture policy
test_moe_root_hook_is_a_no_op_without_padding no padding means the input is passed through unchanged

Ran 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 in test_awq_capture_perf_5284.py that also fail on clean main (left by #5327; tracked by the closed #5324). bash format/check.sh passes.

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 #5015 end-to-end node proves the drop does not disturb the packed input_ids grid.

Docs: docs/moe-awq-calibration.md now documents the AWQ side of the row-ownership contract.

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