Repository navigation
fix(awq): capture declared MoE roots without lifecycle hooks (#4697) - #4723
Merged
Merged
Conversation
Definitions such as Granite-MoE, gpt-oss, ERNIE-4.5-MoE, Gemma-4, DBRX-converted, Diffusion-Gemma, Kimi and Nemotron-H puzzle declare a :moe root but do not set moe_lifecycle_hooks. AWQ registered the root capture hook only from that optional routing object, so the declared root feature stayed (0,) and awq_get_modules_for_scaling dropped the routed-expert gate/up group without a warning. Resolve the declared roots from ModulePlan.moe_roots() in the subset executor and register the AWQ capture hook on each layer-level root, deduplicated against the lifecycle block. Keep the GPTQ padding-hook path unchanged. If a declared root still has no activations, warn and skip the group instead of treating width 0 as a foreign consumer and dropping it silently. Add a real-quantize regression for Granite-MoE and gpt-oss plus a negative test for the empty-root warning.
ZX-ModelCloud
force-pushed
the
fix/4697-awq-moe-root-capture
branch
from
November 17, 2026 11:20
710d0b9 to
2d4e970
Compare
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.
TL;DR
AWQ registered its MoE-root capture hook only from the optional
moe_lifecycle_hooksobject. Definitions that declare a:moeroot withoutlifecycle hooks left the root feature empty, so
awq_get_modules_for_scalingread a zero-width "source", treated every routed expert as width-foreign, and
silently dropped the entire gate/up scaling group. Resolve the declared roots
from
ModulePlan.moe_roots()in the subset executor and register the AWQcapture hook there; warn instead of dropping the group silently when a root
still has no activations.
Net: 4 files, +83 implementation/docs, +190 regression test.
1. The problem
BaseQModel.awq_input_feature_aggregationreturnscapture_root: Trueforevery declared MoE root, so
AWQProcessor.preprocessseeds an empty root task.The only hook that records that task was registered from the optional routing
lifecycle:
flowchart TD A["run_subset_stage"] --> B{"gptq_model.moe_lifecycle_hooks<br/>is not None?"} B -- "yes" --> C["hooks.get_moe_block_for_subset"] C --> D["register_moe_root_capture_hook<br/>record pre-router input"] B -- "no" --> E["no root hook"] E --> F["tasks root stays empty"] F --> G["_layer_input_features<br/>root feature = torch.empty(0)"] G --> H["awq_get_modules_for_scaling<br/>input_width = 0"] H --> I["every expert looks width-foreign"] I --> J["gate/up group dropped<br/>only log.debug, no warning"] style E fill:#ffcdd2,stroke:#b71c1c style J fill:#ffcdd2,stroke:#b71c1cawq_get_modules_for_scalingselected the root feature for a MoE gate/up blockwhen
last_module_root in input_feat, but an empty tensor is still "in" themapping. The width filter then produced
input_width = 0and rejected allsixteen expert projections, so no
post_attention_layernorm -> experts.*.gate/upgroup reached
AWQProcessor._quantize_layer.origin/main:gptqmodel/looper/stage_subset.py:998-1017gptqmodel/looper/stage_subset.py:1020-1044(0,),origin/main:gptqmodel/models/base.py:5728-57360, all consumers foreign,log.debugonlygptqmodel/models/base.py:5745-57592. The new flow
flowchart TD A["awq_input_feature_aggregation<br/>plan.moe_roots()"] --> B["capture_root policy"] B --> C["AWQProcessor.preprocess<br/>seed root task"] D["run_subset_stage<br/>_model_module_plan(looper.gptq_model)"] --> E{"AWQ and layer has<br/>plan.is_expert?"} E -- "yes" --> F["module.get_submodule(template)<br/>layer-level root"] F --> G{"same module as<br/>lifecycle block?"} G -- "no" --> H["register_moe_root_capture_hook"] G -- "yes" --> I["already registered, skip"] H --> J["record_moe_root_input_feature<br/>bounded token rows"] J --> K["_layer_input_features<br/>aggregate root feature"] K --> L["awq_get_modules_for_scaling<br/>norm -> experts gate/up"] L --> M["AWQProcessor._quantize_layer<br/>apply_scale"] E -- "no" --> N["no root hook"] style N fill:#fff3cd,stroke:#997404The plan-based registration runs only for AWQ (
is_awq_processor) and onlywhen the layer actually contains a declared expert (
plan.is_expert). GPTQ'spadding-zeroing hook keeps its existing lifecycle path. A lifecycle block that
is the same object as the declared root is registered once.
3. Failure and ambiguity contract
moe_lifecycle_hooks, top-level:moeroot0, silent droplog.warningnames the root; group is skipped and the experts stay on plain quantizationmixer.experts)4. Change inventory
gptqmodel/looper/stage_subset.pygptqmodel/models/base.py0as a foreign sourcedocs/awq-scaling-groups.mdtests/test_awq_moe_root_capture_4697.py5. Tests / guarantees
test_declared_moe_root_capture_drives_gate_up_group[granitemoe-block_sparse_moe-8]scale_feature == "block_sparse_moe", token-row aggregation and the full calibration token counttest_declared_moe_root_capture_drives_gate_up_group[gpt_oss-mlp-8]mlp; covers a:nosrcexpert-up layout where only the gate/up group can be foldedtest_empty_declared_root_warns_instead_of_silent_dropRed evidence: on unpatched
origin/main(19c40b201) both real-quantize casesfail at
assert row["scale_feature"] == moe_rootwith'block_sparse_moe.experts.0.gate_proj'/'mlp.experts.0.gate_proj', and thewarning test fails because
caplog.textcontains no empty-root message.6. Validation
python -m pytest -q -ra \ tests/test_awq_moe_root_capture_4697.py \ tests/test_awq_scaling_groups.py \ tests/test_awq_gptq_lifecycle.py \ tests/test_moe_padding_rows.py \ tests/test_awq_scale_search_safety.py \ tests/test_awq_moe_router_scaling.py \ tests/test_awq_empty_groups.py \ tests/test_awq_position_kwargs.py \ tests/test_awq_scale_search_memory.py \ tests/test_bloom_awq_replay.py \ tests/module_tree/test_awq_relationships.py \ tests/module_tree/test_bloom_awq_relationships.py \ tests/module_tree/test_registered_module_plans.py \ tests/module_tree/test_definition_subset_ordering.py # 747 passed, 6 skipped, 1 failedThe branch is rebased on current
main(2ed6a6e4f), so the run includes#4720's
tests/test_awq_moe_starved_expert_group_4675.py. The one failure istest_definition_subset_ordering.py::test_issue_4372_tiny_model_data_flow[nemotron_h],which fails identically on unpatched
origin/mainwithValueError: Pointer argument cannot be accessed from Triton (cpu tensor?).It is an existing environment limitation, not a regression from this change.
The 6 skips are the existing
mamba_ssmCPU-fallback and unavailable-familyskips.
The new file alone:
python -m pytest -q -ra tests/test_awq_moe_root_capture_4697.py # 3 passedAdditional real-model checks: a tiny gpt-oss
quantize()now produces twoscaling groups per layer (attention qkv and
post_attention_layernorm -> 16 expert gate/up) instead of one, with the router collected as a scaleconsumer; a tiny Granite-MoE produces ten groups, including the expert gate/up
group.
7. Reviewer notes
Their declared root is nested (
mixer.experts), so the group builder alreadyfalls back to the shared-expert feature and emits the group on unpatched
main; a tiny native Nemotron-H quantize confirms the group is applied. Theplan-based hook deliberately skips nested templates because the group builder
reads a layer-level root feature; changing that boundary would need a
separate consumer/replay contract for latent MoE layouts.
issue's suggested fix. It does not substitute a per-expert feature for the
pre-router input, because experts see disjoint token sets and a single
expert's rows are not a valid scoring input for the whole group.
existing module plan and the AWQ processor identity.