Skip to content

[QUALITY] #4772 (fix of #4741) incomplete: Cohere2-MoE AWQ still sends q/k/v + every routed/shared expert gate/up to plain quantization in every MoE layer (router consumer outside the self_attn replay boundary) #4898

Closed

Description

@Qubitium

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:

  1. _validate_scale_group (looper/awq_processor.py:2990): checked = targets + consumers if allow_outside_fold else .... With allow_outside_fold, only the fold-only extra targets are exempt, and mlp.gate (a _scale_consumers entry) is still required inside self_attn.
  2. If (1) is relaxed, _search_best_scale's replay coverage check (:3311-3320) then raises reference replay did not execute targets ['mlp.gate'], because the consumer is registered as a replay target although the self_attn replay 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

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4697 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-4697 finished this issue. Fix: #5002, squash-merged as c2b0bf64f.

    _validate_scale_group now exempts a group's scale consumers from the replay-boundary containment check when _awq_allow_outside_fold is set (the split #4772 introduced for parallel norm branches). Cohere2-MoE's input_layernorm group carries the MoE router (mlp.gate) as a consumer, and the router lives in the sibling MoE branch, so it can never execute inside the self_attn replay — 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 through apply_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 unmodified main (two replay boundary \self_attn` does not contain targets ['mlp.gate']fallbacks, q/k/vloss=not applicable), green with the fix. Combined with #5000 on current main, the new files plus test_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions