Repository navigation
fix(awq): correct scaling groups across dense and MoE families (#4039) - #4065
Merged
Merged
Conversation
# Conflicts: # gptqmodel/models/definitions/deepseek_v4.py # gptqmodel/models/definitions/minimax_m2.py # tests/module_tree/fixtures/registered_module_plans.json
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.
Fixes #4039
TL;DR
The AWQ scaling-group builder folded a scale into sources whose output is not the consumer's input. This PR closes the remaining families from the #4030/#4035 follow-up, and makes the invariant test cover every dense and MoE family that builds in transformers 5.22 (
91 passed). Net: 23 files, +717/−200, concentrated ingptqmodel/models/base.py(group selection/merge) and one-line tree declarations.1. Root causes (file:line)
Five distinct mechanisms produced the measured damage:
exaone4.py:82,gemma4.py:45,afmoe.py:38,53— missing:postnormgptqmodel/models/base.py:5327(_merge_shared_source_nodes, new)base.py:_select_prev_opshared-source path (:4900) +:in=<tag>inrw.py:44,falcon_h1.py:26fc1 → fc2across a non-homogeneous activationgpt_neox.py:25,gpt_neo.py:27,gpt_bigcode.py:21,bloom.py:21,rw.py:22,gpt_oss.py:30,flint.py— missing:nosrcgate_projbecomes the block's last module and is folded intoo_projafmoe.py:35,muse_glimmer.py:49,hrm_text.py:30,minimax_m2.py:98— missing:nosrcConv1D,HyperConnection,Cohere2LayerNormquantization/awq/quantize/scale.py:79(is_foldable_source, new) +allowed_norms(:57)Additional tree corrections:
olmoe.pyq/k norms moved into the q/k/v block with a group index,laguna'sg_projcollected as a scale consumer (base.py:_norm_scale_consumersnow reads the block),cohere2_moe's undeclaredshared_expertsdeclared,falconsplit intoFalconQModel(Falcon names its normsinput_layernorm, RefinedWeb usesln_1/ln_2),deepseek_v4o_b_proj/q_b_projmarked:nosrc.2. New flow
flowchart TD A["awq_get_modules_for_scaling"] --> B{"non-quantized block?"} B -- "yes" --> C["track last_gain_norm<br/>and last_norm_candidate"] B -- "no" --> D["_select_prev_op<br/>pending norm / block norm / shared in= source"] D --> E["generate_node_for_awq_scaling"] C --> E E --> F["_merge_shared_source_nodes<br/>one group per gain norm"] F --> G["_filter_awq_scaling_sources<br/>nosrc / width"] G --> H["AWQProcessor._quantize_layer"] H --> I{"apply_scale: is_foldable_source?"} I -- "yes" --> J["divide norm once,<br/>scale every consumer"] I -- "no" --> K["skip group<br/>layer quantized plainly"] style G fill:#fff3cd,stroke:#997404,stroke-width:2px style K fill:#fff3cd,stroke:#997404,stroke-width:2px_merge_shared_source_nodesis the core fix: a gain norm may be divided exactly once, so it may have exactly one scaling group. Routed experts,shared_experts, and parallel branches are merged into that group and share one scale vector.3. Before / after (measured relative logit change)
Tiny 2-3 layer models, random scale in
[0.5, 1.5]applied with the library's ownapply_scale, full-model logits compared.exaone4_5gemma4_textafmoecoherefalconfalcon_h1minimaxminimax_m2olmoelagunasolar_openhy_v3glm_moe_dsagpt_neoxgpt_neogpt_bigcodebloomgpt_osshrm_textAttributeError)olmoOlmoLayerNormno weight)cohere2Cohere2LayerNormnot inallowed_norms)cohere2_moegpt2Conv1D)axk2AXK2GatedRMSNorm)deepseek_v4HyperConnection)flintup_proj → down_projfold4. Failure / ambiguity contract
prev_opis a weightless or gated norm /Conv1D/HyperConnectionNotImplementedError/AttributeErroris_foldable_source; layer quantized plainlylast_norm_candidatereturns the block norm, group is dropped5. Tests
tests/test_awq_scaling_groups.pynow resolves every family fromMODEL_MAP, iterates all decoder layers, passes each group's_scale_consumersasconsumer_mapexactly asawq_processor.py:1658-1688does, and requires < 1e-5 relative change. It covers 45 dense + MoE families, a routed/shared-merge assertion for 10 MoE families, a non-source assertion for 20 families, and static:nosrc/:postnormassertions for definitions that have noAutoModelForCausalLMentry point (exaone4_5,muse_glimmer).6. Docs
docs/awq-scaling-groups.mdis updated with the one-group-per-norm contract, the parallel-branch:in=rule, the foldability contract, the per-definition non-source table and a Mermaid flow (already linked fromREADME.md:105).7. Hardware
CPU-only tiny models (
AutoModelForCausalLM.from_config), no GPU kernels exercised. Assigned pair 4090GPU-50a20676-a7a4-8bb3-eb3d-f191fdc9fa42/ R9700HIP_VISIBLE_DEVICES=4; the RTX 5090 was not touched.8. Notes
deepseek_v3/deepseek_v32cannot build a tiny config in transformers 5.22 (RuntimeError: shape '[-1, 8, 0]'), so they are covered structurally by the merge assertion throughdeepseek_v2/deepseek_v4.minimax(original) intentionally has no foldable group: its layer feeds the normalized value into the residual, so every norm is a non-source and the layer is quantized plainly.tests/test_awq_weight_mean.pyfails to collect on this venv (missingparameterized), pre-existing and unrelated.