Repository navigation
fix(awq): keep AWQ for covered MoE experts when one is starved (#4675) - #4720
Merged
Merged
Conversation
AWQ builds one scaling group per MoE block's routed-expert `gate_proj`/`up_proj` pair and treated it as all-or-nothing. One expert below `Fallback.threshold`, one expert that native routing never selects, or one `dynamic`-excluded expert moved every expert in the layer to RTN. On Qwen3-30B-A3B that silently RTNs all 256 routed gate/up projections per layer and only logs a per-layer warning. The search reads one captured MoE-root input per group, and a member's own rows only reach the objective through the replayed block, so a starved member contributes nothing to the scale search while the norm it reads is still divided by the folded scale. - Split the group verdict: `_starved_group_members` classifies members per module; `_should_fallback_group` keeps the whole-group predicate for dense groups (#4063). - Routed-expert gate/up groups (search input is not a group member) drop only the starved members from the search, fold the scale into every member, and plain-quantize the starved ones after the fold. The group falls back wholesale only when no member has data and the group's routed tokens miss the threshold. - The replay-coverage guard now requires only the members native routing executed, and only for routed-expert groups; a dense group still fails closed. - `apply_scale` skips the input-feature division for a member that captured no rows instead of broadcasting a `(0,)` tensor against the scale. Tests: `tests/test_awq_moe_starved_expert_group_4675.py` adds a unit contract (search sees the covered members, the fold sees all of them, only the starved member is plain-quantized) and a tiny Qwen3-MoE end-to-end case whose router bias makes expert 3 unreachable: the other 7 experts' gate/up keep AWQ and only expert 3 is "not applicable". Both fail on the parent commit.
This was referenced Nov 17, 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 #4675.
Problem
AWQ builds one scaling group per MoE block's routed-expert
gate_proj/up_projpair and treated it as all-or-nothing. One expert belowFallback.threshold, one expert native routing never selects, or onedynamic-excluded expert moved every expert in the layer to RTN. On Qwen3-30B-A3B that silently RTNs all 256 routed gate/up projections per layer with only a per-layer warning. GPTQ handles this per module.The search reads one captured MoE-root input per group, and a member's own rows only reach the objective through the replayed block, so a starved member contributes nothing to the scale search — yet the norm it reads is still divided by the folded scale.
Fix
_starved_group_members()classifies members per module;_should_fallback_group()keeps the whole-group predicate for dense groups ([BUG] Quant accuracy: AWQ dense layers scale-search on only the last calibration sample (+ down_proj silently RTN) so AWQ == RTN; EXL3 still crashes under default auto_nf12 (#4006 bypass); in-memory model after quantize uses v1 qzeros as v2 (garbage generate) #4063 behavior unchanged).apply_scaleskips the input-feature division for a member that captured no rows instead of broadcasting a(0,)tensor against the scale.Tests
tests/test_awq_moe_starved_expert_group_4675.py:apply_scalesees all, only the starved member is plain-quantized;quant_log, only expert 3 is"not applicable", no whole-group fallback.Red on the parent commit (
assert 'not applicable' != 'not applicable'formlp.experts.0.gate_proj); green with the fix.Verified:
PYTHONPATH=/root/work-4675 python -m pytestover the new file +test_awq_scale_search_safety,test_awq_weight_mean,test_awq_moe_router_scaling,test_awq_per_module_bits,test_awq_empty_groups,test_awq_clip_empty_feature_4679,test_awq_clip_consistency,test_awq_gptq_lifecycle,test_bloom_awq_replay,test_tiny_moe_quant_smoke→ 277 passed, 90 skipped.ruff check gptqmodel testsclean.Residual: CPU-only validation here (GB10 GPU present but no large MoE checkpoint); the changed math is device-agnostic. A
dynamic-excluded expert stays dense but now receives the folded scale (required for norm/weight equivalence).