Repository navigation
Description
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 declaredquant_method/formatfirst. Raise a clearNotImplementedError("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
mxfp4exactly on the format token, not as a substring, somxfp4_macaqdoes 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
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-11788dff99fdfinished 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
fix(export): refuse an hf export whose method has no dense decoder (#…