Skip to content

fix(awq): replay MoE groups under the capture routing override (#4151) - #4154

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4151-awq-moe-coverage
Nov 15, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4151-awq-moe-coverage

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4151

Root cause

#4144 (bd922cd9b) added the replay-coverage guard in
AWQProcessor._search_best_scale (gptqmodel/looper/awq_processor.py).
Calibration forwards go through ForwardExecutor._moe_forward_context, which
applies ModuleLooper.MoERoutingOverrideContext when the user configures
MoEConfig(routing=ExpertsRoutingOverride(...)). AWQ's reference and candidate
replays call module2inspect directly, so they used the model's native top-k.
Experts captured only because of the override never executed in the replay; the
guard raised _AWQScaleGroupError and the entire gate/up group fell back to
plain quantization (default RTN), with only a warning.

Fix

_search_best_scale now resolves the same capture-time override
(AWQProcessor._replay_moe_routing_override, mirroring ModuleLooper's
dynamic_expert_index + get_num_experts resolution) and re-enters it with
set_moe_topk/restore_moe_topk around both the reference replay and the
20-candidate _compute_best_scale replays. 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=None path) is untouched. This
PR fixes the override _AWQScaleGroupError fallback, not that one.

Before / after (CPU, tiny Qwen3-MoE: 1 layer, 32 experts, top-1, fp16, AWQ 4-bit)

Before (d62bc9af):

MODE=native   _AWQScaleGroupError raised 0 time(s)
MODE=native   scaled gate/up: 0/64   (pre-existing missing-feature fallback)
MODE=override _AWQScaleGroupError raised 1 time(s)
MODE=override scaled gate/up: 0/64
WARN ... using configured plain-quantization fallback for ['mlp.experts.0.gate_proj', ... 'mlp.experts.31.up_proj']:
     AWQ: reference replay did not execute targets [...]; the scale objective would not score the complete group.

After:

MODE=native   _AWQScaleGroupError raised 0 time(s)
MODE=native   scaled gate/up: 0/64   (unchanged pre-existing fallback)
MODE=override _AWQScaleGroupError raised 0 time(s)
MODE=override scaled gate/up: 64/64
(no fallback / coverage warnings in the override run)

Regression tests

  • test_moe_routing_override_replays_every_captured_expert: native top-1
    selects 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 1
    is never executed even under the override, so the guard still raises
    _AWQScaleGroupError for block.experts.1.gate and restores top-k. This
    proves the guard was not weakened.
  • test_tiny_qwen3_moe_awq_routing_override_scales_every_expert: end-to-end
    tiny 32-expert Qwen3-MoE; asserts 0 _AWQScaleGroupError, numeric AWQ loss
    for all 64 expert gate/up projections, and no plain-quantization fallback.
    Fails on d62bc9af (_AWQScaleGroupError), passes here.

Test commands / results

CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD /opt/venvs/cu130t/bin/python -m pytest \
  tests/test_awq_scale_search_safety.py -q
# 40 passed

CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD /opt/venvs/cu130t/bin/python -m pytest \
  tests/test_awq_scale_search_safety.py tests/test_awq_moe_router_scaling.py -q
# 50 passed

CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD /opt/venvs/cu130t/bin/python -m pytest \
  tests/test_awq_scale_search_safety.py tests/test_awq_moe_router_scaling.py \
  tests/test_bloom_awq_replay.py -q
# 74 passed

CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD /opt/venvs/cu130t/bin/python -m pytest \
  tests/test_tiny_moe_quant_smoke.py -q
# 2 passed

HIP_VISIBLE_DEVICES="" PYTHONPATH=$PWD /opt/venvs/rocm101t/bin/python -m pytest \
  tests/test_awq_weight_mean.py -q
# 54 passed, 27 skipped
# (CUDA venv cannot collect this file: pre-existing missing `parameterized`.)

ruff check gptqmodel docs/eora tests setup.py
# All checks passed!

Hardware: CPU only for all runs above (no GPU). The tiny model uses
moe_intermediate_size=64 so the existing AWQ clip path divides evenly.

Limitations

  • Real-checkpoint accuracy cost was not measured; the issue only had a tiny
    random CPU model and this PR keeps that scope.
  • ExpertsRoutingBypass has the same native-replay symptom in the same tiny
    model (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.
  • The pre-existing moe=None missing-feature fallback for experts that never
    captured features is unchanged (and still makes the native run fall back).

@Qubitium
Qubitium merged commit 60ac76d into main Nov 15, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4151-awq-moe-coverage branch November 15, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Follow-up on #4144: AWQ replay-coverage check drops scaling for entire MoE expert gate/up group under ExpertsRoutingOverride

1 participant