Repository navigation
Description
Describe the bug
At 0b94d79c67, the cases below violate the stated supported contract. The validation scope for each case is explicit; source/dispatch proofs are not device numerical qualification.
CPU INT8 dequantization forgets packed tail padding after cache invalidation
Severity: P2
Contract and impact
Logical [in_features,out_features] decoding must be independent of whether the derived INT8 runtime cache is populated.
For an accepted K not divisible by four, ordinary dtype/device application or source reload clears the runtime view; dequantize_weight then crashes until a forward rebuilds the view. Explicit dequantization/export can therefore fail depending on call order.
To reproduce / evidence
TorchInt8Linear bits=8, group_size=-1, sym=False, in_features=17, out_features=8. It validates, transforms, and forwards correctly. Call .to(dtype=torch.float32) after transform_cpu; dequantize_weight now takes the raw checkpoint path.
from gptqmodel.nn_modules.qlinear.torch_int8 import TorchInt8Linear; import torch; m=TorchInt8Linear(bits=8,group_size=-1,sym=False,desc_act=False,in_features=17,out_features=8,bias=False).eval(); m.scales.fill_(1); m.transform_cpu(dtype=torch.float32); print(m.dequantize_weight().shape); m.to(dtype=torch.float32); print(m.dequantize_weight().shape). First prints (17,8); second raises a 20-vs-17 row mismatch. All-zero initialized codes/zero-points describe a valid zero matrix. m(torch.ones(1,17)) succeeds before and after, and rebuilding by forward restores dequantize_weight. Control K16 succeeds throughout.
Observed and expected behavior
Observed RuntimeError: size of tensor a (20) must match size of tensor b (17) at non-singleton dimension 0. Expected a zero (17,8) decoded matrix in every cache state. validate(...in_features=17...) returned True.
Public source and history
GPTQModel/gptqmodel/nn_modules/qlinear/torch_int8.py
Lines 434 to 468 in 0b94d79
| def dequantize_weight(self, num_itr: int = 1): | |
| if num_itr != 1: | |
| raise NotImplementedError("TorchInt8Linear dequantize_weight only supports num_itr == 1.") | |
| # Explicit dequantized export still reflects the native INT8 runtime | |
| # when it is current; conversion always decodes the GPTQ source below. | |
| if self.int8_module is not None and self._int8_source_signature == self._source_signature(): | |
| dequantized = _cached_int8_dequantize(self) | |
| if dequantized is not None: | |
| return dequantized | |
| return self._dequantize_gptq_source_weight() | |
| def _dequantize_gptq_source_weight(self): | |
| if not self._has_all_gptq_buffers(): | |
| raise RuntimeError("TorchInt8Linear missing GPTQ buffers for dequantization.") | |
| self._ensure_unpack_buffers() | |
| zeros = torch.bitwise_right_shift( | |
| torch.unsqueeze(self.qzeros, 2).expand(-1, -1, self.pack_factor), | |
| self.wf_unsqueeze_zero, | |
| ).to(self.dequant_dtype) | |
| zeros = torch.bitwise_and(zeros, self.maxq).reshape(self.scales.shape) | |
| weight = torch.bitwise_and( | |
| torch.bitwise_right_shift( | |
| torch.unsqueeze(self.qweight, 1).expand(-1, self.pack_factor, -1), | |
| self.wf_unsqueeze_neg_one, | |
| ).to(self.dequant_dtype), | |
| self.maxq, | |
| ) | |
| weight = weight.reshape(weight.shape[0] * weight.shape[1], weight.shape[2]) | |
| groups = _normalize_g_idx(self.g_idx, int(self.scales.shape[0])) | |
| return self.scales[groups] * (weight - zeros[groups]) |
GPTQModel/gptqmodel/nn_modules/qlinear/torch_int8.py
Lines 503 to 529 in 0b94d79
| zeros = torch.bitwise_right_shift( | |
| torch.unsqueeze(self.qzeros, 2).expand(-1, -1, self.pack_factor), | |
| self.wf_unsqueeze_zero, | |
| ).to(self.dequant_dtype) | |
| zeros = torch.bitwise_and(zeros, self.maxq).reshape(self.scales.shape) | |
| codes = torch.bitwise_and( | |
| torch.bitwise_right_shift( | |
| torch.unsqueeze(self.qweight, 1).expand(-1, self.pack_factor, -1), | |
| self.wf_unsqueeze_neg_one, | |
| ).to(self.dequant_dtype), | |
| self.maxq, | |
| ).reshape(-1, self.out_features) | |
| codes = codes[:self.in_features] | |
| num_groups = int(self.scales.shape[0]) | |
| groups = _normalize_g_idx(self.g_idx, num_groups) | |
| group_lengths, _ = _group_layout(groups, num_groups) | |
| packed_channels = sum(group_lengths) | |
| if packed_channels != self.in_features: | |
| raise NotImplementedError( | |
| "TorchInt8Linear requires exactly one g_idx entry per input channel; " | |
| f"got {packed_channels} entries for in_features={self.in_features}." | |
| ) | |
| # Channels are stored group-contiguously so one kernel launch per | |
| # quantization group covers every channel of that group. Stable sorting |
GPTQModel/gptqmodel/nn_modules/qlinear/__init__.py
Lines 545 to 548 in 0b94d79
| def _apply(self, fn, recurse=True): | |
| result = super()._apply(fn, recurse=recurse) | |
| self._clear_runtime_weight_cache() | |
| return result |
Raw unsliced decoding predates the window; blame points to f37660b. 31c26c9 #3804 adds the correct logical crop to direct runtime repacking while retaining the uncropped raw dequantizer. This is a parallel path gap, not a demonstrated reintroduction. Attribution caveat: f37660b is the unsliced decoder origin, not independently established support for the K17 case at that date. Treat #3804 as broader runtime tail exposure plus an uncorrected sibling decoder, not a repeated repair.
Existing reports
All-state int8+dequant public issue search found no exact duplicate. #3985 concerns other load/dequant performance/device issues; #3804 states exact checkpoint decoding but its ragged coverage does not exercise this cold-source tail state. Duplicate-search scope was the bounded public all-state queries and the cited issue threads; absence is not proof no report exists.
Software / device info and validation limits
Real CPU tensors, native INT8 runtime conversion/forward and raw dequantizer on Torch 2.15.0+cpu; no GPU involved. The probe avoids post_init compile and calls the shipped transform_cpu directly. Independently ran the entire current tests/kernels/test_torch_int8.py:65 passed. New K17/18/19 cache-cold probes fail while K16 succeeds.
Model / datasets
The evidence uses tiny synthetic tensors or local fixtures derived from the public tests; no private model or dataset is required. Device execution that remains untested is stated above.
Activity
Qubitium commentedon Nov 16, 2026
Taking this. I'll investigate against current
main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.fix(int8): pad group codes to the kernel's contraction alignment (#4512)