Repository navigation
Description
Found on main @ 12c1273, ROCm GPU (torch 2.16 / transformers 5.22.1).
What is wrong
AWQ builds one scaling group for a MoE block's routed-expert gate/up projections: every expert's gate_proj and up_proj share prev_op = post_attention_layernorm (gptqmodel/models/base.py:5570, :5651-5660). Three independent checks then treat that group as all-or-nothing, and each sends every member to the plain-quantization fallback (RTN by default):
_should_fallback_group(gptqmodel/looper/awq_processor.py:2348-2390, consulted at:2486-2488). It has been per-member since fix(awq): aggregate variable-length calibration for every module (#4063) #4071 (fix for [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): "A group shares one scale vector, so one starved member still has to fall back." One expert belowFallback.threshold, or with no captured feature, vetoes the group.- The replay-coverage guard (
awq_processor.py:3071-3077, from fix(awq): preserve scale-search routing and reject incomplete replay groups #4144). An expert that native routing never selects is "not executed" in the reference replay, so_AWQScaleGroupErrorfalls back the whole group (:2601-2605). [BUG] Follow-up on #4144: AWQ replay-coverage check drops scaling for entire MoE expert gate/up group under ExpertsRoutingOverride #4151/[BUG] Follow-up on #4151/#4154:MoEConfig(routing=ExpertsRoutingBypass())still makes AWQ drop every MoE expert gate/up group to RTN fallback #4223 fixed this guard only for override/bypass routing. Under the default native routing it still fires whenever an expert gets zero tokens. - A per-expert
dynamic-:exclusion. The excluded expert has no captured feature, so check 1 vetoes the group in every layer.
For a MoE layer, this means one expert below Fallback.threshold (default 0.5% of the calibration tokens), one with zero routed tokens, or one excluded by dynamic, makes all experts in that layer lose AWQ scaling. That is 128 modules on OLMoE, 256 on Qwen3-30B-A3B. Only a log.warning("fallback quant N modules") reports it.
Under native routing, starved experts are the normal case for large expert counts. With 64 C4 samples (26,795 tokens), these are the routed-token counts per expert from the HF router:
| model (truncated) | experts/layer | experts below the default 0.5% (134 tokens), per layer | zero-token experts |
|---|---|---|---|
| Qwen3-30B-A3B (L0/L1/L2) | 128 | 18 / 16 / 32 | yes (L0, L2) |
| Qwen1.5-MoE-A2.7B | 60 | 0 | no |
| DeepSeek-V2-Lite | 64 | 0 | no |
So on Qwen3-MoE-class models every MoE layer's expert gate/up falls back to RTN under default AWQ. The scale vector would only have been folded into the norm. Starved experts could still take the folded scale and be RTN-quantized on their own, without data, so nothing forces the other 120+ well-calibrated experts to fall back with them.
GPTQ handles the same calibration per module. Only the starved experts' projections fall back.
Repro
OLMoE-1B-7B-0924 truncated to 4 layers, AWQConfig(bits=4, group_size=128), C4 calibration, batch_size=1.
(a) Default threshold, n=1 sample (~390 tokens), so a few experts get 0 tokens:
GPTQ (same data): 9 WARN "no calibration samples reached this module" -> 9 modules RTN (3 experts x 3 projections)
AWQ:
AWQProcessor: layer 0 fallback quant 129 modules: ['mlp.experts.1.gate_proj', 'mlp.experts.4.up_proj', 'mlp.experts.61.up_proj', ...]
AWQProcessor: layer 2 fallback quant 130 modules: [...]
AWQProcessor: layer 3 fallback quant 129 modules: [...]
(b) n=16 (6,704 tokens), fallback={"threshold": 300} to make the effect easy to see. Routed-token counts from the router: layer 0 has exactly one expert below 300 (expert 23: 291 tokens; median 770). Layer 3 has two (experts 6 and 15: 294 and 264). Layers 1 and 2 have none.
AWQProcessor: layer 0 fallback quant 129 modules: ['mlp.experts.15.gate_proj', 'mlp.experts.19.gate_proj', 'mlp.experts.17.up_proj', ...]
AWQProcessor: layer 3 fallback quant 129 modules: [...]
That is 128 gate/up modules (all 64 experts) plus the starved expert's down_proj, because one expert with 291 instead of 300 tokens fell short.
(c) Per-expert dynamic exclusion (dynamic={r"-:.*experts\.(0|1)\..*": {}}, n=16, default threshold). The excluded experts 0/1 stay dense as intended, but:
AWQProcessor: layer 0 fallback quant 124 modules: ['mlp.experts.57.up_proj', 'mlp.experts.62.gate_proj', ...]
AWQProcessor: layer 1 fallback quant 124 modules: [...]
AWQProcessor: layer 2 fallback quant 124 modules: [...]
AWQProcessor: layer 3 fallback quant 124 modules: [...]
All of the remaining 62 experts' gate/up (124 modules) are RTN in every layer.
(d) Default config on a real large-expert MoE: Qwen3-30B-A3B truncated to 3 layers, AWQConfig(bits=4, group_size=128), 32 C4 samples, nothing else changed:
AWQProcessor: layer 0 using configured plain-quantization fallback for ['mlp.experts.0.gate_proj', ... all 256 ...]: AWQ: reference replay did not execute targets ['mlp.experts.5.gate_proj', 'mlp.experts.5.up_proj', 'mlp.experts.10.gate_proj', ..., 'mlp.experts.96.up_proj']; the scale objective would not score the complete group.
AWQProcessor: layer 0 fallback quant 273 modules
AWQProcessor: layer 1 fallback quant 270 modules
AWQProcessor: layer 2 fallback quant 286 modules
That is all 256 routed gate/up projections plus the starved experts' down_proj in every layer. Five unrouted experts in layer 0 (and seven in layer 1) are enough.
Quality (mean token KL vs bf16 on wikitext-2, 16×256):
| run | KL |
|---|---|
| OLMoE-L4 AWQ, default (no expert below threshold) | 0.07036 |
OLMoE-L4 AWQ, threshold=300: 1 expert (L0) and 2 experts (L3) starved, 2×128 gate/up RTN |
0.07157 |
| Qwen3-30B-A3B-L3 RTN | 0.04577 |
| Qwen3-30B-A3B-L3 AWQ default (every expert gate/up RTN, see (d)) | 0.03584 |
Qwen3-30B-A3B-L3 AWQ + ExpertsRoutingOverride("all") (no expert starved, so no fallback) |
0.03529 |
The truncated 3-layer model understates the effect: on the full 48-layer model every MoE layer has unrouted experts at typical calibration sizes. (64 C4 samples: 16-32 of 128 experts per layer are below the 0.5% threshold, and several get zero tokens.)
Suggested fix
In _should_fallback_group, the replay-coverage guard and _quantize_layer, for a MoE gate/up group whose members are per-expert projections (the scale search already reads the MoE root input, not per-expert features):
- drop only the starved experts from the scale search (their features are not used to pick
s); - still apply the folded scale to them (their weights must be multiplied by
sbecause the norm is divided by it), then quantize them with the fallback strategy; - keep AWQ for the remaining experts. In the replay-coverage guard, require only the experts that native routing executed. Skip the input-feature division and clip search for members with empty features (
scale.py:apply_scaleand the clip path both assume non-empty features today).
Only when the routed tokens of the whole group are below the threshold should the whole group fall back. Log the starved expert count per layer at WARN.
Test that should have caught it
tests/test_tiny_moe_quant_smoke.py checks only that AWQ MoE quantization runs. Add a case with a tiny Qwen3-MoE (8 experts) in which a router bias makes one expert never selected. Assert that the other experts' gate/up rows in quant_log are AWQ (not "not applicable") and only the starved expert falls back.
Severity
High (silent quality loss). Default AWQ on large-expert MoE models (Qwen3-MoE, Qwen3.5-MoE, DeepSeek-V3-class, GLM-MoE, ...) gives RTN for every routed expert's gate/up, in every layer that has one rare expert. The user sees only a per-layer warning, and the checkpoint is labelled AWQ.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4720
Reproducing the all-or-nothing MoE gate/up fallback on a tiny MoE
fix(awq): keep AWQ for covered MoE experts when one is starved (#4675) (
refactor(awq): build scaling groups from fold declarations; the tree …
refactor(models): move the remaining structural AWQ overrides to fold…
refactor(models): replace config-conditional AWQ group overrides with…
refactor(models): replace config-conditional AWQ group overrides with…
fix(awq): keep a declared fold whose first reader captured nothing (#…