Repository navigation
fix(awq): replay MoE groups under the capture routing override (#4151) - #4154
Merged
Merged
Conversation
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 #4151
Root cause
#4144 (
bd922cd9b) added the replay-coverage guard inAWQProcessor._search_best_scale(gptqmodel/looper/awq_processor.py).Calibration forwards go through
ForwardExecutor._moe_forward_context, whichapplies
ModuleLooper.MoERoutingOverrideContextwhen the user configuresMoEConfig(routing=ExpertsRoutingOverride(...)). AWQ's reference and candidatereplays call
module2inspectdirectly, so they used the model's native top-k.Experts captured only because of the override never executed in the replay; the
guard raised
_AWQScaleGroupErrorand the entire gate/up group fell back toplain quantization (default RTN), with only a warning.
Fix
_search_best_scalenow resolves the same capture-time override(
AWQProcessor._replay_moe_routing_override, mirroringModuleLooper'sdynamic_expert_index+get_num_expertsresolution) and re-enters it withset_moe_topk/restore_moe_topkaround both the reference replay and the20-candidate
_compute_best_scalereplays. This is route (1) from the issue:it is the faithful option because the scale objective scores the complete
captured group instead of dropping experts that the shared scale fold still
applies to. The guard itself is unchanged and still rejects genuinely partial
groups.
The separate pre-existing native-run fallback for experts that captured no
features at all (
_should_fallback_group,moe=Nonepath) is untouched. ThisPR fixes the override
_AWQScaleGroupErrorfallback, not that one.Before / after (CPU, tiny Qwen3-MoE: 1 layer, 32 experts, top-1, fp16, AWQ 4-bit)
Before (
d62bc9af):After:
Regression tests
test_moe_routing_override_replays_every_captured_expert: native top-1selects only expert 0, the override captures both; the search now scores both
and restores native top-k. Fails on
d62bc9af, passes here.test_moe_routing_override_still_rejects_genuinely_partial_group: expert 1is never executed even under the override, so the guard still raises
_AWQScaleGroupErrorforblock.experts.1.gateand restores top-k. Thisproves the guard was not weakened.
test_tiny_qwen3_moe_awq_routing_override_scales_every_expert: end-to-endtiny 32-expert Qwen3-MoE; asserts 0
_AWQScaleGroupError, numeric AWQ lossfor all 64 expert gate/up projections, and no plain-quantization fallback.
Fails on
d62bc9af(_AWQScaleGroupError), passes here.Test commands / results
Hardware: CPU only for all runs above (no GPU). The tiny model uses
moe_intermediate_size=64so the existing AWQ clip path divides evenly.Limitations
random CPU model and this PR keeps that scope.
ExpertsRoutingBypasshas the same native-replay symptom in the same tinymodel (1 raise, 0/64 scaled). It is a different capture mechanism (a
lifecycle forward wrapper, not a top-k override), and faithfully re-entering
it needs looper lifecycle state; route (2) would weaken the fix(awq): preserve scale-search routing and reject incomplete replay groups #4144 guard.
This PR deliberately does not change bypass behavior and leaves it as a
documented limitation.
moe=Nonemissing-feature fallback for experts that nevercaptured features is unchanged (and still makes the native run fall back).