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] CPU AUTO picks TorchAten/TorchFused for in_features % group_size != 0, first forward crashes (SmolLM2 hidden=576, gs=128); #4326 fix for #4181 incomplete #4571
Found on main @ 4b65923, CPU (host with AVX512-BF16), torch 2.15. The checkpoint was made on an RTX 4090.
What is wrong
#4326 (fix for #4181) added _validate_cpu_int4pack_group_size (gptqmodel/nn_modules/qlinear/torch_fused.py:70-100, also used by TorchAtenLinear). It only checks that the resolved group size is in {32, 64, 128, 256}. It does not check that in_features % group_size == 0. aten::_weight_int4pack_mm_for_cpu requires that too:
RuntimeError: _weight_int4pack_mm_cpu: expect K to be divisible by qGroupSize, got K:576, qGroupSize:128
GPTQ supports a partial last group (K=576, gs=128 -> groups of 128,128,128,128,64), and TorchLinear, TorchInt8, TorchCpuAvx512, Marlin, ExLlamaV2, TritonV2 and AllSpark all run it correctly in my fuzz. TorchAtenLinear and TorchFusedLinear validate the layer, so AUTO on CPU selects them, and the first forward then crashes. On this AVX512 host AUTO picked TorchCpuAvx512Linear only for down_proj (K=1536). Every K=576 projection got TorchAtenLinear. On hosts without AVX512-BF16, every layer goes to Aten/Fused.
Real models with this shape include SmolLM2-135M (hidden 576) and SmolLM2-360M (hidden 960), quantized with the default group_size=128.
Repro (public API)
Tiny Llama with the SmolLM2-135M geometry (hidden 576, intermediate 1536, 9 heads / 3 KV heads, 2 layers, random weights). GPTQConfig(bits=4, group_size=128) quantize + save on CUDA, then:
q=GPTQModel.load(saved, device="cpu", dtype=torch.bfloat16) # AUTO# kernels: {'TorchAtenLinear': [gate_proj, k_proj, o_proj, q_proj, up_proj, v_proj],# 'TorchCpuAvx512Linear': [down_proj]}q.model(torch.randint(100, 2000, (1, 8)))
# RuntimeError: _weight_int4pack_mm_cpu: expect K to be divisible by qGroupSize, got K:576, qGroupSize:128
At module level, TorchAtenLinear and TorchFusedLinear raise the same error for (K, gs) = (320, 128), (288, 64), (288, 128), (4160, 128), with any bits/sym/desc_act, fp16 and bf16, while validate() returns True.
A related, lower-priority gap: with a non-uniform g_idx (ragged groups, the layout #4511 calls supported for the INT8 path), TorchAtenLinear, TorchFusedLinear and TorchCpuAvx512Linear silently return wrong outputs (rel err 0.15-0.46 vs the dequantize reference). build_group_ret_idx documents that it assumes equal-size groups. TorchInt8Linear and TorchLinear handle it correctly.
Suggested fix
In _validate_cpu_int4pack_group_size, also reject in_features % resolved != 0 when in_features is known. Per-module selection passes it, and AUTO then falls through to TorchLinear / TorchInt8Linear. Optionally, pad K to the next multiple of the group in transform_cpu (zero codes, zero activations) as TorchInt8Linear does since #4512. For the ragged case, reject a non-uniform g_idx in post_init/_load_from_state_dict, or route it to TorchLinear.
Test that should have caught it
tests/test_cpu_kernel_constraints_4181.py covers odd N and gs == K. It needs a K % group_size != 0 case (for example K=576, gs=128) for both CPU int4pack kernels, through AUTO selection and a forward.
Severity
Medium-high: GPTQ checkpoints whose hidden or intermediate size is not a multiple of the group size cannot run on CPU with the default backend.
Activity
Qubitium commentedon Nov 17, 2026
Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.
fix(cpu): validate int4pack geometry and serialize first-forward repa…