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] GPTAQ/FOEM crash at batch_size>1; pack_gpu truncates 3-bit qzeros; GPTQ fallback strategies lose group offset #3978
1. GPTAQ, and FOEM with alpha>0, crash for calibration batch_size > 1
gptqmodel/quantization/gptaq.py:43-46, 77-124
gptqmodel/quantization/foem.py:116-209
interacting with looper/gptq_processor.py:594-623 and looper/native_processor.py:101
NativeProcessor stores one entry per forward batch, already masked and flattened to [N_kept_total, H]. GPTQProcessor sets preserve_batch_keep_mask and calls add_batch once per sample. process_batch does native_inps.pop(0) on every call, so sample 0 consumes the whole batch's tensor.
Repro:
sample 0 ERR RuntimeError The size of tensor a (8) must match the size of tensor b (3) at non-singleton dimension 1
sample 1 ERR IndexError pop from empty list
Tests only use QUANT_BATCH_SIZE = 1.
Fix: split the native entry per sample with the same keep mask, or reject batch_size > 1 for GPTAQ/FOEM.
gptqmodel/nn_modules/qlinear/__init__.py:1834-1841: groups = zeros_int.shape[1] // word_bits drops the tail columns.
For 3-bit, K=128, N=48, pack_gpu succeeds but qzeros is (4,3) instead of the registered (4,5). It then fails later in post_init/dequant (shape '[k,48]' is invalid), or a truncated checkpoint gets written.
hf_pack_layer(pack_impl="auto") prefers gpu on CUDA and only falls back on ValueError/NotImplementedError, which this path never raises.
TorchLinear validation accepts the shape (SUPPORTS_OUT_FEATURES_DIVISIBLE_BY=[1]).
pack_original hits IndexError on the same shape; pack_block raises ValueError.
Fix: raise ValueError for 3-bit with N%32≠0 in pack_gpu (and reject the shape in _validate), or implement tail packing in both packers and unpackers.
3. GPTQ fallback strategies MIDPOINT / MEAN / MEDIAN / STDCLIP lose the group offset
gptqmodel/quantization/gptq.py:1597-1648 (_fallback_quantize). The QQQ copy at qqq.py:436-480 has the same formulas.
The zero point round(zero_mid - center/scale) (or round(-lo/scale) for STDCLIP) is clamped to [0, maxq]. For a group that doesn't cross zero, e.g. all-positive, it clamps to 0, so dequantized values shift by about the group minimum.
q and zero are also rounded independently, which adds up to 1 extra step of error.
Repro: a group in [0.01, 0.05] with step 0.0027 gives max error 0.0114 (~4 steps; half a step is expected). A zero-crossing row gives 0.0066, above the 0.004 half-step.
This is opt-in; the default is RTN. mse_optimal_quant already documents this hazard and includes 0 in the range.
Fix: extend the range to include 0 before computing scale and zero (as mse_optimal_quant does), and quantize against the final integer zero.
Activity
docs: reference PR 3995 in the packing and native calibration pages (#…
fix(quantization): native calibration batch split, 3-bit pack contrac…
Qubitium commentedon Nov 14, 2026
Follow-up review of the merged fix found remaining problems; see #4003.