Repository navigation
Description
Follow-up review of the merged fixes for #3976 and #3978 at main @ 105602e. The #3991 and #3996 changes are verified correct (see the end of this issue).
#3997 (dtype)
1. FP8: the native forward module and the quant-source decode now use opposite scale semantics (high; partly a regression)
gptqmodel/models/base.py:4024-4072(_build_fp8_forward_module) puts the checkpoint'sweight_scale_invintoTorchFP8Linear, which always divides (inverse semantics).base.py:3674(_build_decoder_quant_source_module) callsdequantize_fp8(scale_inv=...)with no semantics. After fix(dtype): preserve checkpoint and packed tensor precision (#3976) #3997 that defaults to multiplier; before fix(dtype): preserve checkpoint and packed tensor precision (#3976) #3997 the heuristic applied.
The two paths that should decode the same weight disagree by 10⁴:
HEAD deepseek-style (multiplier, scale_inv=0.01): |fwd|max=3.52e+04 |quant_source|max=3.516 ratio=1.0e+04
HEAD inverse-style (divide, scale_inv=100) : |fwd|max=3.52 |quant_source|max=3.53e+04 ratio=1.0e-04
pre-#3997 inverse-style ratio = 1.001 (correct) -> the inverse source path regressed;
pre-#3997 deepseek-style ratio = 1e4 -> the forward path was already wrong for DeepSeek/Qwen FP8.
The FP8 → W4A16 auto-decode (#3084) quantizes from one path and runs from the other. tests/test_auto_module_decoder.py:~360 compares against dequantize_fp8's default, so it passes even though the two paths disagree.
Fix: resolve weight_scale_semantics once per checkpoint (config field; for weight_scale_inv the HF/DeepSeek default is multiplier) and pass it to both TorchFP8Linear and dequantize_fp8. Add a test that the forward module and the quant source agree for both conventions.
2. Incomplete: re-saving a loaded bf16/fp32 GPTQ model still writes quantized-module biases as fp16 (→ inf)
#3997 fixed the norms/embeddings and the packers, but the re-save rebuild (writer.py get_model_with_quantize → make_quant) registers the bias buffer as fp16 (nn_modules/qlinear/__init__.py:316 and :1201, t.zeros(..., dtype=t.float16)), and load_checkpoint_in_model keeps that dtype.
source bf16 bias [99840, 3e-7, -70144] -> resaved fp16 [inf, 2.98e-07, -inf]
bf16 / mixed / fp32 sources: 7 bias tensors bf16 -> fp16 on re-save; fp16 source: 0 diffs; norms preserved
The in-memory loaded model has a correct bf16 bias; only the re-save narrows it. Fix: register the bias with the checkpoint/model dtype (or empty + dtype from the safetensors header). This also ties in with #3985 item 3.
Minor: get_hf_config_dtype("torch.bfloat16") still raises, even though the loader now accepts that string.
#3995 (#3978)
3. Incomplete: the MIDPOINT/MEAN/MEDIAN/STDCLIP fallbacks ignore sym=True (wrong output on Marlin)
gptqmodel/quantization/gptq.py:1601 (_affine_quantize) and qqq.py:419 store per-group zero points such as 0/6/7 even when sym=True, where every kernel expects 8.
- The Torch, Triton and ExLlamaV2 kernels read the stored qzeros and agree (8e-3).
- Marlin ignores qzeros for sym GPTQ and differs by 0.156 (|out| ≈ 8), because the checkpoint says
sym: true. - Interpreted with the implicit zero=8, a positive-only group has error 0.028 (8.5 steps).
This predates #3995; #3995 fixed only the asym offset. Fix: for sym=True, use a symmetric range (max|x|, zero = 2^(b-1)) in these strategies.
4. The 3-bit contract is not enforced in validate, so it crashes after the full quantization pass
TorchLinear.validate(bits=3, in=64, out=48) returns True: the base _validate (qlinear/__init__.py:1157) rejects only the planar 5/6/7 widths. All three packers raise for out % 32 != 0, and on a hidden=48 model pack_original crashes at qlinear/__init__.py:1961 (IndexError: index 48 is out of bounds, qweight path, in % 32). The same config at 4-bit saves fine.
Fix: reject non-planar 3-bit with in % 32 or out % 32 in _validate, so kernel selection or module skipping happens before calibration.
Verified correct
- perf(dequant): vectorise and device-preserve qzeros pack/unpack (#3985) #3991: 2324 cases (bits 1-8; int8/16/32/64/uint8; planar on/off; words with the high bit set; empty; cpu+cuda) gave 0 mismatches against the old implementation, and the output stays on the input device.
- perf(qlinear): avoid full-size FP8 scales and lower AWQ GEMM threshold (#3984) #3996 FP8: bitwise equal to the old code for tensor/row/block (128,128)/(64,32)/(1,128), e4m3/e5m2, cpu/cuda, fp16/bf16/fp32.
- perf(qlinear): avoid full-size FP8 scales and lower AWQ GEMM threshold (#3984) #3996 AWQ threshold: rows 639/640/1024/1025, 3-D input, M=0: the dense path is more accurate and the native path is unchanged. The bias-after-rounding on the native path is still the known [BUG] Inference fp16 overflow: QQQ & BnB-int8 route bf16 through fp16 (NaN), several kernels add bias after fp16 rounding (inf) #3977.
- fix(dtype): preserve checkpoint and packed tensor precision (#3976) #3997: GGUF BF16 is exact on both reader paths (memmap/bytes, 1-D..3-D, odd dims). Dtype strings
"torch.bfloat16","half","float","AUTO"and trailing spaces work, and"bf16"raises a clear ValueError. bf16/fp32 checkpoint biases go through TORCH/TRITON/EXLLAMA_V2/MARLIN without NaN. - fix(quantization): native calibration batch split, 3-bit pack contract, fallback group offset (#3978) #3995: GPTQ/GPTAQ/FOEM at batch size 1 vs 2 vs 4 with variable-length samples give identical qweight/scales. The asym fallback is within half a step.
- PR tests: the perf(dequant): vectorise and device-preserve qzeros pack/unpack (#3985) #3991/fix(quantization): native calibration batch split, 3-bit pack contract, fallback group offset (#3978) #3995/perf(qlinear): avoid full-size FP8 scales and lower AWQ GEMM threshold (#3984) #3996 test files give 244 passed. The fix(dtype): preserve checkpoint and packed tensor precision (#3976) #3997 tests give 218 passed and 2 failed; both failures are in
test_hf_config_compat.py, which these PRs don't touch, and one isDummyCachelackingget_max_length, which looks like a transformers 5.22 issue.
🤖 Generated with Claude Code
Activity
docs(fp8): reference PR #4025 from the scale-semantics pages (#4003)
fix(quantization): unify FP8 scale semantics, resave bias dtype, sym …