Repository navigation
refactor(models): delete AWQ group overrides that the role rules make redundant (batch A) - #6493
Merged
Merged
Conversation
… redundant (batch A) Since #6480 these definitions plan AWQ groups from their fold declarations (canonical_awq_folds plus awq_folds), and their awq_get_modules_for_scaling post-filters mostly guarded against the old tree tracker's stale fallbacks. Deleted (no replacement; the role-derived folds never emit what they strip): * baichuan, llada2, spark2_5: o_proj/dense/out_proj never joins a norm group, and the packed QKV projection never matches o_proj's width. * gemma3n (text and composite): input_layernorm and v_proj are `nosrc`, so no attention group exists for the KV-shared retarget to act on. * gemma4/gemma4_unified: _retarget_attention_output_folds. v_proj is `nosrc`, so no group targets o_proj. The four overrides keep only retarget_kv_shared_attention_groups (KV-shared q_proj boundary). Replaced by data or a fold-declaration variant: * deepseek_v2: `nosrc` on kv_a_proj_with_mqa and kv_b_proj instead of dropping o_proj groups. Without it a config with kv_lora_rank + qk_rope_head_dim == heads * v_head_dim (tests/test_awq_mla_scaling.py's tiny config) would fold kv_a_proj_with_mqa into o_proj. * k2_horizon: `nosrc` on the attention v_proj instead of stripping o_proj (MHA widths would add v_proj -> o_proj) and `postnorm` on q_norm/k_norm instead of re-pinning the attention group to input_layernorm (with heads * head_dim == hidden_size the norm walk would pick q_norm). The override keeps only the MoVA rule (no input_layernorm group when v_router is present). * lfm3, raon1_mini: awq_fold_declarations keeps the input-norm folds only (lfm3 also drops operator_norm on attention layers). lfm3_vl keeps the base declarations it reached before. Kept, because removing them changes the pinned plan: decilm (fold order and per-feature kwargs), qwen (per-feature kwargs), solar_open2 (tiny_mha would gain v_proj -> o_proj), deepseek_vl_v2 and xing4_0 (leaving the tracker drops their drop:width groups; that opt-out needs a maintainer decision). k2_horizon and gemma4 keep node-level overrides: a declaration override would switch their routed experts to the declared-path empty-capture contract. tests/module_tree/awq_fold_inventory.py --check reports no change for all 210 types. New regressions pin the coincident-width MLA config and K2 MHA, q/k-norm and MoVA layouts; Raon's negative control now builds the default folds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 30, 2026 10:29
5 tasks done
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
… fold-declaration variants (batch B) Since #6480 a definition without `awq_groups_from_tree_order` plans its AWQ groups from `awq_fold_declarations(layer)`. Its config-conditional `awq_get_modules_for_scaling` post-filters become small variants of the derived folds: * llama: `awq_fold_declarations` returns `[]` for LongLLaMA, StableLM-Epoch, Yi and q/k-norm Cohere/StableLM, else `super()`. * telechat2: drops the two norm folds in post-layernorm residual mode. The `key_value` filter is moved into the tree as `key_value:0:nosrc` (the derived folds never use it: it has no `v` role). * hymba: drops a gateless (relu2) expert's `up_proj -> down_proj` and declares the input-norm fold's replay boundary as `mamba.in_proj` instead of rewriting `module2inspect`. * k2_horizon: drops the input-norm fold on MoVA layers. * gemma4, gemma4_unified (text and composite): `retarget_kv_shared_attention_groups(nodes)` becomes `kv_shared_attention_folds(layer, folds)`, which replays a KV-shared layer's input-norm fold on `self_attn.q_proj` alone. * ovis2_6_moe: deleted. It only called `BaseQModel.awq_get_modules_for_scaling` past Ovis2_5QModel, which no longer overrides it. `_awq_nodes_from_declarations` chose the empty-capture contract by class identity (`type(self).awq_fold_declarations is BaseQModel...`), so any variant would have moved a routed expert's empty `down` capture from the processor's starved-member fallback (#4675) to a skip (#5995). That would have changed Hymba's and Gemma 4's MoE layers, and it is why #6493 kept the K2-Horizon and Gemma 4 node filters. The contract is now the declared `awq_hand_declared_folds` flag, set by the two definitions that write their own folds (PanGu, Inkling); a filter of the derived folds keeps the derived contract. Kept, because removing them changes behaviour or needs a maintainer decision: bloom, chatglm, dbrx_converted, rw, ricursive and nemotron_h still plan from the tree tracker and have drop:width groups (leaving the tracker drops them); nanbeige stays on the tracker for its qk_layernorm tracker gap; kimi_k3's NotImplementedError is a fail-closed guard, not a group filter; cohere_compass re-prepares kwargs until PR 10. raon1_mini was converted in #6493 and the deepseek_v4 MTP override was removed with #6435. `tests/module_tree/awq_fold_inventory.py --check` reports no change for all 210 types; a stress and data-dependent A/B (MHA and coincident-width variants, unrouted experts, absent and empty captures) is equal on all 210 types, and a GPU AWQ A/B is bit-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
… fold-declaration variants (batch B) (#6636) Since #6480 a definition without `awq_groups_from_tree_order` plans its AWQ groups from `awq_fold_declarations(layer)`. Its config-conditional `awq_get_modules_for_scaling` post-filters become small variants of the derived folds: * llama: `awq_fold_declarations` returns `[]` for LongLLaMA, StableLM-Epoch, Yi and q/k-norm Cohere/StableLM, else `super()`. * telechat2: drops the two norm folds in post-layernorm residual mode. The `key_value` filter is moved into the tree as `key_value:0:nosrc` (the derived folds never use it: it has no `v` role). * hymba: drops a gateless (relu2) expert's `up_proj -> down_proj` and declares the input-norm fold's replay boundary as `mamba.in_proj` instead of rewriting `module2inspect`. * k2_horizon: drops the input-norm fold on MoVA layers. * gemma4, gemma4_unified (text and composite): `retarget_kv_shared_attention_groups(nodes)` becomes `kv_shared_attention_folds(layer, folds)`, which replays a KV-shared layer's input-norm fold on `self_attn.q_proj` alone. * ovis2_6_moe: deleted. It only called `BaseQModel.awq_get_modules_for_scaling` past Ovis2_5QModel, which no longer overrides it. `_awq_nodes_from_declarations` chose the empty-capture contract by class identity (`type(self).awq_fold_declarations is BaseQModel...`), so any variant would have moved a routed expert's empty `down` capture from the processor's starved-member fallback (#4675) to a skip (#5995). That would have changed Hymba's and Gemma 4's MoE layers, and it is why #6493 kept the K2-Horizon and Gemma 4 node filters. The contract is now the declared `awq_hand_declared_folds` flag, set by the two definitions that write their own folds (PanGu, Inkling); a filter of the derived folds keeps the derived contract. Kept, because removing them changes behaviour or needs a maintainer decision: bloom, chatglm, dbrx_converted, rw, ricursive and nemotron_h still plan from the tree tracker and have drop:width groups (leaving the tracker drops them); nanbeige stays on the tracker for its qk_layernorm tracker gap; kimi_k3's NotImplementedError is a fail-closed guard, not a group filter; cohere_compass re-prepares kwargs until PR 10. raon1_mini was converted in #6493 and the deepseek_v4 MTP override was removed with #6435. `tests/module_tree/awq_fold_inventory.py --check` reports no change for all 210 types; a stress and data-dependent A/B (MHA and coincident-width variants, unrouted experts, absent and empty captures) is equal on all 210 types, and a GPU AWQ A/B is 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
AWQ lifecycle step 5, batch A (map
awq_lifecycle.md, PR 5). Since #6480, most of these definitions build their AWQ groups from fold declarations (canonical_awq_foldsplusawq_folds). Theirawq_get_modules_for_scalingpost-filters were written against the old tree tracker's stale fallbacks. This PR deletes the filters the role rules make redundant. Where a filter still mattered for some config, it is replaced by tree data (:nosrc,:postnorm) or a smallawq_fold_declarationsvariant. Five overrides stay, because removing them changes the pinned plan.Behavior-preserving:
awq_fold_inventory.py --checkreportschanged: nonefor all 210 types.The meta inventory alone was not sufficient. Two filters that the map listed as redundant only matter on configs the inventory does not build:
kv_lora_rank + qk_rope_head_dim == heads * v_head_dim, deleting the filter would foldkv_a_proj_with_mqaintoo_proj.tests/test_awq_mla_scaling.py's tiny config has exactly this layout.query_key_norm: whenheads * head_dim == hidden_size, the norm walk picksq_norminstead ofinput_layernorm. The existingtest_k2_horizon_local_port.py::...[qknorm]neutrality test caught this.Both cases are now tree data and have regression tests.
What Changed
126e83fb3)baichuanawq_get_modules_for_scalingstripso_proj(baichuan.py:31)W_pack -> o_projis never width-equal (3h vs h), and the presentW_packblock stops the norm walkllada2attention.dense(llada2.py:45)query_key_valuenordensehas a role, andquery_key_valuestops the norm walkspark2_5out_proj(spark2_5.py:48)q_k_v_proj/out_projhave no role)gemma3n,gemma3n_textretarget_kv_shared_attention_groups(gemma3n.py:279, 350)input_layernormandv_projarenosrc, so no attention group existsgemma4*,gemma4_unified*(4 classes)_retarget_attention_output_folds+ KV-shared retarget (gemma4.py:86, 357, 450; gemma4_unified.py:128, 181)_retarget_attention_output_foldsdeleted:v_projisnosrc, so no group targetso_proj. The KV-sharedq_projboundary retarget staysdeepseek_v2o_proj(deepseek_v2.py:13)kv_a_proj_with_mqaandkv_b_projare:nosrc(latent-norm folds are never derived)k2_horizono_proj, re-pins q/k/v/gate toinput_layernorm, drops that group on MoVA layers (k2_horizon.py:138)v_proj:nosrc,q_norm/k_norm:postnorm. The override keeps only the MoVA rule (3 lines)lfm3,lfm3_omniffn_norm(+operator_normon conv layers) (lfm3.py:85)awq_fold_declarationsvariant.lfm3_vlsetsawq_fold_declarations = BaseQModel.awq_fold_declarations, the default it reached beforeraon1_minio_proj(raon1_mini.py:69)awq_fold_declarationsvariant that keeps the two norm sourcesAlso:
tests/module_tree/test_awq_fold_inventory.py: thelfm3,lfm3_omniandraon1_minientries are removed fromAWQ_FOLD_DIFFERENCES, because their declarations now equal the effective plan.docs/awq-scaling-groups.md: twonosrctable rows and one sentence on the new declaration variants._kv_shared_replay.py: the docstring no longer describes the tracker.Kept, with the reason (each removal was tried;
--checknames the type as changed):decilm.py:34(deci,nemotron-nas)v_proj -> o_projmoves before the MLP folds, and the linear groups carry per-feature kwargs instead of the layer kwargs (alreadyTRACKER_PLANNED)qwen.py:24w1 -> c_projgroup would carryc_proj's per-feature kwargs (alreadyTRACKER_PLANNED)solar_open2.py:92tiny_mhawould gainv_proj -> o_proj(canonical-unsafe; alreadyTRACKER_PLANNED)deepseek_vl_v2.py:120,xing4_0.py:86kv_b_proj -> o_projdrop:width group, which needs the maintainer decision on those 66k2_horizonand the fourgemma4classes keep a node-levelawq_get_modules_for_scalingrather than a declaration variant on purpose. Overridingawq_fold_declarationsswitches a definition to the declared-path empty-capture contract (base.py:7333): a routed expert's emptydowngroup would be skipped instead of reaching the starved-member fallback. Both families have routed experts.Out of scope: batch B/C (PR 6/7). That includes lfm3_vl's explicit
v_proj -> o_projoverride and raon1_mini in PR 6's list (its whole override is gone here).Tests
New/changed tests:
tests/test_awq_mla_scaling.py::test_mla_scale_groups_only_contain_consumers_of_the_fold_source: also asserts that no group targetso_projon its coincident-width config.tests/test_k2_horizon_support.py::test_k2_horizon_awq_attention_groups_with_mha_widths[dense|qknorm|mova]: with MHA widths and hidden-width q/k norms, the attention group's source isinput_layernormwith q/k/v/gate (none on MoVA), and no group targetso_projor usesq_norm/k_norm.Both pass on origin/main and on this branch. They fail on this branch without the new
nosrc/postnormflags (2 failed / 1 passed each time).tests/module_tree/test_awq_raon1_mini_neutrality.py::test_raon_dropped_generic_folds_are_not_neutral: the negative control now builds the role-derived default folds (BaseQModel.awq_fold_declarations) directly, sinceBaseQModel.awq_get_modules_for_scalingapplies Raon's variant.Measured Impact
Not applicable: no claimed issue. E3 is bit-identical.
Model Support / Module Plan
Not applicable: no
MODEL_MAPentry, path, tag or fusion change. The new:nosrc/:postnormflags are AWQ source metadata only: the block compiler drops them from block names, and onlyawq_folds.py,fold_rules.pyand the tracker read them.tests/module_tree/test_registered_module_plans.pyandtest_definition_subset_ordering.pypass (in E2).AWQ onboarding safety
No grouping changes. Every touched type's effective plan equals main's on:
k_eq_v;dynamic), 20% empty, MoE root empty; 3 seeds.The per-variant AWQ policy is unchanged from main. The existing native neutrality tests pass unchanged:
test_awq_raon1_mini_neutrality.py,test_k2_horizon_local_port.py::test_awq_scale_folds_preserve_dense_moe_and_mova_layer_outputs[*],test_awq_scaling_groups.py(lfm3, gemma4, gemma4_unified, k2_horizon, deepseek_v2 families),test_awq_shared_kv_states_replay.py, and the lfm3/llada2/spark2_5/baichuan/deepseek_v2 local ports.Structural stress A/B (
ab_stress.py, scratch):+mhacopy of each (num_key_value_heads = num_attention_headsin every sub-config), the coincident-width DeepSeek-V2 MLA config (q_lora and lite), and Gemma4 KV-shared +k_eq_v.cases=55 equal=55 differ=0(llada2_moe's bare default needsllada_versionand fails to build on both sides; itsmini/flashvariants build).deepseek_v2/mla_coincident*and on everyk2_horizon/*+mhacase.Logic Flow Documentation
file:lineevidence (What Changed).docs/repeats the diagrams, titled for the mechanism, and is linked fromREADME.md(docs/awq-scaling-groups.md, flow unchanged from refactor(awq): build scaling groups from fold declarations; the tree tracker stays only as the test oracle #6480; this PR updates its declaration andnosrcsections).The decision mechanism changes from "post-filter the planner's nodes per model" to "declare the source eligibility in the tree, or filter the declarations":
flowchart TD A["awq_get_modules_for_scaling"] --> B["awq_fold_declarations(layer)"] B -- "default" --> C["canonical_awq_folds<br/>_find_norm skips :postnorm (k2 q_norm/k_norm)<br/>_linear_edges skips :nosrc (k2 v_proj, dsv2 kv_a/kv_b)"] B -- "lfm3 / raon1_mini variant" --> D["super().awq_fold_declarations<br/>keep input-norm sources"] C --> E["_awq_nodes_from_declarations<br/>declared_fold, merge_by_source"] D --> E E -- "malformed" --> X["raise AWQFoldDeclarationError"] E -- "no capture" --> Y["skip group<br/>targets quantize plainly"] E --> F["_filter_awq_scaling_sources"] F --> G{"definition post-filter left?"} G -- "k2_horizon MoVA" --> H["drop input_layernorm group"] G -- "gemma4 KV-shared" --> I["retarget_kv_shared_attention_groups<br/>q_proj boundary"] G -- "none" --> J["AWQProcessor._quantize_layer"] H --> J I --> J style X fill:#f8d7da,stroke:#842029,stroke-width:2px style Y fill:#fff3cd,stroke:#997404,stroke-width:2pxReview Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, pack or dispatch change. E3 shows identical packed tensors.
Notes
E3 (GPU A/B).
AWQConfig(bits=4, group_size=128), 64 wikitext rows, seed 0, bf16, origin/main126e83fb3vs this branch on the same GPU. Every safetensors tensor is compared bytewise, plus the json files andquant_log.csvwithout the time columns:_retarget_attention_output_foldsdeleted)The Gemma-3n and Gemma-4 branch runs used
e3610f939, the pre-rebase head. The Gemma3 branch run used the same tree minus the later K2postnorm/test edits, which touch no Gemma code.Gemma-4-E2B's KV-shared layers plan
input_layernorm -> self_attn.q_projalone, so the retained retarget is exercised. Not run: the other touched families (no small cached checkpoints: baichuan, llada2, spark2_5, deepseek_v2, k2_horizon, lfm3, raon1_mini). For those, the structural and perturbation A/B plus their native CPU tests are the evidence.Net lines.
17 files changed, 106 insertions(+), 258 deletions(-)(−152). Production code plus docs (gptqmodel/,docs/):13 files changed, 50 insertions(+), 246 deletions(-). Most of the remaining additions are the two regression tests.The known
dynamic-exclusion shared-norm fold on the tracker path (refactor(awq): build scaling groups from fold declarations; the tree tracker stays only as the test oracle #6480 Notes) is untouched: no tracker type changes here.🤖 Generated with Claude Code