Repository navigation
fix(awq): keep bypass-mode candidate replays on native routing - #5934
Merged
Merged
Conversation
`_search_best_scale` kept the `_all_experts_replay_forward` wrapper installed for the whole 20-candidate grid. The wrapper's gate/up outputs are discarded and only the native routed output reaches the loss, so every candidate paid for an all-experts pass on every replay token. Limit the all-experts lifecycle to the reference pass that needs the observation (#4223); run the candidate grid under the same top-k override but with native routing.
Qubitium
force-pushed
the
fix/awq-bypass-replay-reference-only-5730
branch
from
November 20, 2026 15:41
13fb831 to
400a5c8
Compare
Qubitium
marked this pull request as ready for review
November 20, 2026 15:41
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.
Summary
Fixes #5730.
AWQProcessor._search_best_scalekept_moe_replay_routing(and therefore_all_experts_replay_forward) installed around the whole 20-candidate scale grid. In bypass mode the wrapper runs every expert's gate/up on every replay token and discards the outputs; only the native routed output reaches the loss. The all-experts lifecycle is only needed by the reference pass, whose forward pre-hooks record which group members were observed (#4223).What Changed
AWQProcessor._moe_replay_routing(..., all_experts: bool = True): the bypass lifecycle (all-experts wrapper) is only entered whenall_experts; the top-k override is unchanged and still applies to both passes.AWQProcessor._search_best_scale:[STEP 4](_compute_best_scaleand its kwargs) moved out of the reference-passwithblock and now runs under a second_moe_replay_routing(..., all_experts=False)context that keeps the captured top-k override but uses native routing.tests/test_awq_bypass_candidate_replay_5730.py(real tiny Qwen3-MoE, CPU) counts expert gate rows per MoE-block row during each_compute_best_scalecall and asserts native top-1 routing (~1 row/token) instead of the all-experts wrapper (E+1 rows/token). It also asserts the reference pass still scores all 8 experts.No API change;
down_projgroups are unaffected (their replay boundary isdown_projitself, so_moe_bypass_replayalready returnedNone).Tests
Measured Impact
Workload: real tiny
Qwen3MoeForCausalLM(1 layer, hidden 64, 8 experts, top-1, moe_intermediate 32), 17 calibration tokens, AWQ 4-bit group 16,FORMAT.GEMM,MoEConfig(routing=ExpertsRoutingBypass()), CPU, torch 2.15.0+cu132, Python 3.14t. Only one scale group (all-experts gate/up) crosses the MoE block; it runs 20 candidates. Wall times are three runs each.quantize()wall time (s, mean of 3)37e985a8…37e985a8…quant_logloss SHA-256dc7390f1…dc7390f1…Commands:
/root/bench_5730.py(per-call counters + wall time) and/root/bench_5730_hash.py(torch.manual_seed(0)before the fixture, SHA-256 over the quantized state_dict and over sorted(module, loss)rows), run on74a480ecaand on the PR head. The identical hashes show the discarded all-experts pass did not affect scales, losses, or the checkpoint.Not measured: CUDA / Qwen3-30B-A3B (host has one GPU but no CUDA toolkit, so no GPU AWQ run was possible). The issue's 16x gate/up FLOP ratio for Qwen3-30B-A3B is an estimate, not a measured wall time here.
Model Support / Module Plan
Not applicable: no
MODEL_MAPentry, model type, definition, or module-plan change.Logic Flow Documentation
Kernel Accuracy Requirements
Review Requirements
Notes
fp16_outputis produced by the wrapper'soriginal_forward(native) call, the scored loss is unchanged; the seeded hashes confirm it.