Skip to content

[BUG] loader: 3-bit GPTQ checkpoints saved by GPT-QModel < 7.0 (e.g. 5.6.12, 6.0.3) load at HEAD without any warning and produce garbage (PPL 13.9 -> 107252): #2763 changed the INT3 v1 qzeros offset but added no compatibility path for older checkpoints #6375

Description

@Qubitium

Summary

A 3-bit GPTQ checkpoint saved by GPT-QModel 5.6.12 or 6.0.3 with the default format="gptq" (v1) loads at HEAD with no error or warning, through both GPTQModel.load and AutoModelForCausalLM.from_pretrained. The output is garbage. The same checkpoint is fine when loaded by the release that wrote it:

checkpoint (TinyLlama-1.1B-Chat-v1.0, bits=3, group_size=128, sym=True, desc_act=False) loaded by wikitext-2 PPL (40x512, BOS per window) generate("The capital of France is")
saved by 6.0.3 6.0.3 (TorchQuantLinear) 13.917 Paris. The capital of France is Paris. ...
saved by 6.0.3 HEAD GPTQModel.load (TorchLinear) 107252.6 iatiatiatiatiat...
saved by 6.0.3 HEAD from_pretrained 107252.6 iatiatiat...
saved by 5.6.12 5.6.12 14.206 Paris, which is also the largest city in France...
saved by 5.6.12 HEAD GPTQModel.load 107115.8 iatiatiat...
6.0.3 checkpoint, qzeros re-encoded (see below) HEAD GPTQModel.load 13.919 Paris. The capital of France is Paris. ...

For comparison, the AutoGPTQ 3-bit checkpoint kaitchup/Llama-2-7b-hf-gptq-3bit loads correctly at HEAD (PPL 9.25), as do 4-bit and 8-bit checkpoints from the same 5.6.12/6.0.3 runs (TinyLlama 4-bit g128: PPL 11.05 at HEAD; 8-bit: 10.50).

Cause: before 7.0, convert_gptq_v1_to_v2_format_module and convert_gptq_v2_to_v1_format_module used per-word constant offsets for INT3 qzeros with the word-0 and word-2 constants swapped. Word 0 got 0b00100100... (0x24924924), word 1 got 0x92492492, and word 2 got 0b01001001... (0x49249249). The canonical 10-1-10-1-10 layout needs 0x49249249 for word 0 and 0x24924924 for word 2. Save applied -= with these constants and load applied the matching +=, so a 1.x-6.x checkpoint round-tripped inside the release that wrote it. On disk, though, its qzeros are not canonical v1. Decoding row 0 of a sym checkpoint, where every stored zero should be 3, gives [0]*10, 4, [3]*10, 3, [2]*10.

#2763 (8e8ff11, "fix int3 qzero format conversion", first released in 7.0.0) switched loading to the canonical logical-field shift, which is correct for AutoGPTQ and other third-party INT3 checkpoints. It added no path for checkpoints that GPT-QModel itself wrote before the fix. Those checkpoints say "meta": {"quantizer": ["gptqmodel:6.0.3"]} (or an older version), so they can be identified.

Introduced by

8e8ff11 (#2763), released in v7.0.0. The swapped constants it replaced go back to 2d9dc85 (#89) and 918ed30 (#1218, v1.8.0). So any GPTQ v1 3-bit checkpoint saved by GPT-QModel from that point through 6.0.x is probably affected. I checked 5.6.12 and 6.0.3.

Location (origin/main 0dd8e8a)

gptqmodel/utils/model.py:1164-1175 (convert_gptq_v1_to_v2_format_module):

    if bits in (2, 4, 8) or (bits == 3 and pack_dtype == torch.int32):
        module.qzeros.data.copy_(
            _correct_gptq_v1_qzeros(module.qzeros.data, bits, planar=getattr(module, "planar", False))
        )

The legacy constants are still in the same function (:1176+), but only for non-int32 pack dtypes. Nothing checks meta.quantizer.

v6.0.3 gptqmodel/utils/model.py:630-668 (the writer/reader pair that produced the checkpoints):

    elif bits == 3:
        # range 0 offset
            offset = 0b00100100100100100100100100100100      # int32, word 0
        module.qzeros.data[:, range(0, module.qzeros.data.shape[1], 3)] += offset
        # range 1 offset
            offset = 0b10010010010010010010010010010010      # word 1
        # range 2 offset
            offset = 0b01001001001001001001001001001001      # word 2

Reproduction (ran it)

  1. Quantize with an older release. I used a v6.0.3 tree with transformers 5.4.0, and a v5.6.12 tree with transformers 4.57.1:
from gptqmodel import GPTQModel, QuantizeConfig
m = GPTQModel.load("TinyLlama/TinyLlama-1.1B-Chat-v1.0", QuantizeConfig(bits=3, group_size=128, desc_act=False, sym=True))
m.quantize(c4_texts_128, batch_size=8)
m.save("tinyllama-3bit-v603")
  1. Load at HEAD:
from gptqmodel import GPTQModel
m = GPTQModel.load("tinyllama-3bit-v603", device="cuda:0")
ids = m.tokenizer("The capital of France is", return_tensors="pt").to("cuda:0")
print(m.tokenizer.decode(m.generate(**ids, max_new_tokens=24, do_sample=False)[0]))   # 'iatiatiatiat...'
  1. Root-cause check. In each qzeros tensor, add back the old per-word offsets (0x24924924, 0x92492492, 0x49249249 for words 0, 1, 2) to recover the true zero points. Then re-encode them as canonical v1 (decode the 3-bit fields, subtract 1 per field, repack 10-1-10-1-10) and leave qweight, scales and g_idx unchanged. HEAD then loads the checkpoint with PPL 13.919, matching 6.0.3's own 13.917. An independent numpy AutoGPTQ-layout dequantizer agrees with HEAD's TorchLinear dequant to a relative error of 2e-4 on both the 6.0.3 file and the kaitchup checkpoint. 6.0.3's own dequant of its file differs from it (relative error 0.92). So HEAD reads the canonical layout correctly, and the old files are simply not in that layout.

Downstream check: ARC-Easy, first 500 test questions, log-likelihood scoring with lm-eval's arc_easy prompt and the default BOS, on the 6.0.3 3-bit checkpoint:

loaded by acc acc_norm
6.0.3 (writer) 0.560 0.518
HEAD, file as saved 0.248 (chance, 4 choices) 0.248
HEAD, qzeros re-encoded to canonical v1 0.550 0.520

Expected vs actual

  • Expected: a 3-bit checkpoint written by an earlier GPT-QModel release loads correctly, or at least fails loudly. It should never be silently decoded with a zero-point layout it was not written in.
  • Actual: it loads without any message and outputs garbage, on every GPTQ kernel that supports 3-bit (TorchLinear here, also used by the HF path).

Suggested fix

When bits == 3, checkpoint_format == "gptq" (v1) and meta.quantizer names gptqmodel:<version> with a version below 7.0.0, apply the pre-#2763 per-word offsets on load (+0x24924924 / +0x92492492 / +0x49249249 on words 0/1/2) instead of the logical shift. Or convert those qzeros to canonical v1 once at load. A save() of such a model would then write canonical qzeros. Checkpoints without a gptqmodel meta.quantizer (AutoGPTQ, optimum, AutoRound) must stay on the canonical path. If version-gated decoding is not wanted, refuse to load these checkpoints with a message that names the converter. Add a regression test with a small 3-bit fixture packed by the pre-7.0 constants.

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