Repository navigation
Description
Summary
Before #2983, GPT-QModel (and AutoGPTQ) sized and packed qzeros as out_features // 32 * bits (rounded down). #2983 changed the buffer to ceil(out_features / pack_factor). The two formulas give different widths whenever out_features % 32 != 0, so every older GPTQ checkpoint with such a projection now fails to load, both through GPTQModel.load and through AutoModelForCausalLM.from_pretrained.
The most visible case is the Mamba2 hybrids. Granite-4.0-H mamba.in_proj has out_features = 3376. ModelCloud's own published ModelCloud/Granite-4.0-H-350M-GPTQMODEL-W4A16 (quantizer gptqmodel:5.1.0-dev, 4-bit, g32, sym=True) stores in_proj.qzeros as [24, 420]. HEAD allocates [24, 422] and the load stops:
ValueError: Trying to set a tensor of shape torch.Size([24, 420]) in "qzeros" (which has shape torch.Size([24, 422])), this looks incorrect.
The checkpoint data itself is fine. It is symmetric, so every stored qzeros word is 0x77777777 and the missing tail words carry no information. Padding the two missing words per row with the same constant makes HEAD load the model and produce correct output (see below). The checkpoint was produced and published by GPT-QModel, and the GPT-QModel version that wrote it loaded it.
Introduced by
079edcc "fix(qlinear): size GPTQ buffers by pack_factor ..." (#2983). It changed _register_gptq_buffers from out_features // self.pack_dtype_bits * self.bits to math.ceil(out_features / self.pack_factor), and the later 1c8020f (#2985) changed it to math.ceil(out_features * bits / pack_dtype_bits). The new width is correct for new checkpoints. However, no compatibility path was added for the legacy floor-sized qzeros that GPT-QModel <= ~5.x and AutoGPTQ wrote. It is still present at HEAD 8ebe255.
Location
gptqmodel/nn_modules/qlinear/__init__.py:1994 (HEAD 8ebe255), _register_gptq_buffers:
self.register_buffer(
"qzeros",
t.zeros(
(
math.ceil(in_features / self.group_size),
math.ceil(out_features * self.bits / self.pack_dtype_bits),
),The loaders then hand the checkpoint tensor to accelerate's set_module_tensor_to_device (GPTQModel.load) or to the Transformers loading report (from_pretrained), and both reject the shape.
Reproduction (ran it, RTX 4090, HEAD 8ebe255, transformers 5.23)
from gptqmodel import GPTQModel
m = GPTQModel.load("ModelCloud/Granite-4.0-H-350M-GPTQMODEL-W4A16")
# ValueError: Trying to set a tensor of shape torch.Size([24, 420]) in "qzeros" (which has shape torch.Size([24, 422])), this looks incorrect.
from transformers import AutoModelForCausalLM
AutoModelForCausalLM.from_pretrained("ModelCloud/Granite-4.0-H-350M-GPTQMODEL-W4A16", device_map="cuda:0")
# model.layers.{0...31}.mamba.in_proj.qzeros | MISMATCH | Reinit due to size mismatch - ckpt: torch.Size([24, 420]) vs model:torch.Size([24, 422])
# RuntimeError: You set `ignore_mismatched_sizes` to `False`, thus raising an error.Checkpoint contents: model.layers.0.mamba.in_proj.qweight [96, 3376], scales [24, 3376], qzeros [24, 420]. All 32 in_proj.qzeros tensors hold only 0x77777777.
Then I padded each in_proj.qzeros to 422 columns with 0x77777777 (no other change) and reloaded with GPTQModel.load at HEAD:
LOADED KERNELS ['MarlinLinear', 'TorchLinear'] DTYPE torch.bfloat16
GEN 'The capital of France is Paris.'
PPL 32.517 (wikitext-2, 40x512 tokens; unquantized ibm-granite/granite-4.0-h-350m: 27.907)
Expected vs actual
- Expected: GPTQ checkpoints written by earlier GPT-QModel releases, including ModelCloud's own published ones, still load and generate at HEAD.
- Actual: any such checkpoint with a quantized projection whose
out_features % 32 != 0fails to load on both the GPT-QModel and the HF paths. This affects the Granite-4.0-H family (mamba.in_proj= 3376) and other Mamba2 hybrids whosein_projwidth includes the head count.
Suggested fix
When a GPTQ (v1 or v2) checkpoint's qzeros has exactly out_features // 32 * bits columns instead of ceil(out_features * bits / 32), treat it as the legacy layout:
- If
sym=True, the zero point is constant, so pad the missing tail words with the symmetric zero word (0x77777777for 4-bit v1, the v2 equivalent for gptq_v2) during load. Do this both inGPTQModel.loadand in the HF bridge (e.g. a load-state-dict pre-hook on the GPTQ quant linear). - If
sym=False, the tail zero points were never written, so raise a clear error that names the legacy layout instead of the generic accelerate shape error.
Add a regression test with a GPTQ module of out_features 3376 (or any width with % 32 != 0) serialized in the legacy width.
Activity
fix(hf): packable kernel selection and legacy floor-width qzeros in t…
fix(hf): packable kernel selection and legacy floor-width qzeros in t…
fix(hf): consolidate packable selection, per-layer shape dispatch and…
fix(hf): keep legacy qzeros markers across kernel reselect (#6152)
fix(hf): packable selection, per-layer shape dispatch and legacy qzer…
fix(hf): reselect offload-safe kernels for Marlin at post-init (#6152) (