Skip to content

[BUG] export(..., "hf") silently writes garbage dense weights for Paro and MACaQ checkpoints: detect_format() sniffs Paro as AWQ and MACaQ ('mxfp4_macaq') as MXFP4, dropping rotations/Hadamard (nll 1.49 -> 13.28) #4786

Closed

Description

@Qubitium

Found on main @ dba142d, RTX 5090 (CUDA 13.2, torch 2.15, transformers 5.22).

What is wrong

GPTQModel.export(path, out, "hf") sends every checkpoint to utils/model_dequant.dequantize_model(). That function picks a decoder with detect_format() (gptqmodel/utils/model_dequant.py:644). detect_format() guesses from tensor names first and never checks the declared quant_method against a list of supported methods. As a result, two GPT-QModel formats are decoded as a different format. The export reports success and writes a dense checkpoint with wrong weights and no quantization_config:

checkpoint (quant_method) detect_format() returns why result
Paro (paro) awq it has .qweight and no .g_idx (:758-765) theta / pairs / channel_scales are dropped and the rotated codes are decoded as plain AWQ. Silent garbage.
MACaQ (macaq, format: "mxfp4_macaq") mxfp4 the substring "mxfp4" is in the declared format (:678) BH (Hadamard) and pre_scale are ignored. Silent garbage.
GGUF (gptqmodel_gguf) awq .qweight without .g_idx KeyError: Incomplete AWQ buffers ... missing {'qzeros','scales'}: loud, but the message is misleading
QQQ / NF12 / VPTQ none ValueError: Unable to detect quantization format: loud, OK

The exported config has no quantization_config, so nothing downstream can tell that the weights are wrong. The checkpoint loads in plain transformers and runs, but the output is garbage.

Repro (full Qwen2.5-0.5B-Instruct, 64 C4 samples)

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import CalibrationConfig, ParoConfig, MacaqConfig
from transformers import AutoModelForCausalLM

src = "Qwen/Qwen2.5-0.5B-Instruct"
for name, cfg in (("paro", ParoConfig(bits=4, group_size=128)), ("macaq", MacaqConfig())):
    m = GPTQModel.load(src, cfg, dtype=torch.float16)
    m.quantize(CalibrationConfig(dataset=calib_texts)); m.save(f"q_{name}"); del m
    q = GPTQModel.load(f"q_{name}", dtype=torch.float16)
    ids = q.tokenizer(TEXT, return_tensors="pt").input_ids.cuda()
    a = q.model(ids).logits
    GPTQModel.export(f"q_{name}", f"q_{name}_hf", "hf")        # no error
    h = AutoModelForCausalLM.from_pretrained(f"q_{name}_hf", dtype=torch.float16, device_map="cuda:0")
    b = h(ids).logits
    nll = lambda lo: torch.nn.functional.cross_entropy(lo[0, :-1].float(), ids[0, 1:]).item()
    print(name, nll(a), nll(b), (a - b).abs().max().item())

Output (the fp16 base model has nll 1.455 on the same text):

paro   GPTQModel.load nll 1.487 | exported dense nll 13.279 | max logit diff 26.38
macaq  GPTQModel.load nll 1.734 | exported dense nll 12.641 | max logit diff 28.17

detect_format() on the saved checkpoints: paro -> awq, macaq -> mxfp4, gptqmodel_gguf -> awq.

As a control, RTN (GPTQ layout) and FP8 checkpoints from the same harness export correctly: max logit diff 0.016 vs GPTQModel.load, KL 6e-5.

Suggested fix

  • In dequantize_model(), read the declared quant_method / format first. Raise a clear NotImplementedError("export(..., 'hf') does not support <method> checkpoints") for every GPT-QModel method that has no dense decoder. Today that is Paro, MACaQ, GGUF, QQQ, NF12, VPTQ and EXL3. Use tensor-name sniffing only when no method is declared, for legacy or third-party checkpoints.
  • Match mxfp4 exactly on the format token, not as a substring, so mxfp4_macaq does not count as MXFP4.
  • Alternatively, implement dense decoders for these methods. Paro and MACaQ already have Torch reference kernels whose dequantize_weight()-style paths could be reused.

Test that should have caught it

tests/test_export.py covers GPTQ, AWQ, quantized embeddings and legacy configs only. A parametrized test that saves a tiny checkpoint for every METHOD GPT-QModel writes should require one of two outcomes from export(..., "hf"): the dense logits match GPTQModel.load, or the export raises. That test would catch both silent cases.

Severity

High for Paro and MACaQ: the documented export path reports success and produces a dense model with garbage weights (nll 1.5 -> 13). Low for GGUF, where the error is loud but misleading.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-11788dff99fd finished this issue.

    Pull request: #4824

    Reproducing the Paro/MACaQ export misdetection on CPU; will make the declared quant_method decide and fail closed for methods with no dense decoder

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