Repository navigation
Description
Found on main @ 4f287eb, CPU (transformers 5.22.1). Same behavior at 12c1273.
What is wrong
#4772 (fix of #4741) lets a shared-norm group whose members span two parallel branches fold the same scale into the branch outside the replay boundary (_awq_allow_outside_fold). That covers Falcon-H1 and made dense Cohere/Cohere2 gain their input_layernorm group. Cohere2-MoE has the same parallel residual block (norm -> attention and norm -> MoE), but its group also carries the router as a scale consumer. That consumer still has to be inside the boundary, so every MoE layer still sends its largest group to plain quantization:
AWQProcessor: layer 0 using configured plain-quantization fallback for ['self_attn.q_proj', 'self_attn.k_proj', 'self_attn.v_proj', 'mlp.experts.0.gate_proj', 'mlp.experts.0.up_proj', ... 'mlp.shared_experts.gate_proj', 'mlp.shared_experts.up_proj']: AWQ: replay boundary `self_attn` does not contain targets ['mlp.gate'] for source `input_layernorm`; a matching replay input and boundary are required.
AWQProcessor: layer 0 fallback quant 19 modules: [...]
AWQProcessor: layer 1 ... (same)
So an "AWQ" Cohere2-MoE checkpoint has 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 get AWQ scales.
Two checks need the consumer exemption that #4772 gave only to targets:
_validate_scale_group(looper/awq_processor.py:2990):checked = targets + consumers if allow_outside_fold else .... Withallow_outside_fold, only the fold-only extra targets are exempt, andmlp.gate(a_scale_consumersentry) is still required insideself_attn.- If (1) is relaxed,
_search_best_scale's replay coverage check (:3311-3320) then raisesreference replay did not execute targets ['mlp.gate'], because the consumer is registered as a replay target although theself_attnreplay can never run it.
The fold itself is output-preserving. The router reads the same input_layernorm output, so multiplying its weight columns by s is exact. tests/test_awq_scaling_groups.py already checks cohere2_moe group construction, and that passes. Only the processor-side checks reject the group.
Repro (CPU, ~10 s)
import tempfile, torch
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
from gptqmodel import GPTQModel
from gptqmodel.quantization import AWQConfig
from gptqmodel.quantization.config import CalibrationConfig
d = tempfile.mkdtemp()
cfg = AutoConfig.for_model("cohere2_moe", vocab_size=1000, hidden_size=128, intermediate_size=256,
moe_intermediate_size=128, num_hidden_layers=2, num_attention_heads=4,
num_key_value_heads=4, num_experts=8, num_experts_per_tok=2, pad_token_id=0)
torch.manual_seed(0)
AutoModelForCausalLM.from_config(cfg).to(torch.bfloat16).save_pretrained(d)
AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct").save_pretrained(d)
q = GPTQModel.load(d, AWQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
rows = [{"input_ids": torch.randint(3, 1000, (L,)).tolist(), "attention_mask": [1] * L}
for L in (64, 48, 80, 56, 72, 40, 64, 96)]
q.quantize(CalibrationConfig(dataset=rows))This logs the two warnings above for every layer, and 19 of 25 quantized modules per layer go to plain quantization. No expert is starved (each expert receives 400-480 of 856 tokens), so the fallback comes only from the boundary check.
Suggested fix
When _awq_allow_outside_fold is set, treat _scale_consumers that lie outside module2inspect the same as the out-of-boundary targets. Skip them in the _validate_scale_group containment check and in the replay-coverage target list, and still pass them to apply_scale's consumer_map so the router is compensated. Also, the fallback for the whole group should log at least once per run that AWQ was disabled for q/k/v + all experts. Today the per-layer warning is easy to miss in a long run.
Test that should have caught it
tests/test_awq_falcon_h1_parallel_branch_4741.py covers only a parallel branch without scale consumers. A tiny cohere2_moe real-quantize() test that asserts no plain-quantization fallback for the input_layernorm group would catch it.
Severity
Medium (quality): AWQ is silently reduced to RTN for most of the weights of every Cohere2-MoE MoE layer.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4697is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent release:
agent-root-4697finished this issue. Fix: #5002, squash-merged asc2b0bf64f._validate_scale_groupnow exempts a group's scale consumers from the replay-boundary containment check when_awq_allow_outside_foldis set (the split #4772 introduced for parallel norm branches). Cohere2-MoE'sinput_layernormgroup carries the MoE router (mlp.gate) as a consumer, and the router lives in the sibling MoE branch, so it can never execute inside theself_attnreplay — every layer rejected the group and sent q/k/v plus every routed/shared expert gate/up to plain quantization. Now only the members the search scores must be replayed; out-of-boundary members and consumers are folded and compensated throughapply_scale's consumer map (exact, since they read the same normed tensor).Verified on a tiny
cohere2_moe(8 experts, top-2, 2 layers,AWQConfig(bits=4, group_size=32)),tests/test_awq_cohere2_moe_parallel_norm_4898.py: red on unmodifiedmain(tworeplay boundary \self_attn` does not contain targets ['mlp.gate']fallbacks, q/k/vloss=not applicable), green with the fix. Combined with #5000 on currentmain, the new files plustest_awq_moe_root_capture_4697.py,test_awq_falcon_h1_parallel_branch_4741.py,test_awq_scale_search_safety.py,test_awq_empty_groups.py,test_docs_contract_refs.py`: 70 passed.fix(awq): fold a norm's scale consumers outside the replay boundary (M…