Repository navigation
Description
Summary
#6323 added _reject_unvalidatable_shape_blind_selection() to hf_select_quant_linear{,_v2}. It raises ValueError whenever in_features is omitted and the selected kernel is a PackedGroupedQuantLinear without auto-padding and group_size != -1.
Transformers/Optimum always call this bridge before any layer exists, without in_features (Optimum GPTQQuantizer.select_quant_linear(..., pack=False)). The guard therefore refuses the selection for every GPTQ checkpoint, not only the partial-group case it was added for. The selected kernel is valid whenever every layer width is divisible by group_size, but the bridge never checks that — it refuses on the mere absence of the width.
This breaks the plain-HF interop path (AutoModelForCausalLM.from_pretrained) for all GPTQ checkpoints on both CPU and CUDA:
- CPU/AUTO selects
TorchCpuAvx512Linear, which is also aPackedGroupedQuantLinearwithout auto-padding, so it is refused. - CUDA/AUTO selects
MarlinLinear, which is refused for the same reason.
The repo's own existing test for this path is red now:
tests/test_checkpoint_compat.py::test_gptq_block_name_loads_through_plain_hf FAILED
ValueError: hf_select_quant_linear_v2() cannot validate the selected `TorchCpuAvx512Linear`
without the layer shape: `in_features`/`out_features` were not both provided ...
Reproduction (CPU, no GPU)
Build a tiny GPTQ checkpoint whose width is group-aligned (hidden 64, group 16), save it, and load it through plain Transformers:
import torch
from transformers import AutoTokenizer, Qwen2Config, Qwen2ForCausalLM
from gptqmodel import GPTQModel, QuantizeConfig, CalibrationConfig, BACKEND
src = "/tmp/tiny_src"
tok = AutoTokenizer.from_pretrained("/monster/data/model/Qwen2.5-0.5B-Instruct")
vocab = ((len(tok) + 15) // 16) * 16
tok.save_pretrained(src)
torch.manual_seed(0)
Qwen2ForCausalLM(Qwen2Config(vocab_size=vocab, hidden_size=64, intermediate_size=128,
num_hidden_layers=2, num_attention_heads=4, num_key_value_heads=2,
max_position_embeddings=256, tie_word_embeddings=False)).save_pretrained(src)
m = GPTQModel.load(src, QuantizeConfig(bits=4, group_size=16, desc_act=False,
offload_to_disk=False, device="cpu"), dtype=torch.float32)
m.quantize(CalibrationConfig(dataset=["the quick brown fox jumps over the lazy dog and then keeps running through the field while the others watch"] * 8, batch_size=2), backend=BACKEND.GPTQ_TORCH)
m.save("/tmp/tiny_gptq")
from transformers import AutoModelForCausalLM
AutoModelForCausalLM.from_pretrained("/tmp/tiny_gptq") # raisesAt the pre-wave commit 89dbcf91 the same call returns a Qwen2ForCausalLM whose projections carry qweight. At current main (29f58fb1) it raises:
ValueError: hf_select_quant_linear_v2() cannot validate the selected `TorchCpuAvx512Linear`
without the layer shape: `in_features`/`out_features` were not both provided ...
`TorchCpuAvx512Linear` is a grouped kernel that requires `in_features % group_size == 0`
and does not pad a partial group (group_size=16) ...
Direct bridge reproduction (no checkpoint needed):
import torch
from gptqmodel.utils.importer import hf_select_quant_linear_v2
from gptqmodel.quantization import METHOD, FORMAT
hf_select_quant_linear_v2(bits=4, group_size=16, desc_act=False, sym=True,
format=FORMAT.GPTQ, quant_method=METHOD.GPTQ, device_map={"": "cpu"}, pack=False)
# ValueError; group_size=16 divides the fixture's width 64Expected vs actual
Expected: a shape-blind bridge returns a kernel that can build the caller's layers. For a group-aligned checkpoint that is TorchCpuAvx512Linear/MarlinLinear; the per-layer constructor already validates the real width. At worst, only a width the bridge knows is incompatible should be refused.
Actual: the bridge refuses before the width is known, so every plain-HF GPTQ load fails — including models whose widths are valid (the fixture above, hidden 64/g16; the PR's own test_supplied_in_features_keeps_the_previous_selection shows in_features=896 is valid).
Introduced by
339036d504482e24ce893848053486c3e176bc5c (#6323, fix(hf): refuse unvalidatable kernels when the bridge caller omits in_features (#6149)), merged in the 07:55 UTC wave.
Location
gptqmodel/utils/importer.py:
_reject_unvalidatable_shape_blind_selection()(~L1410)hf_select_quant_linear()(~L1512)hf_select_quant_linear_v2()(~L1622)
Suggested fix
Do not treat "no in_features" as evidence that the selection is invalid. Either:
- Keep the historical shape-blind selection and let the per-layer constructor's
validate()reject a partial group (the original [BUG] HF bridge:AutoModelForCausalLM.from_pretrainedof a GPT-QModel GPTQ checkpoint crashes when anyin_featuresis not a multiple ofgroup_size(SmolLM2 hidden=576, g128): bridge returns MarlinLinear without shape info #6149 failure remains a per-layer, actionable error), or - When the width is unknown, prefer a kernel that pads partial groups (e.g. the auto-padding Torch kernel) instead of raising, so group-aligned and partial-group checkpoints both load; or
- Only refuse when the caller supplied a width that provably violates the contract.
Add tests/test_checkpoint_compat.py::test_gptq_block_name_loads_through_plain_hf to the merge gate: it is the end-to-end guard for this path and is currently red.
Activity
Rebase onto abde192: merge #6326 shape fallback with pack/qzeros
fix(hf): fall back to the auto-padding kernel when the bridge has no …