You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] HF/Optimum bridge: GPTQ checkpoints that ship no g_idx (AutoRound auto_gptq exports, desc_act=False) load with an uninitialized g_idx -> garbage output (PPL 1e8-1e9) or a crash with every non-Marlin kernel, and since #6327 this is the default from_pretrained path on CUDA #6339
Some desc_act=False GPTQ checkpoints store only qweight/qzeros/scales(/bias) and no g_idx tensor. A
well-known example is the AutoRound auto_gptq export, fbaldassarri/HuggingFaceTB_SmolLM2-1.7B-Instruct-auto_gptq-int4-gs128-sym.
For desc_act=False, GPT-QModel treats g_idx as optional ("Plain contiguous quantization derives the canonical
mapping", checkpoint_required_buffers), and GPTQModel.load does derive arange(in)//group_size for it.
The Transformers/Optimum bridge does not. The layers are built on meta, and Transformers materializes the missing g_idx buffer with uninitialized memory. In practice that is all zeros on CUDA and random int32 values on CPU.
Neither hf_gptqmodel_post_init nor the kernels' post_init repairs the buffer. Marlin ignores g_idx when
desc_act=False, so it is unaffected. Every other kernel that reads g_idx is affected:
On CUDA, TorchLinear and TritonV2Linear read the all-zero g_idx, so every column uses group 0's scales and
zeros. The result is silent garbage (PPL 1.6e9).
On CPU, TorchCpuAvx512Linear (the CPU AUTO pick at 89dbcf9) gives silent garbage (PPL 2.2e8). At HEAD, TorchLinear raises ValueError: TorchLinear: checkpoint g_idx is out of range for 16 scale group(s) (got min=-1403453427, max=2147449099 ...).
At 89dbcf9 the CUDA default selected Marlin, so a plain from_pretrained(..., device_map="cuda") was correct.
Since #6327 the shape-blind bridge always returns TorchLinear (see #6336), so the default CUDA load of these
checkpoints now silently produces garbage.
Introduced by
The missing g_idx derivation on the HF bridge is pre-existing: the CPU path is already wrong at 89dbcf9. f6ae416 (#6327) made it the default CUDA behaviour.
Location
gptqmodel/utils/model.py:2238hf_gptqmodel_post_init at 42827b6 (current main). It runs after Transformers
has loaded the packed tensors, but nothing there or in the kernels' post_init rebuilds a g_idx that the
checkpoint did not supply.
gptqmodel/nn_modules/qlinear/__init__.py:1934checkpoint_required_buffers. For desc_act=False, g_idx
is declared optional because the canonical mapping is derivable, but the derivation exists only on the GPTQModel.load path.
importtorchfromtransformersimportAutoModelForCausalLMp="fbaldassarri/HuggingFaceTB_SmolLM2-1.7B-Instruct-auto_gptq-int4-gs128-sym"# no g_idx tensors in model.safetensorsm=AutoModelForCausalLM.from_pretrained(p, device_map="cuda:0", dtype=torch.float16)
q=m.model.layers[0].self_attn.q_projprint(type(q).__name__, q.g_idx[-4:]) # TorchLinear tensor([0, 0, 0, 0]); canonical would end in 15
The load report also lists model.layers.{0...23}.self_attn.q_proj.g_idx | MISSING.
wikitext-2 PPL, first 4 x 2048 tokens (512 on CPU):
ValueError: checkpoint g_idx is out of range ... min=-1403453427
GPTQModel.load(p, backend=BACKEND.GPTQ_TORCH), cuda / cpu
TorchLinear (g_idx [0..15])
13.7 / 13.6
Expected vs actual
Expected: a desc_act=False checkpoint without g_idx loads through Transformers with the canonical contiguous
mapping, the same as GPTQModel.load, on every kernel. Actual: the buffer is left uninitialized. Non-Marlin kernels
then return garbage or crash, and the default CUDA path now hits this.
Suggested fix
In hf_gptqmodel_post_init, or in BaseQuantLinear.post_init before the kernel-specific transforms, rebuild g_idx = arange(in_features) // group_size for desc_act=False layers when the checkpoint did not supply it. GPTQModel.load already derives that mapping. Transformers reports the missing keys
(loading_info["missing_keys"]), or the bridge can detect an out-of-range or non-monotone g_idx on a
desc_act=False layer. As a fallback, refuse the load with a clear error instead of producing garbage.
Activity
fix(hf): derive missing g_idx for bridge loads (ModelCloud#6339) (Mod…