Repository navigation
fix(awq): keep a declared fold whose first reader captured nothing - #6657
Merged
Merged
Conversation
The fold-declaration planner skipped a declared fold when its first feature was absent or empty. For a MoE gate/up group whose root capture was seeded but empty (a missing capture hook, a dynamic exclusion), this dropped a fold the tree planner keeps and could not tell the processor that the group's readers share the source (#6630). Use the tracker's feature precedence: the MoE root only when it holds rows, else the first declared target with a capture; when none captured anything, keep the node with `inp=None` and the full target set. The processor's fallback check then sees the starved members and does not fold the source without them. Full-capture plans are unchanged for all 210 MODEL_MAP types. Keep the derived routed-expert `down` empty capture (#4675) and the hand-written-declaration skip (#5995). Build the node from the merged declaration so a merged source keeps its full target set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
December 1, 2026 14:28
This was referenced Dec 1, 2026
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
* fix(awq): drop folds whose source has no weight elements A port materializes a config-disabled projection as a zero-sized Linear. Klear's mlp.shared_experts with n_shared_experts=0 is the concrete case: gate_proj/up_proj are [0, hidden] and down_proj is [hidden, 0]. After #6657 kept declared folds whose first reader captured nothing, the planner also kept a fold whose source is one of those empty projections. planned_group() only checked the module plan and widths, so the node became a scaling group; tests/module_tree/test_klear_local_port.py then sees the shared_experts.up_proj -> down_proj fold in the no-shared plan. Reject a source whose weight tensor has no elements in the shared planner filter. A zero-sized source has no output to divide and no weight to absorb a scale, so the group cannot be folded; the target falls back to plain quantization like any other dropped group. This is general to every definition, not a Klear special case. Refs #6657 * test(awq): pin the zero-size fold source rejection The planner unit test fails on main because planned_group() accepts a zero-sized Linear as a fold source, and passes with the fix. --------- Co-authored-by: GB10 Sweep <sweep@localhost>
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…ations (#6675) Remove the `awq_groups_from_tree_order` opt-out for the 19 types whose full-capture plan differs from their fold declarations only by width-dropped guesses. #6657 keeps a declared fold whose first reader captured nothing, so the declaration path no longer needs the tracker's narrowed/dropped groups. The inventory fixture diff removes exactly 36 `drop:width` groups and no other group; `awq_fold_inventory.py --check` reports `changed: none`. deepseek_v3, kimi_k2 and kimi_k25 stay on the tracker until the `_search_best_clip` KeyError on an uncaptured ungrouped projection is fixed; xing4_0 and minimax_m3_vl keep their separate reasons. Co-authored-by: Claude Opus 5.5 <[email protected]>
5 tasks done
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
`_search_best_clip` indexed `input_feat[name]` for every quantized module, so a featureless layer, a `dynamic` exclusion, a starved reader or an unrouted expert raised KeyError instead of leaving the module unclipped. #6657 keeps a declared fold with `inp=None`, so a declaration-planned layer can reach the clip search with an ungrouped quantized projection that has no capture. Skip absent or empty features with the existing #4679 `log.warn` low-coverage signal. The same missing-capture condition also filtered those modules out of `apply_quant`; the module then reached packing without zero points and aborted the run. Quantize every non-fallback module and let the clip search skip the uncaptured ones. The tracker path already quantizes the same module via its fallback, so the declaration path now matches it. Tests: the DeepSeek-V3/Kimi featureless tests force the declaration path and assert the #6657 featureless contract; clip-search unit tests cover the absent feature and its warning. Full-capture plans are unchanged (`awq_fold_inventory.py --check` -> changed: none; Qwen2.5-0.5B and ERNIE-4.5-21B GPU A/B bit-identical). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
`_search_best_clip` indexed `input_feat[name]` for every quantized module, so a featureless layer, a `dynamic` exclusion, a starved reader or an unrouted expert raised KeyError instead of leaving the module unclipped. #6657 keeps a declared fold with `inp=None`, so a declaration-planned layer can reach the clip search with an ungrouped quantized projection that has no capture. Skip absent or empty features with the existing #4679 `log.warn` low-coverage signal. The same missing-capture condition also filtered those modules out of `apply_quant`; the module then reached packing without zero points and aborted the run. Quantize every non-fallback module and let the clip search skip the uncaptured ones. The tracker path already quantizes the same module via its fallback, so the declaration path now matches it. Tests: the DeepSeek-V3/Kimi featureless tests force the declaration path and assert the #6657 featureless contract; clip-search unit tests cover the absent feature and its warning. Full-capture plans are unchanged (`awq_fold_inventory.py --check` -> changed: none; Qwen2.5-0.5B and ERNIE-4.5-21B GPU A/B bit-identical). Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Summary
The fold-declaration AWQ planner dropped a declared fold whenever its first
feature was absent or empty. On a MoE gate/up group the feature is the root
capture when it holds rows (#4760); a seeded-but-uncaptured root (an empty
tensor) therefore skipped the whole group, even though every routed expert had
its own capture. The layer lost a fold the tree planner keeps, and the planner
could no longer tell the processor that the group's readers share the norm, so
an excluded/starved reader could not veto the fold (#6630).
The declaration planner now uses the tracker's feature precedence: the MoE root
only when it holds rows, otherwise the first reader with a capture; if no reader
captured anything it keeps the node with
inp=Noneand the full declared targetset. The processor's fallback check then owns the group: a group with a starved
member is not folded, and a group whose members are all captured folds
neutrally on the captured member's feature. This is a behavior fix for
declaration-path types whenever a capture is empty or absent; full-capture plans
are unchanged for every type.
Fixes #4697 (the empty-root case now folds on a captured member instead of
dropping the group) and completes the declaration-path half of #6630.
What Changed
gptqmodel/models/base.py—_awq_nodes_from_declarations:first declared target with a capture (tracker precedence);
inp=Noneand every declared target when the firstfeature is absent/empty, instead of
continue; the derived routed-expertdowngroup still keeps its empty capture ([QUALITY] AWQ MoE: one starved, unrouted or dynamic-excluded expert sends ALL experts' gate/up to RTN (one all-or-nothing scale group); default AWQ on Qwen3-30B-A3B RTNs all 256 expert gate/up per layer #4675) and hand-writtendeclarations still skip (Declare AWQ fold sources and consumers per layer variant #5995);
merge_by_source), so thefull target set and consumers of a merged source reach the processor.
docs/awq-scaling-groups.md— the declared-fold contract and the plannerflow diagram now describe the kept node and the processor fallback.
tests/test_awq_declaration_empty_capture.py— new real-model regression onQwen2-MoE and Qwen3-MoE tiny local ports: an empty root keeps the full
gate/up group, the fold is neutral, an uncaptured reader stays in the group,
folding around it drifts, and folding the full set is neutral.
contract:
tests/module_tree/test_awq_fold_declarations.py,tests/test_awq_moe_root_capture_4697.py,tests/module_tree/test_deepseek_v4_local_port.py,tests/module_tree/test_intern_s2_preview_local_port.py,tests/test_hymba_local_port.py, and the processor fixture intests/test_lfm3_native_coverage.py(it passed full module names where theprocessor uses layer-relative names, and inference tensors where it divides
the replay feature in place).
Behavior change: with
fallback=None, an empty (not absent) capture now failsclosed with
_AWQScaleGroupErrorinstead of silently skipping the fold; thedocumented
fallback=Nonecontract already propagates that error. With thedefault fallback the group quantizes plainly, and absent readers are skipped by
the processor's missing-feature check.
Out of scope: the 23
_EMPTY_CAPTUREtracker keeps are released by PR-B afterthis lands; no definition opt-out is touched here.
Tests
GPU AWQ A/B (
gpu_ab.py, GPU index 2, fixed seed, Salesforce/wikitext-2calibration, every checkpoint tensor compared byte-for-byte):
Perturb A/B: declaration-path types whose plan changes
Two seeds of
empty20,absent20,root_empty, andunroutedover everyconfig variant (plus
+mha) of the 156 declaration-pathMODEL_MAPtypes,base
f442095e2(currentmain) vs branch. 144 types change; no typeremoves or changes an existing group, and no
fullplan differs. Thebranch only adds nodes:
ok) underroot_empty/empty20: the group issearched on the first captured reader and folds every declared target.
falls the group back to plain quantization instead of folding it.
drop): theprocessor's missing-feature check skips it.
Per-type exact group delta (144 types)
Perturb A/B: declaration-path types whose plan changed (base vs branch)
No type removed or changed an existing group; every difference is an added node.
#templates one routed expert. Adropnode has at least one declared target absent frominput_feat(the processor skips it); afallbacknode has an empty feature (the processordoes not fold it); an
oknode is a fold the base planner dropped.total types: 144
Measured Impact
Not applicable: no kernel, format, or runtime math change. Full-capture AWQ
plans and saved checkpoints are unchanged (inventory
changed: none, stressA/B 0 differences, GPU A/B bit-identical on the control and the MoE model).
The behavior change is limited to empty/absent captures, where the group now
falls back or folds on a captured member instead of being dropped.
Model Support / Module Plan
Not applicable: no new
MODEL_MAPentry, alias, or definition change. Themodule-plan inventory fixture is unchanged;
awq_fold_inventory.py --checkreports
changed: none.AWQ onboarding safety
local ports, capture the layer inputs from a native forward, and apply the
emitted fold to every target and non-quantized consumer. The empty-root group
folds with a captured expert's input (the same post-norm tensor every expert
reads) and is output-neutral (
0.0relative logits change). Folding the norminto the captured siblings only changes the output, which is why the
uncaptured reader stays in the group.
absent/empty member is not folded (the starved member is folded then
plain-quantized for a MoE gate/up group, [QUALITY] AWQ MoE: one starved, unrouted or dynamic-excluded expert sends ALL experts' gate/up to RTN (one all-or-nothing scale group); default AWQ on Qwen3-30B-A3B RTNs all 256 expert gate/up per layer #4675; a dense group falls back
whole).
tests/test_awq_moe_shared_expert_group_4760.py,tests/test_awq_moe_starved_expert_group_4675.py,tests/test_awq_moe_prune_uncovered_4456.py,tests/test_awq_empty_groups.py, andtests/module_tree/test_awq_dynamic_excluded_reader.pypass.changed: noneand the width-coincidence stress A/B has 0 differences.Logic Flow Documentation
docs/awq-scaling-groups.md:the declared-fold flow now keeps the node (
inp=None) and the processorfallback owns it; the hand-declared skip and the routed-expert
downexception are marked.
(
_awq_nodes_from_declarations,merge_by_source,generate_node_for_awq_scaling,AWQProcessor._quantize_layer).shown in the diagram and described in the contract text.
keep node with inp=None,skip group).docs/awq-scaling-groups.md, already linked fromthe AWQ documentation set.
Review Requirements
A/B; existing tests updated only where they pinned the old skip behavior.
Kernel Accuracy Requirements
Not applicable: no kernel, packing, dispatch, or fusion change.
Notes
fallback=None+ an empty (not absent) capture now fails closed with_AWQScaleGroupErrorinstead of silently dropping the fold. This is thedocumented
fallback=Nonecontract; the default fallback quantizes plainly.test_lfm3_native_coverage.pyfixture now passes layer-relativemodule names and normal tensors to the processor, matching production
(
state.modules[module.name], replay features are divided in place). The oldfixture's full names only worked because the planner skipped every group.
🤖 Generated with Claude Code