Repository navigation
refactor(models): move the remaining structural AWQ overrides to fold data (batch C) - #6624
Merged
Merged
Conversation
… data (batch C) Batch C of the AWQ lifecycle cleanup: the structural awq_get_modules_for_scaling overrides that rebuilt or patched scaling nodes by hand now come from the fold declarations (canonical_awq_folds plus awq_folds data), where that reproduces the current plan exactly. * phi4mm: the override's lora_A consumers and `_awq_allow_partial_replay` are `awq_folds` data. AWQFoldDeclaration gains `partial_replay` (the boundary replay may not execute every member; the adapters never run there), which _awq_nodes_from_declarations turns into the node flag. merge_by_source keeps a group's boundary when a merged fold adds only consumers, so the data fold of the same target keeps the derived `self_attn`/`mlp` replay boundary. * intern_s2_preview: the hand-built DeltaNet node is deleted; the `:in=x` tags already derive input_layernorm -> in_proj_qkv, in_proj_z with in_proj_b/a compensated. A two-line filter keeps one corner: without an in_proj_qkv capture (a `dynamic` exclusion) the group is not planned, so in_proj_z quantizes plainly instead of joining a starved group (fallback routing). The override's past_key_values -> cache_params rename is dropped: the scale search re-adds the layer's past_key_values with setdefault, and awq_module_replay_inputs rejects any non-None cache under either name, so the DeltaNet replay only loses an explicit cache_params=None, its default (recorded on GPU; the checkpoints are bit-identical). * minicpmv_4_6: the same DeltaNet builder becomes "DeltaNet layers plan from the declarations" with the same filter. Full-attention layers keep the tree tracker: their width-dropped v_proj -> o_proj group is one of the 66 drop:width-only differences that can still route a starved member to fallback. * solar_open2: leaves the tracker. `v_proj:nosrc` replaces the override's o_proj stripping (o_proj reads the gated output; tiny_mha would otherwise gain v_proj -> o_proj), and the dense-prefix mlp.up_proj -> down_proj group the override restored is a role-derived fold. Kept, because the declarations change a reachable plan: * ernie4_5_vl_moe: its declarations already equal the override's MoE group, but leaving the tracker drops the width-dropped v_proj -> o_proj group on every layer (one of the 66). * nemotron_omni: the same drop:width group on attention layers, and the MoE group's `mixer` search-feature name (which lets the processor split a starved routed expert, #4675) has no declaration form. * nemotron_h_puzzle: with routed experts unrouted on a non-latent layout the tracker plans a shared-expert group that falls back while the declarations skip the group (the MoE root is not captured); a `dynamic` exclusion of shared_experts.up_proj on latent layouts drops the fold the tracker still makes (the known shared-norm exclusion bug, preserved); and moe_latent_size == hidden_size would add the routed experts to the norm group. The phi4mm and solar_open2 tiny_mha entries leave AWQ_FOLD_DIFFERENCES and TRACKER_PLANNED. tests/module_tree/awq_fold_inventory.py --check reports no change for all 210 types. 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 7, batch C (map
awq_lifecycle.md, PR 7). The structuralawq_get_modules_for_scalingoverrides that built or patched scaling nodes by hand now come from the fold declarations (canonical_awq_foldsplusawq_foldsdata), where that reproduces the current plan exactly. Four of the seven targets move (phi4mm, intern_s2_preview, minicpmv_4_6, solar_open2). Three stay (ernie4_5_vl_moe, nemotron_omni, nemotron_h_puzzle), because moving them changes a reachable plan; the reasons are below.Behavior-preserving:
awq_fold_inventory.py --checkreportschanged: nonefor all 210 types.first_k_dense_replace=1) and MHA+dense variants; the unit-test tiny configs (MiniCPM-V 4.6 DeltaNet text layout, Puzzle tiny/MHA/no-latent/bias); and coincident widths (Puzzlemoe_latent_sizeequal to the hidden size or the expert width).dynamicexclusion; 20% empty; MoE root empty; 3 seeds; every distinct layer of every variant above). The only differences are unreachable. Intern-S2 and MiniCPM-V 4.6 differ when the densein_proj_qkvcapture is empty (a dense projection sees every token of its layer). Solar Open 2 differs only when the MoE rootmlpcapture is empty while experts hold rows ([QUALITY] AWQ silently drops the routed-expert gate/up scaling group for 15 MoE definitions without moe_lifecycle_hooks (gpt-oss, Granite-MoE, ERNIE-4.5-MoE, Gemma-4, Nemotron-H...): MoE-root capture is never registered #4697: the root sees every routed token). Before thein_proj_qkv-capture filter, the perturbation also found the reachabledynamic-exclusion difference that the filter now preserves.quant_log.csv) on seeded tiny MiniCPM-V 4.6, Intern-S2-Preview and Solar Open 2 fixtures (GPU), a tiny phi4mm fixture (CPU, see Notes) and Qwen2.5-0.5B-Instruct (GPU control).AWQ_FOLD_DIFFERENCESis not empty after this PR. The map's goal assumed all of batch C could move; the entries left belong to PR 6 (config-conditional overrides), the tracker-gap/canonical-unsafe cases that need a quality-evidenced PR, and the three kept definitions here.What Changed
phi4mmawq_get_modules_for_scaling(phi4.py:67) keeps norm groups, replaces their consumers with each target'slora_A.{vision,speech}and sets_awq_allow_partial_replay(phi4.py:95)awq_foldsentries with those consumers andpartial_replay=Trueintern_s2_previewlinear_attn, hand-buildsinput_layernorm -> in_proj_qkv, in_proj_z(consumersin_proj_b/a, boundarylinear_attn) whenin_proj_qkvwas captured, renamespast_key_valuestocache_params:in=xtags already derive that group. A 2-line filter keeps one corner: no group without anin_proj_qkvcaptureminicpmv_4_6solar_open2o_projfrom norm groups and restores the dense-prefixmlp.up_proj -> down_projv_proj:0:nosrc(o_proj reads the gated output; tiny MHA would otherwise gainv_proj -> o_proj), andup -> downis a role-derived foldShared code:
AWQFoldDeclaration.partial_replay(awq_folds.py): the boundary replay may not execute every member;_awq_nodes_from_declarations(base.py) turns it into_awq_allow_partial_replay.merge_by_source: a merged fold that adds only consumers keeps the group's boundary. Without this, phi4mm's data fold for the same single target re-anchored the group fromself_attnto the target. No other type merges such a fold (E1).tests/module_tree/test_awq_fold_inventory.py: phi4mm leavesAWQ_FOLD_DIFFERENCES; solar_open2tiny_mhaleavesAWQ_FOLD_DIFFERENCESandTRACKER_PLANNED.docs/awq-scaling-groups.md: the new field, the consumer-only merge, and the DeltaNet note.The
past_key_values -> cache_paramsrename is dropped on purpose. In the old flow_search_best_scalere-adds the layer'spast_key_valuesthroughsetdefaultfrom the global kwargs, and both definitions'awq_module_replay_inputsreject a non-None cache under either name. The only difference in the DeltaNet replay is an explicitcache_params=None(its default). This was recorded on GPU by wrapping the DeltaNet forward:Kept, with the reason:
ernie4_5_vl_moe.py:400(+ tracker :26)self_attn.v_proj -> o_projgroup on every layer. That is one of the 66 drop:width-only opt-outs, and the group can still route a starved member to fallback.nemotron_omni.py:181(tracker viaNemotronHQModel)_input_feature_name="mixer"(which lets the processor split a starved routed expert, #4675) has no declaration form: the nestedmixer.expertsroot is not captured, so the declared feature would bemixer.shared_experts.up_proj.nemotron_h_puzzle.py:47(tracker viaNemotronHQModel)v_proj:nosrc) equal the inventory and the unit-test tiny configs, but the perturbation A/B finds three reachable differences. (1) Unrouted routed experts on a non-latent layout: the tracker plans a shared-expert-only group that falls back, while the declarations skip the group, because puzzle does not capture its MoE root. (2) Adynamicexclusion ofshared_experts.up_projon latent layouts: the tracker still folds the norm intofc1_latent_proj, while the declarations drop the group. This is the known shared-norm exclusion bug, preserved here. (3)moe_latent_size == hidden_sizewould add the routed experts to the norm group.Out of scope: PR 6 (config-conditional overrides; nemotron_h belongs there), and releasing the 66 drop:width-only opt-outs (needs a maintainer decision).
Tests
New tests (all pass on origin/main's code and on this branch):
tests/module_tree/test_awq_fold_declarations.py::test_merge_keeps_the_group_boundary_when_a_fold_adds_only_consumerstests/module_tree/test_intern_s2_preview_local_port.py::test_deltanet_input_group_searches_on_in_proj_qkv_capture[None|linear_attn.in_proj_qkv|linear_attn.in_proj_z]tests/test_minicpmv46_awq_port.py::test_input_group_searches_on_in_proj_qkv_capture[linear_attn.in_proj_qkv|linear_attn.in_proj_z]Measured Impact
Not applicable: no numerics change. The GPU A/B above is bit-identical.
Model Support / Module Plan
No
MODEL_MAPentries were added. Tree changes: one:nosrcflag onsolar_open2self_attn.v_proj(AWQ-only; GPTQ ignores it). Registry and per-model tests are in the E2 run above.AWQ onboarding safety
No new groups. Every touched variant keeps its exact plan: E1 (210 types), the structural stress A/B (MHA / equal-width / dense-prefix / unit-test tiny configs) and the perturbation A/B (unrouted experts,
dynamicexclusions, empty captures). The existing per-model neutral-fold, candidate-search and replay tests (test_minicpmv46_awq_port.py,test_intern_s2_preview_local_port.py,test_phi4_local_port.py,test_solar_open2_local_port.py) pass unchanged.Logic Flow Documentation
The generic flow in
docs/awq-scaling-groups.md("Flow") is unchanged. Per-definition hand-built nodes are replaced by declared data:flowchart TD A["awq_get_modules_for_scaling(layer)"] --> B{"awq_groups_from_tree_order?<br/>(minicpmv_4_6: full-attention layers only)"} B -- "no" --> C["canonical_awq_folds + awq_folds<br/>phi4mm: lora_A consumers, partial_replay"] C --> D["merge_by_source<br/>consumer-only fold keeps the boundary"] D --> E["_awq_nodes_from_declarations<br/>partial_replay -> _awq_allow_partial_replay"] E --> F{"intern_s2 / minicpmv_4_6:<br/>feature == linear_attn.in_proj_z?"} F -- "yes (no in_proj_qkv capture)" --> G["drop the DeltaNet input group<br/>in_proj_z quantizes plainly"] F -- "no" --> H["scaling nodes"] B -- "yes" --> T["tree tracker (ernie, nemotron_omni, puzzle, minicpmv full attention)"]awq_folds+AWQFoldDeclaration.partial_replay:in=xderivation + 2-line filterv_proj:nosrc+ role-derivedup -> downReview Requirements
Kernel Accuracy Requirements
Not applicable: no kernel is touched.
Notes
apply_rotary_pos_embgets CPUcos/sin(Expected all tensors to be on the same device, modeling_phi4_multimodal.py:1216)._prepare_module_forwardrebuildsposition_embeddingswith the root rotary, which stays on CPU for phi4mm (norotary_embeddingdeclaration). So the phi4mm A/B above ran on CPU.test_awq_hybrid_recurrent_mask_4671.py::test_awq_batch_size_one_quantizes_a_mamba_hybrid(the tiny tokenizer sometimes "cannot encode ordinary text") andtest_awq_weight_mean.py::test_awq_pseudo_quantize_nan_guard_uses_one_host_read(scalar_reads4 instead of 1). Both fail and pass intermittently on the main worktree too.ab_stress.py,perturb.py(extended from PR 5's) andgpu_ab.pyare kept outside the repo.🤖 Generated with Claude Code