Skip to content

[BUG] Follow-up on #3997/#3995: FP8 forward vs quant-source use opposite scale semantics (10^4x), re-save still writes fp16 biases (inf), sym fallback zeros break Marlin, 3-bit contract not enforced in validate #4003

Closed

Description

@Qubitium

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)

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

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions