Repository navigation
fix(awq): fold a norm's scale consumers outside the replay boundary (#4898) - #5002
Merged
Merged
Conversation
…4898) Cohere2-MoE reads one `input_layernorm` from two parallel branches (`self_attn` and the MoE block), and the MoE router consumes the same normed input. `_merge_shared_source_nodes` already splits such a group (#4772): the members the replay boundary covers are scored, the rest are fold-only (`_awq_allow_outside_fold`). But `_validate_scale_group` exempted only the fold-only *targets* from the containment check, so the router - a `_scale_consumers` entry - still had to live inside `self_attn`. It never can, so every layer rejected the group and sent q/k/v plus every routed and shared expert gate/up to plain quantization behind one per-layer warning. With `_awq_allow_outside_fold`, only the members the search scores must be replayed; out-of-boundary members and consumers are folded, and `apply_scale` still compensates every declared consumer through its consumer map. The fold is exact because the router reads the same normed tensor. `tests/test_awq_cohere2_moe_parallel_norm_4898.py` reproduces it end to end on a tiny `cohere2_moe`: on unmodified main every layer logs "replay boundary `self_attn` does not contain targets ['mlp.gate']" and q/k/v keep `loss=not applicable`; with the fix the group is scored and folded.
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
Cohere2-MoE reads one
input_layernormfrom two parallel branches (self_attnand the MoE block) and its MoE router consumes the same normed input. #4772 let
such a group fold the members that live outside the replay boundary
(
_awq_allow_outside_fold), but the containment check still required everyscale consumer to be inside
self_attn. The router (mlp.gate) never is,so every layer rejected the group:
An "AWQ" Cohere2-MoE checkpoint therefore had plain-quantized q/k/v and
plain-quantized gate/up for every routed and shared expert in every MoE layer;
only
o_projand thedown_projs kept AWQ scales.Fixes #4898.
What Changed
gptqmodel/looper/awq_processor.py(_validate_scale_group): whenallow_outside_foldis set, only the members the search scores must be insidethe replay boundary. Out-of-boundary members and scale consumers are folded,
not replayed —
apply_scalecompensates every declared consumer through itsconsumer map, and the fold is exact because they read the same normed tensor.
tests/test_awq_cohere2_moe_parallel_norm_4898.py: end-to-end CPU test on atiny
cohere2_moe(8 experts, top-2, 2 layers). Asserts noplain-quantization fallback and that q/k/v plus the routed experts keep AWQ
scales.
docs/awq-scaling-groups.md: the "Now" column now states that a groupdeclared across sibling branches folds its out-of-boundary members and
consumers instead of scoring them.
.github/workflows/awq_cpu.yml: run the new file in the AWQ CPUunitsuite.No API change. Groups without
_awq_allow_outside_foldkeep the strictcontainment check for targets, fold-only members and consumers.
Tests
Red on unmodified
origin/main(a62bed008), test file copied into a separateworktree at that commit:
Green with the fix:
1 passed. Fold exactness forcohere2_moeis alreadypinned by
tests/test_awq_scaling_groups.py::test_scaling_groups_preserve_decoder_layer_output[cohere2_moe](decoder-layer output unchanged to <1e-5 with a random folded scale and the
router compensated), which passes on both trees.
Regression suites (fix vs unmodified main — identical failure sets):
test_awq_cohere2_moe_parallel_norm_4898.pytest_awq_scale_search_safety.py,test_awq_scaling_groups.py,test_awq_falcon_h1_parallel_branch_4741.py,test_awq_moe_shared_expert_group_4760.py,test_awq_moe_router_scaling.py,test_awq_moe_root_capture_4697.py,test_awq_moe_starved_expert_group_4675.py,test_awq_empty_groups.py,test_awq_scale_folding.py,test_docs_contract_refs.pyThe 7 failures are pre-existing on unmodified main (
afmoe/flintgroupinvariants,
jambax_projsource, and the end-to-end bailing MoE test).ruff checkclean on the changed Python files.Model Support / Module Plan
Not applicable: no
MODEL_MAPentry, alias, or definition change.