Skip to content

[BUG][model] Several model definitions silently leave layers unquantized against transformers 5.22 #4174

Closed

Description

@Qubitium

Severity: high — quantized checkpoints keep large parts of the model in BF16 with no error
Version: 7.11.0 @ 6c3421c, transformers 5.22.2

How this was found

For each MODEL_MAP type:

  1. Build the real module tree on the meta device the way the loader does: resolve_trust_remote_code → defuser → build_shell_model → definition.
  2. Compare the declared quantized and :! paths with every Linear / Conv / Embedding leaf.

About 151 types were checked. The existing tests/module_tree suites pass (520 passed) and catch none of the cases below.

Findings

Model Where Problem
Voxtral definitions/voxtral.py:12-15 Tree declares language_model.model.layers; the real path in 5.22 is model.language_model.layers. pre_lm_head_norm_module was updated, the tree wasn't. Zero layers resolve, so nothing is quantized.
Nemotron-H MoE (e.g. NVIDIA-Nemotron-3-Nano-30B-A3B) definitions/nemotron_h.py:22-33 No mixer.experts.#, mixer.shared_experts or router entries, and layer_modules_strict=False. 2944 routed-expert up/down projections plus shared experts stay BF16, which is most of the weights.
Ling 2.0 (bailing_moe) — regression from #4080 (2ac5a4e) definitions/bailing_moe.py:26-43 attention.query_key_value / attention.dense were dropped on the assumption that the layout no longer exists. bailing_moe is remote-code only and still uses it, so on Ling-mini-2.0 attention in all 20 layers stays FP.
Llama-4 Maverick definitions/llama4.py:31-48 (+ Llama4TextQModel) feed_forward:moe has no "" dense entry. MoE is every other layer, so 24/48 layers have undeclared feed_forward.{gate,up,down}_proj. With strict=True this should raise; relaxed, the dense MLPs stay FP. Scout is unaffected.
Gemma-4 MoE (enable_moe_block=True, e.g. 26B-A4B) definitions/gemma4.py:20-50 No router or expert entries. Experts are a 3-D Gemma4TextExperts parameter, and defuser 0.0.31 has no gemma4 entry. The undeclared-leaf warning only checks Linear/Conv, so the user gets no warning.
Phi-3 128k (longrope) definitions/phi3.py Native AutoConfig fails on 5.22 (KeyError: rope_parameters missing original_max_position_embeddings), so remote code is used. That code has a fused mlp.gate_up_proj, while the definition declares gate_proj/up_proj with strict=True, so quantization fails.

lm_head=True calibrated on the wrong inputs / wrong path

lm_head_pre_quantize_generate_hook (base.py:~3934) applies pre_lm_head_norm_module to the last layer's output.

  • phimoe, falcon_h1, nemotron_h and hrm_text declare no pre-head norm, although model.norm / final_layernorm / norm_f exist. lm_head GPTQ is calibrated on un-normalised hidden states.
  • zamba.py:16 and zamba2.py:17 set it to "lm_head", so the hook runs the head on its own input.
  • Llama4TextQModel inherits lm_head="language_model.lm_head", but Llama4ForCausalLM has lm_head.

Lower

  • Jamba mamba.dt_proj and GRIN-MoE block_sparse_moe.gate are undeclared.
  • KimiLinearNativeQModel.rotary_embedding points at the non-existent model.rotary_emb.
  • mllama cross-attention is left FP (known TODO).

Suggested fix

  • Fix the trees above and add model-specific module-plan tests (per AGENTS.md).
  • Consider a registry-wide test that builds each meta model from its default/local config and fails when any Linear/Conv/expert parameter under the layer stack is neither declared nor tagged :! / :?. Include 3-D expert parameters, not only Linear/Conv.

Note: CI environments with defuser 0.0.29 (below the required 0.0.31) fail the granite awq_relationships cases spuriously.


Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Activity

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

    @Qubitium
    CollaboratorAuthor

    Another definition in the same class, found in a follow-up pass at 9dad249: internvl_chat (models/definitions/internvl_chat.py:34-52) declares only Qwen-style decoder leaves.

    InternVL2 / 2.5 checkpoints with an InternLM2 backbone share the same model_type. Their real decoder leaves (attention.wqkv, attention.wo, feed_forward.w1/w2/w3) are all undeclared. There is no layout variant and no clear rejection, and with layer_modules_strict=True quantization should fail at module_looper.py:~2226.

    import torch
    from transformers import AutoConfig, AutoModel
    from gptqmodel.models.auto import MODEL_MAP
    cfg = AutoConfig.from_pretrained("OpenGVLab/InternVL2-8B-MPO", trust_remote_code=True)
    cfg.vision_config.num_hidden_layers = 1; cfg.llm_config.num_hidden_layers = 1
    m = AutoModel.from_config(cfg, trust_remote_code=True)
    declared = {i.split(":")[0] for s in MODEL_MAP[cfg.model_type].simple_layer_modules(cfg, None) for i in s}
    print([n for n, x in m.language_model.model.layers[0].named_modules() if isinstance(x, torch.nn.Linear) and n not in declared])
    # all 5 InternLM2 leaves undeclared
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

    bugmodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions