Skip to content

[BUG] writer/HF interop: Phi-3/Phi-3.5/Phi-4 and GLM-OCR GPTQ checkpoints save the defused mlp.gate_proj/up_proj, so AutoModelForCausalLM.from_pretrained randomly initializes gate_up_proj (PPL 1e11) and save() gives no warning #6166

Done

Description

@Qubitium

Summary

For definitions whose HF module is a fused dense mlp.gate_up_proj (Phi-3 family incl. Phi-3.5-mini and Phi-4, GLM-OCR, and per #4620 also GLM/GLM-4/Zamba2), Defuser splits the projection into gate_proj + up_proj before quantization. The writer serializes the split names (mlp.gate_proj.qweight, mlp.up_proj.qweight, ...). Transformers 5.23's Phi3/GLM-OCR modeling only has mlp.gate_up_proj, so plain from_pretrained reports every gate/up tensor UNEXPECTED and gate_up_proj.* MISSING. It randomly initializes the whole first MLP projection of every layer and returns garbage without raising.

The writer already has hf_compat_warnings() for the equivalent MoE case (experts.<n>.*.qweight vs fused 3-D experts, see #4073). It has nothing for defused dense blocks, so this case is completely silent. The native Transformers load bridge from #3503 handled fused-block rewrites, but #4620 removed it. Since then nothing covers this path.

Introduced by

The dense defuse dates from #2765 (Phi-3 defused MLP mapping). Plain-HF loading of these checkpoints lost its last cover when #4620 (d2dfb93) removed the Transformers bridge from #3503 (472f4c8) and defuser.replace_fused_blocks(). GLM-OCR moved onto the same path in #3558 (24d1b77) and later commits.

Location

HEAD 8ebe255:

  • gptqmodel/models/definitions/phi3.py:27: "mlp": ("gate_proj:0:in=x", "up_proj:0:in=x", "down_proj:1"), (the source checkpoint and HF modeling have mlp.gate_up_proj)
  • gptqmodel/models/definitions/glm_ocr.py:38: "mlp": ("gate_proj:0", "up_proj:0", "down_proj:1"), (HF GlmOcrTextMLP.gate_up_proj)
  • gptqmodel/models/writer.py:325 hf_compat_warnings() only flags experts.<n>. per-expert modules, not defused dense blocks.

Reproduction (ran on RTX 4090, transformers 5.23, optimum installed, default GPTQ 4-bit g128)

from gptqmodel import GPTQModel, GPTQConfig, CalibrationConfig
m = GPTQModel.load("microsoft/Phi-3.5-mini-instruct", GPTQConfig(bits=4, group_size=128))
m.quantize(CalibrationConfig(dataset=c4_texts[:64], batch_size=1)); m.save("phi35-gptq")   # no hf_compat warning logged

from transformers import AutoModelForCausalLM
hf = AutoModelForCausalLM.from_pretrained("phi35-gptq", device_map="cuda:0")
model.layers.{0...31}.mlp.gate_proj.qweight     | UNEXPECTED |
model.layers.{0...31}.mlp.up_proj.qweight       | UNEXPECTED |
  ... (scales/qzeros/g_idx likewise)
model.layers.{0...31}.mlp.gate_up_proj.qweight  | MISSING    |
model.layers.{0...31}.mlp.gate_up_proj.scales   | MISSING    |
  ...
HF   wikitext2 PPL 110621517293.02   generate("The capital of France is") -> ''
NATIVE (GPTQModel.load, same dir)  PPL 6.9043   -> 'Paris.\n\nParis is the capital of France. ...'

GLM-OCR (zai-org/GLM-OCR, quantized with image calibration) behaves the same way. GPTQModel.load reads an OCR test image correctly ('QUANTIZED MODELS\n\nInvoice 4821 total $93.10', same as bf16). AutoModelForImageTextToText.from_pretrained reports mlp.gate_up_proj.* MISSING and generates '_div divid十二章 regener IBtotстра ...'.

Expected vs actual

Expected: a GPTQModel checkpoint either loads correctly through Transformers or, as for MoE experts and lm_head=True, save() warns that only GPTQModel.load/vLLM can read it.
Actual: it loads without error, with every layer's gate/up projection randomly initialized, and nothing warns.

Suggested fix

Preferred: re-fuse on save. For GPTQ/AWQ with desc_act=False, gate_proj and up_proj share in_features and group geometry. Concatenating qweight/scales along the output dim, and qzeros too when N % (32/bits) == 0, gives an exact gate_up_proj that Transformers and vLLM both consume natively. GPTQModel.load would need the inverse split, which Defuser already does for the dense source. At minimum, extend hf_compat_warnings() to flag any definition whose quantized module names differ from the HF module names because of a defused dense block (Phi-3, GLM, GLM-4, GLM-OCR, Zamba2, ...).

Activity

  1. added 3 commits that reference this issue on Nov 29, 2026
    37c361f
    bbae869
    34ffadb
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