Skip to content

[BUG] AWQ scaling groups: KeyError 'q_zeros' crash for Phi3/Apertus (empty groups), non-output-preserving groups for OLMo2/3, Exaone4, OPT, Phi, GPT-J, Starcoder2 #4005

Closed

Description

@Qubitium

Audit of main @ 105602e. The same tiny-model end-to-end sweep shows GPTQ is fine for all 16 families tested. The problems below are in AWQ scaling-group construction (awq_get_modules_for_scaling, models/base.py ~4347-4600) and in a few module trees. Related to #3973 (Gemma2/3, fixed); these are other families.

1. AWQ crashes with KeyError: 'q_zeros' when no scaling groups are built (Phi3, Apertus, likely CodeGen/MPT)

  • base.py ~4558: in awq_get_modules_for_scaling, the if prev_op is None: continue branch skips _try_update_last_module. If the tree's first block has no norm entry, last_module is never set and every block is skipped.
  • awq_processor.py:1539-1545 and :1626-1631: with an empty group list, the layer goes to _finalize_quantized_layer without quantizing.
  • awq_processor.py:3116: pack_module then fails on module.state.pop("q_zeros").

Trees affected:

  • Phi3: the tree has no input_layernorm / post_attention_layernorm.
  • Apertus: ("attention_layernorm:!") at definitions/apertus.py:27,29 is a string, not a 1-tuple, so the norm entries are silently dropped.
  • CodeGen / MPT: same tree shape (by inspection).
t_awqmap.py phi3   ->  AWQMAP ---   (empty)  ...  QUANT_EXC KeyError 'q_zeros'

There is also a leftover debug print("modddd", module.full_name) at awq_processor.py:3114.

Fix: update the tracker even when prev_op is None, and on the empty-group paths call _quantize_layer_fallback (plain quantization) instead of _finalize_quantized_layer. Add the norms to the Phi3 tree, fix the Apertus tuples, and remove the print.

2. AWQ scaling groups that are not output-preserving (silent accuracy loss)

prev_op is the last non-quantized norm, or the previous linear in tree order. Nothing checks that it actually feeds the consumer directly.

Test method: apply the library's own apply_scale with a random scale in [0.5, 2] to each generated group and measure the relative logit change. It should be ≈1e-7 (Llama: 1.8e-7 to 3.8e-7).

family group GPTQModel builds rel. change why it's invalid
OLMo2 / OLMo3 / Exaone4 post_attention_layernorm → mlp.gate/up 0.34-0.36 post-norm runs before the residual add
OPT final_layer_norm → q/k/v 0.34 tree lists the pre-MLP norm first; self_attn_layer_norm missing
OPT self_attn.out_proj → fc1 0.25 crosses the residual
Phi self_attn.dense → mlp.fc1 0.36 parallel attention/MLP block
Phi self_attn.q_proj → k_proj 8e-3 q/k/v in separate subsets :0/:1/:2 (phi.py:21)
Phi mlp.fc1 → mlp.fc2 7.4e-2 crosses GELU
GPT-J attn.out_proj → mlp.fc_in 0.33 parallel block
GPT-J mlp.fc_in → mlp.fc_out 7.8e-2 crosses GELU
Starcoder2 mlp.c_fc → mlp.c_proj 5.1e-2 crosses GELU

For OPT, the AWQ log says "sanitized 4 scaling groups", but the invalid groups above are still built. On random tiny models AWQ doesn't beat RTN even for Llama, so end-to-end damage is hard to show this way (OLMo2 is the clearest at 1.40× Llama's AWQ/RTN ratio). Real models with outlier channels pick larger scales, so the damage should be larger.

Fix:

  • Allow a norm as prev_op only when it is the direct input of the block (mark pre- vs post-norm in the tree).
  • Allow a linear prev_op only for a gated MLP (gate·up → down) or the v → o pair. Otherwise use a scaled-activation op or skip the group.
  • Fix the OPT tree (add self_attn_layer_norm before attention, move final_layer_norm before fc1) and put Phi's q/k/v in one subset.
  • Extend tests/test_awq_scale_folding.py::test_gemma2_mlp_scale_fold_is_output_neutral to every registered dense family.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Follow-up on #4030: Exaone 4.5 lost the :postnorm fix, and the GELU fc1→fc2 folds remain for gpt_neox, gpt_neo, gpt_bigcode, bloom and falcon. More non-output-preserving groups and crashes are listed in #4039.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions