Repository navigation
refactor(models): declare non-canonical AWQ folds as data - #6470
Merged
Merged
Conversation
Eight definitions fold a projection the role-derived default (`canonical_awq_folds`) cannot name: an output projection without an o role (`out_proj`, `dense`), an MLP whose linear branch has no up role (OPT `fc1 -> fc2`, ExaOne `c_fc_1 -> c_proj`, Qwen-1 `w1 -> c_proj`), and the Granite-4 hybrid Mamba gated `norm -> out_proj`, declared after its consumer. Declare each one as `awq_folds = (AWQFoldDeclaration(...),)` class data next to the module tree. `BaseQModel.awq_folds` defaults to `()`. `canonical_awq_folds(..., declared=awq_folds)` adds the declared folds to the derived ones. A fold applies to the layers that own its source (the LFM2 conv layers and Granite attention layers have none), it is emitted after the block that holds its first target, and it is merged by source. Unresolved targets and unplaceable folds raise. The boundary rule moves into `_default_boundary`, which `merge_by_source` applies to any fold without a boundary. The canonical output is unchanged for all 345 inventoried layer variants. The inventory test now compares what a definition declares: `awq_fold_declarations(layer)` when overridden (PanGu, Inkling2-Loop), otherwise canonical plus `awq_folds`. Ten AWQ_FOLD_DIFFERENCES entries are removed: exaone, gpt_neo, gptj, gpt_pangu, opt, phi, lfm2_moe, qwen, granitemoehybrid and inkling2_loop. phi4mm stays listed with a precise reason: its override also sets `_awq_allow_partial_replay`, which a declaration cannot express. Nothing in production reads `awq_folds` yet. The AWQ planner and the inventory fixture are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 30, 2026 02:59
12 tasks done
Qubitium
added a commit
that referenced
this pull request
Nov 30, 2026
…d teardown Rebased fix/6148-issue onto origin/main 94ceaf7 (after #6464, #6465, #6467, #6469, #6470). Three conflicts: - gptqmodel/looper/forward_executor.py: import block. Main dropped the unused resolve_calibration_keep_mask import; kept only the PR's replay_records import. - gptqmodel/looper/module_looper.py: #6465 moved the failed-run teardown into InflightLayerTracker (inflight_layer.py). Kept main's structure and re-applied the PR's release_looped_capture() as a ModuleLooper override of _release_failed_run_processors that calls super() first. - gptqmodel/models/definitions/inkling2_loop.py: #6464 reduced pre_quantize_generate_hook_start to the batch-index/bank reset plus super(); the PR removes that reset, so the override is deleted. Earlier rebase (onto 81ac176): Rebased fix/6148-issue onto origin/main 81ac176. Two conflicts: - gptqmodel/models/definitions/inkling2_loop.py: import block. Kept the PR's replay_records imports; dropped the PR's get_op_name import because main removed its last use and the rebased file does not use it. - tests/module_tree/test_inkling2_loop_plan.py: main added the AWQ declaration block where the PR deletes _capture_inkling2_forward. Kept all of main's AWQ tests, removed only the helper the PR replaced with record-owned head banks. Tests: 135 passed, 1 skipped on CPU (main baseline for the pre-existing files: 124 passed). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 30, 2026
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…d teardown Rebased fix/6148-issue onto origin/main 94ceaf7 (after #6464, #6465, #6467, #6469, #6470). Three conflicts: - gptqmodel/looper/forward_executor.py: import block. Main dropped the unused resolve_calibration_keep_mask import; kept only the PR's replay_records import. - gptqmodel/looper/module_looper.py: #6465 moved the failed-run teardown into InflightLayerTracker (inflight_layer.py). Kept main's structure and re-applied the PR's release_looped_capture() as a ModuleLooper override of _release_failed_run_processors that calls super() first. - gptqmodel/models/definitions/inkling2_loop.py: #6464 reduced pre_quantize_generate_hook_start to the batch-index/bank reset plus super(); the PR removes that reset, so the override is deleted. Earlier rebase (onto 81ac176): Rebased fix/6148-issue onto origin/main 81ac176. Two conflicts: - gptqmodel/models/definitions/inkling2_loop.py: import block. Kept the PR's replay_records imports; dropped the PR's get_op_name import because main removed its last use and the rebased file does not use it. - tests/module_tree/test_inkling2_loop_plan.py: main added the AWQ declaration block where the PR deletes _capture_inkling2_forward. Kept all of main's AWQ tests, removed only the helper the PR replaced with record-owned head banks. Tests: 135 passed, 1 skipped on CPU (main baseline for the pre-existing files: 124 passed). 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
This is step 4a of the AWQ lifecycle cleanup. Eight definitions fold a projection that the role-derived default (
canonical_awq_folds, #6446) cannot name. This PR declares those folds as plain class data,awq_folds = (AWQFoldDeclaration(...),), placed next to each definition'smodule_tree:orole:out_proj,dense;uprole: OPTfc1 -> fc2, ExaOnec_fc_1 -> c_proj, Qwen-1w1 -> c_proj;norm -> out_proj, where the norm is declared after its consumer.There are no per-model functions, no new types and no registry. The data reuses the existing
AWQFoldDeclaration.Data only. No production path reads
awq_foldsyet:--check:changed: nonefor all 210 types);canonical_awq_foldswithout data is byte-identical toorigin/mainon all 345 inventoried layer variants.The inventory test now compares what each definition declares against the effective plan. Ten
AWQ_FOLD_DIFFERENCESentries are removed.Net diff:
12 files changed, 144 insertions(+), 51 deletions(-)(+93). This step adds data, so the "net lines go down" rule does not apply.What Changed
BaseQModel.awq_folds: Tuple[AWQFoldDeclaration, ...] = ()(models/base.py:1709). It sits next to the other AWQ class attributes, away from the planner and from thecalibration_device_modulesblock.Data in 8 definitions:
awq_foldsexaone.py:38attn.attention.v_proj -> attn.attention.out_proj,mlp.c_fc_1 -> mlp.c_projgpt_neo.py:37attn.attention.v_proj -> attn.attention.out_projgptj.py:37attn.v_proj -> attn.out_projopt.py:63self_attn.v_proj -> self_attn.out_proj,fc1 -> fc2phi.py:37self_attn.v_proj -> self_attn.denselfm2_moe.py:115self_attn.v_proj -> self_attn.out_proj(anorole would also hit the convout_proj)qwen.py:123mlp.w1 -> mlp.c_projgranitemoehybrid.py:76mamba.norm -> mamba.out_projgptqmodel/models/awq_folds.py(not a production path):canonical_awq_folds(..., declared=())adds declared folds to the derived ones:ValueError, and so does a fold whose first target is in no quantized block._default_boundary.merge_by_sourceapplies it to every fold that has no boundary, so declared data does not need to repeat boundaries.tests/module_tree/test_awq_fold_inventory.py:test_canonical_folds_match_inventorycomparesawq_fold_declarations(layer)when a definition overrides it (PanGu, Inkling2-Loop), otherwisecanonical_awq_folds(..., declared=awq_folds). This is the chain a declaration-driven planner (step 4b) would consume.awq_foldssource resolves on some decoder layer, so a misspelled source cannot silently apply nowhere.test_awq_folds_resolve_strictlycovers the apply/skip/raise rules on the real LFM2-MoE parity model (attention layer plus conv layer).phi4mmstays listed, with a precise reason (see Notes).docs/awq-scaling-groups.md: one short paragraph onawq_folds.Out of scope:
qwen.pyoverride (PR 5).tracker-gapandcanonical-unsafeentries: declaring them would freeze today's gaps as data, or they neednosrcfirst.Why "canonical plus data" rather than "data replaces canonical"
The map sketched
awq_folds or canonical, where data replaces the whole derivation. I implementedcanonical + awq_foldsfor three reasons:awq_fold_declarations(layer)methods filteringsuper(), and PanGu and Inkling2-Loop already use that hook.The data shape is the same tuple of
AWQFoldDeclarationin both designs, so 4b can choose either.Tests
Environment: Python 3.14, torch 2.15.0+cu132, transformers 5.23.0, CPU only (
CUDA_VISIBLE_DEVICES=,HF_HUB_OFFLINE=1).gptqmodel.__file__was printed from the clone under test. Head is rebased onorigin/main2863a6b, which already contains #6460 and #6464.Structural A/B of the derivation (CPU, meta). For every inventory case and layer variant, the script dumps
canonical_awq_folds(plan, layer, blocks, gqa_shape_gate=...)with no data, as(source, targets, consumers, boundary, span_roots). It ran once on anorigin/mainworktree and once on this branch:This shows that moving the boundary rule into
_default_boundary/merge_by_sourcechanges no derived fold.GPU A/B: not applicable. No quantize, pack, save or load path is touched, and the production planner's effective plan is pinned unchanged by E1.
Measured Impact
Not applicable: no runtime path changes.
Model Support / Module Plan
Not applicable to the registry: no
MODEL_MAPentry, tree, tag, alias or fusion change. The 8 touched definitions gain one class attribute.test_registered_module_plans.pyandtest_definition_subset_ordering.pypass (above).AWQ onboarding safety
Per-variant policy is unchanged. Every declared fold is one the current planner already searches and folds (inventory status
ok). The data restates it; nothing new is admitted. Forward evidence for each relationship, from the vendored ports:v -> out_proj/dense: softmax attention output is linear in V (gpt_neomodeling_gpt_neo.py:151/163, gptjmodeling_gptj.py:191/229, phimodeling_phi.py:236, lfm2_moemodeling_lfm2_moe.py:321/344).c_proj(act(c_fc_0(x)) * c_fc_1(x)),modeling_exaone.py:214.c_proj(w1(x) * silu(w2(x))),modeling_qwen.py:165.fc2(act(fc1(x))), whereactis ReLU in every released OPT config (configuration_opt.py:67), so the fold is exact for positive scales.out_proj(norm(scan_output, gate))with a gated RMSNorm gain,modeling_granitemoehybrid.py:719-722.Unverified layouts are the same as on
origin/main, because the inventory does not build them:Both are left to the derivation unchanged: the declared fold's source is absent there, or the data is identical across layouts.
Logic Flow Documentation
flowchart TD A["awq_fold_declarations(layer)"] --> B{"overridden<br/>(not None)?"} B -- "yes (PanGu, Inkling2-Loop)" --> M["merge_by_source<br/>default boundary"] B -- "no" --> C["canonical_awq_folds(plan, layer, blocks,<br/>declared=awq_folds)"] C --> D{"declared source<br/>on this layer?"} D -- "no" --> S["skip that fold"] D -- "yes" --> E{"targets resolve and first<br/>target in a quantized block?"} E -- "no" --> X["ValueError"] E -- "yes" --> F["emit after that block"] F --> M S --> M M --> T["test: equals inventory 'ok' groups<br/>unless listed in AWQ_FOLD_DIFFERENCES"] style X fill:#fdd,stroke:#c00Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, dispatch or packing change.
Notes
AWQ_FOLD_DIFFERENCES. Itslora_Aadapter consumers could be declared as data. Butphi4.py:67also sets_awq_allow_partial_replay(the adapters never run in replay), andAWQFoldDeclarationhas no field for it. The inventory does not record that flag either, so step 4b's E1 gate would not notice if it were lost. Recording it in the inventory belongs in a later step.qwen.py'sawq_get_modules_for_scalingoverride still produces the productionw1 -> c_projgroup. The data now states the same fold and pins it; PR 5 deletes the override.run_awq_cpu.sh unitfailures above reproduce onorigin/mainand are unrelated to this change.🤖 Generated with Claude Code