Repository navigation
fix(awq): keep a dynamic-excluded reader in its source's scaling group on the tree-order planner - #6630
Merged
Conversation
…p on the tree-order planner A module excluded by a `dynamic` `-:` rule captures no input, so it is absent from `input_feat`. The tree-order planner (`_awq_generic_get_modules_for_scaling`, still used by the 92 types with `awq_groups_from_tree_order = True`) skipped any block with no captured feature, which also dropped the fact that the block reads a source: * parallel decoders (falcon, refinedWebModel, moss, falcon_h1): with the MLP (or Mamba) branch excluded, the shared input norm was folded into the attention branch only, and the excluded branch read the divided norm output uncompensated (relative logits change 0.15 on a tiny Falcon; a real CPU AWQ run divides input_layernorm by the scale and leaves dense_h_to_4h untouched); * with the attention branch excluded, the MLP's `:in=` source was never recorded, so the MLP input was folded into `self_attention.dense` / `self_attn.o_proj`, an output on the other branch; * qwen3_next's AWQ-quantized router, nemotron_h shared/routed experts and ernie4_5_moe's split dense gate/up blocks lost their compensation the same way. The fold-declaration path already keeps an excluded target in its fold, so the processor finds a member without features and does not fold the source. The tracker now does the same: an uncaptured block is planned from its modules' input width and merged into its source's group; a group whose first block captured nothing is dropped after merging, matching a declared fold whose first branch captured nothing. Plans without exclusions are unchanged (fold inventory --check: changed: none). Across all 210 MODEL_MAP types, planning every layer variant with every single quantized module and every branch prefix excluded changes plans only for the 10 tracker types above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
December 1, 2026 09:48
This was referenced Dec 1, 2026
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…6657) 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]>
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
AWQ with a
dynamic-:rule that excludes a whole block of modules could fold a scale into a source that the excluded modules still read, and those modules got no compensation. This happened on the tree-order planner, which still plans the 92 types withawq_groups_from_tree_order = True. The decoder output then changed even though nothing in it was quantized yet.An excluded module captures no input, so it is missing from
input_feat._awq_generic_get_modules_for_scalingskipped any block without a captured feature, and with it the fact that the block reads a source::in=source was never recorded, so the MLP input was folded intoself_attention.dense/self_attn.o_proj. That output is on the other branch.mlp.gateis quantized in its AWQ tree), the nemotron_h shared and routed experts, and ernie4_5_moe's densegate_proj/up_projblocks lost their compensation the same way.The fold-declaration path (#6480; cohere, the qwen3.5 family and the other 118 types) already keeps an excluded target in its fold. The processor then finds a member without features and does not fold that source. This PR makes the tree-order planner do the same, so both planners agree.
What Changed
BaseQModel._awq_generic_get_modules_for_scaling: a block the layer owns but whose modules have no captured input is no longer skipped. It is planned from its modules' input width and merged into its source's group by_merge_shared_source_nodes. A merged group whose first block captured nothing has no search input. It is dropped after merging, with a warning when captured members lose the fold. This matches a declared fold whose first branch captured nothing. No processor change._module_input_width: input channels of a 2-D weight module (Conv1Dstores[in, out]).docs/awq-scaling-groups.md: contract rule 7, adynamic-excluded reader stays in its source's group.dynamicexclusion (or a looper-pruned module) on tree-order types. The affected source is no longer folded. Its captured readers are quantized without that scale, or with the configured fallback when they share a group with the excluded member, exactly as on the declaration path.Fallback, its captured siblings therefore drop to RTN instead of AWQ clip-quantization (e.g.query_key_valuewhen Falcon's MLP is excluded, or Cohere's q/k/v when its MLP is excluded). That is safe but not ideal. Compensating excluded readers would keep AWQ for the siblings: fold the scale into them and search on the captured members only. It would change the declaration path too.Tests
New:
tests/module_tree/test_awq_dynamic_excluded_reader.py. It builds tiny random-init models from the vendored ports (float64, non-unit norm gains) and removes the excluded modules' captured inputs, as the processor'sinput_featdoes under a-:rule. It then folds every emitted group with a non-uniform scale into all of its members and consumers and compares the full-model logits.Existing coverage (CPU,
-n 16):Measured Impact
Fold-only (identity quantization) worst relative change of the full-model logits. Every planned group is folded with scales
linspace(0.55, 1.45)into all of its members and consumers, on tiny vendored-port models with the listed modules excluded:mlp.*)self_attention.*)self_attention.query_key_value)mlp.gate, the router)mlp.*, declaration path)linear_attn.in_proj_z, declaration path)Real CPU AWQ quantize: a tiny Falcon with
dynamic={"-:.*\.mlp\..*": {}},GPTQModel.load+quantize, bits=4, group_size=32. On main,input_layernorm.weightchanges by 32% / 12% relative (layers 0 / 1), while the excludeddense_h_to_4hchanges only by the bf16 load cast (1.7e-3), so the MLP input is uncompensated. On this branch,input_layernormchanges only by the same load cast (1.7e-3). No fold happens, andquery_key_valuetakes the configured fallback, like Cohere on the declaration path.Blast radius under
dynamicexclusion. All 210MODEL_MAPtypes were planned on meta, for every config variant and distinct decoder layer. Each layer was planned with nothing excluded, then with each non-expert quantized module excluded alone, then with each branch prefix excluded (mlp.*,self_attn.*,mlp.experts.*, ...). That is 5838 plans, main vs branch:kv_a_layernorm -> kv_b_projwhenq_b_projis excluded, a data-flow-correct MLA fold (kv_b_proj is that norm's only reader) that the oracle flags only because the unexcluded plan does not emit it.GPU AWQ A/B without
dynamic(bits=4, group_size=128, 64 wikitext rows, bf16, one GPU, main then branch). The tensors and json/csv files of the saved checkpoints were compared:# docs contract python -P -m pytest -q tests/test_docs_contract_refs.py 266 passedModel Support / Module Plan
Not applicable: no
MODEL_MAPentry, module tree or definition changes. The fold inventory for all 210 types is unchanged (--check:changed: none).Model test node IDs and results (or "not applicable"): not applicable (see Tests for the registry/plan suites run).
AWQ onboarding safety
AWQ evidence and per-variant policy: this change only removes folds. A tree-order source that an excluded module reads is no longer folded, so no new fold is qualified. Neutrality is covered on real vendored-port models: Falcon parallel with MLP, attention and qkv excluded, and Qwen3-Next with the router excluded. Cohere and Qwen3.5-text on the declaration path are covered as guards. The full-model logits are measured with non-uniform scales (table above), and every test asserts which groups survive. A real CPU AWQ run on Falcon confirms the processor no longer divides the norm and that
query_key_valuetakes the configured fallback. Chunk parity and rollback are untouched (no search or replay change). Only the planner's response to a missing feature changed.Logic Flow Documentation
Diagram summary: not applicable. The planner's selection order is unchanged. One branch, "block without a captured feature", now keeps the block in its source's group instead of skipping it, and the contract is recorded as rule 7 in
docs/awq-scaling-groups.md.Review Requirements
Kernel Accuracy Requirements
Notes
base.py/awq_processor.py); the CPU suite (1680 passed, 3 skipped), the new test andawq_fold_inventory.py --check(changed: none) were rerun on the rebased head. The sweep, numeric table and GPU A/B ran against base 44aa0f9.defaultconfig variants do not build on meta in the inventory harness (they areerrorentries in the committed fold inventory too); each of those 18 types is still covered through another variant (parity,released, ...). Data-dependent outcomes (starved experts, empty captures) are outside the meta sweep.🤖 Generated with Claude Code