Repository navigation
Description
Summary
Optimum constructs the bridge-selected class positionally:
self.quant_linear(self.bits, self.group_size, self.desc_act, self.sym, in_features, out_features, bias, weight_dtype=...)
(optimum/gptq/quantizer.py::_replace_by_quant_layers). MarlinLinear, TritonV2Linear, ExllamaV2Linear and
GPTQQuantLinear declare (bits, group_size, desc_act, sym, ...) and match that order. The portable GPTQ kernels
declare (bits, group_size, sym, desc_act, ...): TorchLinear, TorchAtenLinear (so also TorchCpuAvx512Linear)
and TorchFusedLinear. Every Optimum-built layer of those classes therefore gets sym and desc_act swapped.
For the usual sym=True, desc_act=False checkpoint, the layer gets sym=False, desc_act=True.
This went mostly unnoticed because Marlin was the CUDA default. Since #6327, every shape-blind HF load returns
TorchLinear, on CUDA and on CPU. Then #6344 (the fix for #6339) added if use_act_order or getattr(module, "desc_act", False): raise ValueError(...) to _repair_bridge_missing_g_idx. That check now reads the swapped
desc_act=True, so the checkpoints #6339 is about fail to load instead of being repaired. On current main,
AutoModelForCausalLM.from_pretrained("fbaldassarri/HuggingFaceTB_SmolLM2-1.7B-Instruct-auto_gptq-int4-gs128-sym")
(desc_act=False, sym=True, no g_idx) raises on both CUDA and CPU:
ValueError: `model.layers.0.self_attn.k_proj` is a GPTQ layer with `desc_act=True`, but its checkpoint supplied no
usable `g_idx` (the loaded buffer is not a permutation of 16 group(s) over 2048 input rows). Activation-order GPTQ
cannot be reconstructed without the checkpoint's group index. ...
I instrumented _repair_bridge_missing_g_idx. It is called with use_act_order=False, which is correct, but the
layer reports TorchLinear desc_act=True.
Introduced by
The parameter-order mismatch is pre-existing. TorchLinear has had (bits, group_size, sym, desc_act, ...) since
at least 15a6cc3 (Dec 2024). f6ae416 (#6327) made TorchLinear the default HF kernel. 0a5b67a (#6344) turned
the swapped desc_act into a hard load failure.
Location (at be14824, current main)
gptqmodel/nn_modules/qlinear/torch.py:458-459,torch_aten_kernel.py:221-222andtorch_fused.py:334-335
declaresym: bool, desc_act: bool.marlin.py:149-150declaresdesc_act: bool, sym: bool.gptqmodel/utils/model.py:2277if use_act_order or getattr(module, "desc_act", False):trusts the layer attribute.
Reproduction (ran it; transformers 5.23 + optimum, RTX 4090 and CPU)
import torch
from transformers import AutoModelForCausalLM
m = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct-GPTQ-Int4", device_map="cuda:0", dtype=torch.float16)
q = m.model.layers[0].self_attn.q_proj; qc = m.config.quantization_config
print(type(q).__name__, q.sym, q.desc_act, "| config", qc.sym, qc.desc_act)
# TorchLinear False True | config True False (same with device_map="cpu")
AutoModelForCausalLM.from_pretrained("fbaldassarri/HuggingFaceTB_SmolLM2-1.7B-Instruct-auto_gptq-int4-gs128-sym",
device_map="cuda:0", dtype=torch.float16)
# main (0a5b67a7e / be1482448): ValueError ... is a GPTQ layer with `desc_act=True` ... (cuda and cpu)
# abde192ed: loads, but PPL 1.6e9 (#6339); 89dbcf91b (Marlin): PPL 21.9Expected vs actual
Expected: Optimum-built layers carry the checkpoint's sym/desc_act, and the #6344 repair derives the canonical
g_idx for this desc_act=False checkpoint. Actual: the portable kernels swap the two flags. The repair then refuses
the load, and any other code that reads layer.sym/layer.desc_act on an HF-loaded model sees the wrong values.
Suggested fix
Make the constructor contract the same across all GPTQQuantLinear subclasses: either reorder
TorchLinear/TorchAtenLinear/TorchFusedLinear (and their AWQ/int8 siblings, if Transformers' AWQ path ever
calls them positionally) to (bits, group_size, desc_act, sym, ...), or have the bridge return a thin subclass or
factory that maps Optimum's positional order to keywords. Also, in _repair_bridge_missing_g_idx, decide with the
use_act_order that Optimum passes from the checkpoint config rather than the layer attribute. A regression test that
builds the selected class positionally, the way Optimum does, would catch this.
Activity
fix(hf): align W4A GPTQ kernel positional order with Optimum
fix(hf): align portable GPTQ kernel positional order with Optimum (Mo…