Repository navigation
Description
Summary
#6327 (the fix for #6326) makes hf_select_quant_linear{,_v2} return BACKEND.GPTQ_TORCH for any AUTO,
grouped GPTQ selection made without in_features. Optimum's GPTQQuantizer.select_quant_linear always makes
that call without a shape, and Transformers' GPTQConfig defaults backend="auto". So every
AutoModelForCausalLM.from_pretrained(<gptq checkpoint>, device_map="cuda") now builds TorchLinear for every
layer, including the group-aligned checkpoints that make up nearly every released GPTQ model. Before #6323/#6327
those loads got MarlinLinear. Outputs are still correct (PPL matches), but decode and prefill on CUDA are much
slower, and nothing warns about it. The fallback is only needed for the rare partial-group checkpoint
(#6149, e.g. SmolLM2 with hidden 576/960 at g128), but it now applies to all of them.
Introduced by
f6ae416 (#6327). Before that, 339036d (#6323) refused these loads outright (#6326). At 89dbcf9 the same
loads selected MarlinLinear.
Location
gptqmodel/utils/importer.py at 42827b6 (current main), _needs_shape_safe_gptq_kernel (line 1629) and both callers:
kernel_cls = select_quant_linear(**select_kwargs)
if _needs_shape_safe_gptq_kernel( # line 1726 / 1841
kernel_cls=kernel_cls, group_size=group_size, in_features=in_features,
quant_method=METHOD.GPTQ, backend=backend,
):
select_kwargs["backend"] = BACKEND.GPTQ_TORCH # line 1735 / 1850in_features is always None on the Optimum path (optimum/gptq/quantizer.py::select_quant_linear calls
hf_select_quant_linear_v2(...) with no shape), so the condition holds for every checkpoint with group_size != -1.
Reproduction (ran it; transformers 5.23, optimum, RTX 4090, fp16, device_map="cuda:0")
import torch, collections
from transformers import AutoModelForCausalLM, AutoTokenizer
p = "hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4"
m = AutoModelForCausalLM.from_pretrained(p, device_map="cuda:0", dtype=torch.float16)
print(collections.Counter(type(x).__name__ for x in m.modules() if hasattr(x, "qweight")))
# then time generate(max_new_tokens=128) at batch 1 and a 4x2048 forwardKernel choice, then median-of-3 decode tok/s at batch 1 and prefill tok/s for a 4x2048 forward. The GPU was shared, so
absolute numbers are noisy, but the gap shows up on every run:
| checkpoint | 89dbcf9 | main (#6327) |
|---|---|---|
| hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 | MarlinLinear: 54-80 tok/s, 8.0k prefill | TorchLinear: 31-44 tok/s, 5.9k prefill |
Llama-3.1-8B, main with GPTQConfig(bits=4, backend="marlin") |
MarlinLinear: 81 tok/s, 12.3k prefill | |
| Qwen/Qwen2.5-7B-Instruct-GPTQ-Int4 | MarlinLinear: 62.5 tok/s, 11.9k prefill | TorchLinear: 54.4 tok/s, 7.6k prefill |
| TheBloke/Llama-2-7B-Chat-GPTQ | MarlinLinear: 64.9 tok/s, 6.0k prefill | TorchLinear: 49.3 tok/s, 4.8k prefill |
| Qwen/Qwen2.5-0.5B-Instruct-GPTQ-Int4 | MarlinLinear: 89 tok/s | TorchLinear: 67 tok/s |
PPL (wikitext-2, 2048-token windows) is unchanged, so this is a pure speed regression. For example, Llama-3.1-8B
gives 7.1571 with Marlin and 7.1569 with Torch, and Qwen2.5-0.5B gives 15.986 with both.
Expected vs actual
Expected: group-aligned checkpoints keep the fastest validated CUDA kernel (Marlin) on the plain-HF path. Only
layers that really have a partial group should fall back to an auto-padding kernel. Actual: every layer of every
grouped GPTQ checkpoint is silently built with the portable Torch kernel.
Suggested fix
Decide per layer, not per checkpoint. The bridge cannot see the widths, but the class it returns is built
once per layer with in_features (Optimum _replace_by_quant_layers passes it to the constructor). One option is to
return a thin selector class whose __new__ builds the AUTO kernel (Marlin) when
in_features % group_size == 0 and the auto-padding kernel otherwise. Another is to keep the AUTO kernel and swap
only the non-aligned layers in hf_gptqmodel_post_init. Either way, #6149 stays fixed and aligned
checkpoints keep Marlin. Logging the downgrade would also help.
Activity
fix(hf): keep the AUTO kernel for group-aligned layers on plain-HF loads
fix(hf): consolidate packable selection, per-layer shape dispatch and…
fix(hf): dispatch layer shapes the AUTO kernel cannot build
fix(hf): packable selection, per-layer shape dispatch and legacy qzer…