Skip to content

refactor(awq): build scaling groups from fold declarations; the tree tracker stays only as the test oracle - #6480

Merged
Qubitium merged 2 commits into
mainfrom
refactor/awq-groups-from-declarations
Nov 30, 2026
Merged

Qubitium merged 2 commits into
mainfrom
refactor/awq-groups-from-declarations

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

AWQ lifecycle step 4b (map awq_lifecycle.md, PR 4b). BaseQModel.awq_get_modules_for_scaling now builds the processor's scaling nodes from awq_fold_declarations(layer). That method's default is the module plan's role-derived folds plus the definition's awq_folds data (canonical_awq_folds, merged in #6446/#6470). For 118 of 210 MODEL_MAP types, production no longer runs the backward prev-op tracker (_awq_generic_get_modules_for_scaling). The declared path (PanGu, Inkling2-Loop) also stops re-running it to borrow a feature, kwargs and replay module.

The tracker stays for two uses: as the test oracle, and for the 92 types that keep it through the declared opt-out awq_groups_from_tree_order = True. Their declarations cannot yet reproduce today's groups byte-for-byte (below). No per-model function was added.

Behavior-preserving on the measured surface:

  • E1: the fold inventory, extended first to record every node field the processor consumes, is byte-equal for all 210 types (--check: changed: none).
  • E3: AWQ quantize A/B gives bit-identical tensors on all 7 models run (dense, MoE, VL and hybrid).
  • Data-dependent oracle: one reachable difference remains, under a dynamic exclusion. There main has a fold bug that this PR does not fix (see Notes).

What Changed

Who keeps the tracker, and why (each is a TRACKER_PLANNED entry or the width-drop rule in tests/module_tree/test_awq_fold_inventory.py)

Divergence if planned from declarations Types
Declarations add self_attn.v_proj -> o_proj: the tracker loses it behind a :! leaf. Adopting it changes numerics. afmoe (plus dense layer 0 pre_mlp_layernorm -> mlp), apertus, apertus1p5, apertus1p5_text, bailing_hybrid, exaone4_5, glm5_next, hrm_text, mage_vl, mimo_v2, qwen3_vl, qwen3_vl_moe
Declarations add self_attn.v_proj -> o_proj on a variant the AWQ unit tests build (now in the inventory) nanbeige (qk_layernorm), minimax (MHA), solar_open2 (tiny MHA; canonical-unsafe: o_proj reads a gated output)
Declarations add the DeltaNet input_layernorm -> in_proj_qkv, in_proj_z fold qwen3_5, qwen_drive, sensenova_loop
The awq_folds data fold attn.attention.v_proj -> out_proj raises on a GQA layout: data folds are not width-gated yet exaone (gqa)
Its phi-2 backbone needs self_attn.v_proj -> dense, which no role names and awq_folds cannot declare for one backbone only (found by tests/module_tree/test_openvla_local_port.py) openvla
Declarations add the linear-attention input, v -> o and dense MLP folds olmo_hybrid
qwen.py's override appends w1 -> c_proj with layer kwargs; the awq_folds fold carries c_proj's per-feature kwargs qwen
decilm.py's override re-appends v -> o and up -> down: duplicate source raises deci, nemotron-nas
Only the tracker's drop:width groups (width-mismatched Linear->Linear guesses such as fused QKV -> dense, GQA v -> o, MLA latents) disappear 66 types: bloom, chatglm, dbrx_converted, deepseek_v3/v32, deepseek_vl_v2, dots3_note, ernie4_5_moe(_vl), ernie4_5_vl_moe, falcon, falcon_h1, flint, glm, glm4, glm4_moe(_lite), glm4v(_moe, _moe_text), glm_ocr, glmasr, gpt_bigcode, gpt_neox, gpt_oss, granitemoehybrid, grinmoe, internlm2, jamba, kimi_k2, kimi_k25, lfm2(_moe, _vl), llama4(_text), mimo_v2_flash, minicpm3, minicpmv, minicpmv4_6, minimax_m2, minimax_m3_vl, ministral3, mistral3, mixtral, mllama(_text_model), moss, mpt, nemotron_h, nemotronh_nano_omni_reasoning_v3, phi3, phimoe, qwen2_5_omni, qwen2_5_vl(_text), qwen2_vl(_text), qwen3_next, qwen3_omni_moe, refinedWeb, refinedWebModel, ricursive, starcoder2, voxtral, xing4_0
Inherited or shared class (byte-equal under full features) bailing_moe (shares BailingMoeQModel), nemotron_h_puzzle (inherits NemotronHQModel; its expert-0-unrouted split also differs, below)

Tests

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

New or changed tests:

  • tests/module_tree/test_awq_fold_inventory.py::test_tracker_planned_cases_still_need_the_tracker[*]: re-plans every opted-out case from declarations. A listed case must still change an effective group. Any other case of an opted-out definition may differ only by its drop:width groups. So the opt-out list can only shrink.
  • test_current_planner_matches_inventory[*] now also pins partial_replay, inp, kwargs and keys.
  • tests/module_tree/test_awq_fold_declarations.py::test_default_declaration_is_the_role_derived_fold_set replaces the None-keeps-generic test. On a layer computing out(left(norm(x))) + right(norm(x)), the tracker emits left -> right and right -> out, neither of which reads that output. The default emits norm -> left only, and the opt-out restores the tracker.
# CPU, PYTHONPATH=<clone>, HF_HUB_OFFLINE=1, CUDA_VISIBLE_DEVICES=
# E2 set: the onboarding baseline plus every test touching the planner, fold_rules, declarations or
# awq_get_modules_for_scaling (214 files), minus 3 model-scale GPU e2e files
# (test_awq_gemv.py, test_awq_moe.py, test_awq_marlin.py)
cd tests && python -P -m pytest -q -p no:cacheprovider -n 64 -rfEs $(cat e2_files.txt)
# rebased branch: 2 failed, 4901 passed, 208 skipped in 202s
#   FAILED test_awq_weight_mean.py::test_awq_pseudo_quantize_nan_guard_uses_one_host_read  (also fails on main; known)
#   FAILED test_deepseek_vl_v2_local_port.py::test_processor_image_forward_cache_generation_and_calibration[tail-2D-True]
#     (a generation-cache equality under xdist load; deepseek_vl_v2 stays on the tracker; passes alone on both sides
#      (8 passed) and passed in the pre-rebase branch run)
#   skips: 195 need CUDA/ROCm/an accelerator kernel; 13 others (BitBLAS absent, MiniCPM-o extra, Unlimited-OCR asset
#   needs network, native AWQ extension, 2 opt350/muse_glimmer not buildable, 2 ricursive sliding_window==1)
# main c37c3f12e (same files): 1 failed (the same NaN-guard test), 4902 passed, 208 skipped
# Not run: test_awq_gemv.py, test_awq_moe.py, test_awq_marlin.py (model-scale GPU e2e; with CUDA hidden they
#   quantize real checkpoints on CPU for hours on both sides)

# onboarding baseline (included above)
python -P -m pytest -q 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            # all pass

# E1
HF_HUB_OFFLINE=1 python -P tests/module_tree/awq_fold_inventory.py --check   # changed: none (210 types), on the branch
#   and on main's code with this fixture (the guard)
python -P -m pytest -q -n 64 tests/module_tree/test_awq_fold_inventory.py      # 764 passed
bash format/check.sh                                                          # All checks passed!

Measured Impact

Not applicable (no claimed issue). E3 is bit-identical; wall-clock and peak memory are in the A/B logs below.

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, path, tag or fusion change. Definitions only gain the opt-out attribute. tests/module_tree/test_registered_module_plans.py and test_definition_subset_ordering.py pass (in E2).

AWQ onboarding safety

No new grouping: every type's effective plan is unchanged (E1). This includes every node field the processor reads, and the scaling-group/neutrality suites pass unchanged (E2). Per-variant AWQ policy is unchanged from main.

Data-dependent oracle. perturb2.py runs origin/main and the branch, each in its own interpreter, over 210 types, every config variant and each distinct layer, with 3 seeds per perturbation: 4714 plans.

Perturbation Reachable in a real run? Result
full features yes equal everywhere
half the routed experts unrouted (empty captures) yes equal everywhere
20% of modules absent (dynamic exclusion) only with dynamic differs for 7 types. (C1) agnes, qwen3_5_moe(_text), zdtaichu5_0: main folds the norm into the remaining members and leaves the excluded co-reader uncompensated (bug, Notes); the branch keeps it in the group, so the processor's coverage check skips the fold. (C2) agnes, qwen3_5_text, raon1_mini, intern_s2_preview: neither folds, but main and branch disagree on whether the remaining members use the configured fallback strategy or plain quantization.
20% of modules empty no: every differing case empties an always-executed attention, shared-expert, dense-MLP or in_proj_z capture differs (unverified, unreachable)
MoE root empty, experts captured no: the #4697 missing-hook state differs (unverified, unreachable)

Logic Flow Documentation

  • The required diagrams and docs page are included below.
  • New-flow Mermaid diagram(s) describe the shipped code using real symbol names.
  • The removed/replaced mechanism is tabulated with file:line evidence.
  • Failure and ambiguity paths are marked and visually distinct from success.
  • A reference page under docs/ repeats the diagrams, titled for the mechanism, and is linked from README.md (docs/awq-scaling-groups.md).
flowchart TD
    A["awq_get_modules_for_scaling"] --> B{"awq_groups_from_tree_order?"}
    B -- "no" --> C["awq_fold_declarations(layer)<br/>default: canonical_awq_folds + awq_folds"]
    C --> D["_resolve_awq_fold_declarations<br/>declared_fold per fold"]
    D -- "malformed" --> E["raise AWQFoldDeclarationError"]
    D --> F["merge_by_source<br/>boundary and span_roots"]
    F --> G{"search input captured?<br/>MoE root or first branch"}
    G -- "no" --> H["skip group<br/>targets quantize plainly"]
    G -- "yes" --> I["generate_node_for_awq_scaling<br/>feature, kwargs, boundary"]
    B -- "yes" --> T["_awq_generic_get_modules_for_scaling<br/>tree-order tracker"]
    T --> M["_merge_shared_source_nodes"]
    I --> O["_filter_awq_scaling_sources"]
    M --> O
    O --> S["AWQProcessor._quantize_layer"]
    style E fill:#f8d7da,stroke:#842029,stroke-width:2px
    style H fill:#fff3cd,stroke:#997404,stroke-width:2px
Loading
Decision origin/main (888959022) This PR
Default source of groups awq_fold_declarations returns None (base.py:7141), so the tracker runs (awq_get_modules_for_scaling, base.py:7375 -> _awq_generic_get_modules_for_scaling, base.py:7385) awq_fold_declarations returns canonical_awq_folds(...) (base.py:7145); the tracker runs only for awq_groups_from_tree_order (base.py:1722, 7336)
Declared folds' feature, kwargs, replay module borrowed from a full tracker run (base.py:7274) derived from the fold: merge_by_source boundary, first-branch or MoE-root feature (base.py:7263)
Validation declared_fold for overrides only; nn.Linear targets; no cross-branch fold declared_fold for every fold; [out, in] targets; span_roots with a boundary (fold_rules.py:171, 187)
Parallel-branch span _merge_shared_source_nodes sets _awq_search_layers/_awq_allow_outside_fold (base.py:8068) span_roots from merge_by_source sets the same node keys

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel, pack or dispatch change (E3 shows identical packed tensors).

Notes

  • Equivalence evidence.

    • E1: HF_HUB_OFFLINE=1 python -P tests/module_tree/awq_fold_inventory.py --check gives changed: none (210 types).
    • E3, GPU AWQ A/B with AWQConfig(bits=4, group_size=128), 64 wikitext rows, seed 0, origin/main vs branch on the same GPU, every safetensors tensor compared bytewise plus the json and quant_log.csv files:
    Model (type, planner on this branch) Tensors Result Peak CUDA MiB main / branch
    Qwen/Qwen2.5-0.5B-Instruct (qwen2, declarations) 626 bit-identical 387 / 387
    unsloth/Llama-3.2-1B-Instruct (llama, declarations) 370 bit-identical 754 / 754
    allenai/OLMoE-1B-7B-0924 (olmoe MoE, declarations) 9491 bit-identical 1509 / 1569
    Qwen/Qwen1.5-MoE-A2.7B (qwen2_moe, shared expert, declarations) 13635 bit-identical 1984 / 2143
    unsloth/gemma-3-4b-it (gemma3 VL, declarations) 1359 bit-identical 2085 / 2085
    unsloth/gemma-3n-E2B-it (gemma3n hybrid VL with override, declarations) 2026 bit-identical 880 / 880
    FlameF0X/TinyMoE-100m-2x8-retrained (mixtral, tracker opt-out; sanity) 873 bit-identical 313 / 313

    All runs are on the rebased head against c37c3f12e. A first round against 888959022 was also bit-identical for all seven. Peak memory on the two MoE models varies between runs on both sides (Qwen1.5-MoE main 2017 then 1984 MiB; branch 2105 then 2143). No measurable VRAM claim is made. Not run: Qwen3-30B-A3B (cached but too large for a modest-memory lane), Qwen2.5-VL-3B and Granite-4.0-H-350m (cached, but qwen2_5_vl and granitemoehybrid stay on the tracker, so the A/B would only exercise main's code), and Qwen3.5 (qwen3_5 is opted out).

  • Real bug on main, left alone. Suppose dynamic excludes a module that reads a norm shared with a quantized block of another tree block: cohere/stablelm's parallel MLP, qwen3.5-family linear_attn.in_proj_z, or intern_s2_preview's shared expert. The tracker skips the excluded block and folds the norm into the remaining members with status ok. The excluded module still reads the norm and is not compensated, so the layer output changes. For example, with cohere and mlp.* excluded, main folds input_layernorm -> q/k/v only. The branch keeps the excluded targets in the group, so the processor's coverage check falls back instead of folding. Preserving main here would mean re-implementing the tracker's per-block state (block features, block-local consumers, block boundaries) inside the new builder, so this is the one reachable divergence. It should get its own issue and fix; the safe fix compensates excluded readers as consumers.

  • Junk-only opt-outs. For 66 types the declarations already reproduce every group the processor folds. They differ only by the tracker's drop:width groups, which check_layer drops. Those groups matter only before the drop, where the fallback policy can send a starved member to the configured fallback. With the default 0.5% threshold that cannot happen for these always-executed dense projections. Moving these types is a one-line removal each plus a fixture regeneration that deletes exactly those rows, once the maintainer accepts that, or after a processor change that checks the width DROP before the fallback policy.

  • Two empty-capture contracts. The derived default keeps a routed expert's empty down capture (the tracker's MoE-down branch). A definition's own awq_fold_declarations skips it (main's declared path, Declare AWQ fold sources and consumers per layer variant #5995). Both are preserved here (base.py:7281); unifying them is a behavior PR.

  • Net lines. Planner code shrinks by 40 lines (base.py, awq_folds.py, fold_rules.py: +92/-132). The PR as a whole grows (80 files changed, 598 insertions(+), 238 deletions(-), fixture included) because the tracker must stay as the oracle and opt-out, and the 92 opt-outs are data lines (157 in 71 definition files). PRs 5-8 remove them together with the tracker.

  • refactor(awq): share the planner's width predicates and feature-kwargs merge #6476 (shared planner predicates) merged while this was in progress. The branch is rebased onto it (no conflicts), and E1/E2/E3 were rerun against c37c3f12e. The head is then rebased onto 522e4c0c9. fix(awq): validate the plan path's sampled-row cache against the live host copy #6479 touches only awq_processor.py's sampled-row cache, not this PR's files; the onboarding baseline, the declaration tests and fix(awq): validate the plan path's sampled-row cache against the live host copy #6479's test_awq_reservoir_sibling_rows_5267.py pass on the final head (787 passed, 2 skipped).

🤖 Generated with Claude Code

Qubitium and others added 2 commits November 30, 2026 05:47
…the fold inventory

The meta inventory pinned source, targets, consumers, boundary, feature,
search members and span_roots, but not the other node fields
AWQProcessor._quantize_layer reads: `_awq_allow_partial_replay` (set by
phi4mm's override), which input tensor `inp` is, which feature's kwargs a
group replays with, and any extra key that reaches _search_best_scale.

layer_plan now hands the planner one kwargs marker per feature and records
`partial_replay`, `inp` and `kwargs` (when they are not the group's own
feature) and `keys` (unknown node keys). Four config variants the AWQ unit
tests exercise but the inventory did not are added (nanbeige qk_layernorm,
minimax MHA, exaone GQA, solar_open2 tiny MHA).

The fixture is regenerated on unchanged production code; the new fields
appear for phi4mm (partial replay), cohere_compass (re-prepared
position_embeddings), deci, nemotron-nas and qwen (override-built nodes
without per-feature kwargs) and nemotron_omni (feature renamed to the MoE
block). No previously recorded group changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tracker stays only as the test oracle

BaseQModel.awq_get_modules_for_scaling now builds the processor's scaling
nodes from awq_fold_declarations(layer), whose default is the module plan's
role-derived folds plus the definition's awq_folds data
(canonical_awq_folds). The tree-order backward tracker
(_awq_generic_get_modules_for_scaling) no longer runs for those
definitions, and the declared path no longer re-runs it to borrow a
feature, kwargs and replay module:

* every fold is validated by fold_rules.declared_fold before mutation;
  a target may be any quantized module applying an [out, in] weight
  (Qwen3-Next's AWQ tree quantizes its router), and a fold that spans
  sibling branches of its declared boundary is legal;
* merge_by_source supplies the replay boundary; a span_roots fold scores
  the targets inside it and folds the rest (#4741), as
  _merge_shared_source_nodes did;
* the search input is the first captured target of the fold's first
  branch, or the MoE root capture for gate/up groups (#4697/#4760/#4903);
  the derived default keeps a routed expert's empty down capture for the
  processor's starved-member fallback (#4675), declared overrides skip it
  (#5995), as on main.

A definition whose declarations do not yet reproduce its effective groups
sets awq_groups_from_tree_order = True and keeps the tracker (92 of 210
types): 24 whose declarations change an effective group (tracker-gap
v -> o and DeltaNet folds, canonical-unsafe v -> o on gated attention,
exaone's GQA data fold, openvla's phi-2 backbone, qwen.py's kwargs,
decilm.py's duplicates), 66 whose only difference is the tracker's
width-mismatched drop:width groups, which the processor drops but which
can still route a starved member to fallback, plus bailing_moe and
nemotron_h_puzzle through their class.
test_tracker_planned_cases_still_need_the_tracker re-plans them from
declarations, so the list can only shrink. The per-model
awq_get_modules_for_scaling overrides still call super() and post-filter.

The fold inventory (now recording every node field the processor reads)
is unchanged for all 210 types: inventory --check reports no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium marked this pull request as ready for review November 30, 2026 05:49
@Qubitium
Qubitium merged commit 44a08b8 into main Nov 30, 2026
6 checks passed
@Qubitium
Qubitium deleted the refactor/awq-groups-from-declarations branch November 30, 2026 05:49
Qubitium added a commit that referenced this pull request Nov 30, 2026
… redundant (batch A) (#6493)

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 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]>
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.

1 participant