Skip to content

fix(awq): fold a norm's scale consumers outside the replay boundary (#4898) - #5002

Merged
Qubitium merged 1 commit into
mainfrom
root/awq-consumer-fold-4898
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/awq-consumer-fold-4898

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Cohere2-MoE reads one input_layernorm from two parallel branches (self_attn
and 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 every
scale consumer to be inside self_attn. The router (mlp.gate) never is,
so every layer rejected the group:

AWQProcessor: layer 0 using configured plain-quantization fallback for
['self_attn.q_proj', ..., 'mlp.shared_experts.up_proj']: AWQ: replay boundary
`self_attn` does not contain targets ['mlp.gate'] for source `input_layernorm`

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_proj and the down_projs kept AWQ scales.

Fixes #4898.

What Changed

  • gptqmodel/looper/awq_processor.py (_validate_scale_group): when
    allow_outside_fold is set, only the members the search scores must be inside
    the replay boundary. Out-of-boundary members and scale consumers are folded,
    not replayed — apply_scale compensates every declared consumer through its
    consumer 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 a
    tiny cohere2_moe (8 experts, top-2, 2 layers). Asserts no
    plain-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 group
    declared 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 CPU unit suite.

No API change. Groups without _awq_allow_outside_fold keep the strict
containment check for targets, fold-only members and consumers.

Tests

Red on unmodified origin/main (a62bed008), test file copied into a separate
worktree at that commit:

CUDA_VISIBLE_DEVICES="" PYTHONPATH=<worktree> python /tmp/root-rt.py \
  tests/test_awq_cohere2_moe_parallel_norm_4898.py -q -o addopts= -o log_cli=false
# 1 failed  (two "replay boundary `self_attn` does not contain targets
#            ['mlp.gate']" fallbacks, one per layer)

Green with the fix: 1 passed. Fold exactness for cohere2_moe is already
pinned 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):

suite main fix
test_awq_cohere2_moe_parallel_norm_4898.py 1 failed 1 passed
test_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.py 7 failed, 267 passed, 2 skipped 7 failed, 268 passed, 2 skipped

The 7 failures are pre-existing on unmodified main (afmoe/flint group
invariants, jamba x_proj source, and the end-to-end bailing MoE test).

ruff check clean on the changed Python files.

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, alias, or definition change.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant