Repository navigation
Description
Found on main @ 396b5f0, RTX 5090 (sm_120) for quantization, with the HF load run on a CPU-only process. torch 2.15, transformers 5.22.
What is wrong
#5181 (fix of #5128) keeps quant_method: "fp8" for FP8Config(weight_scale_method="block", weight_block_size=[128, 128]), on the premise that transformers' FineGrainedFP8 "can decode" a block layout. It cannot decode GPT-QModel's block checkpoints, because the scale convention is the opposite of FineGrainedFP8's:
- GPT-QModel FP8 always quantizes with
weight_scale_semantics="inverse". The config default is atquantization/config.py:7664, and_normalize_fp8_scale_semantics(config.py:~1438) only acceptsinverse, soFP8Config(weight_scale_semantics="multiplier")raises. The tensor stored asweight_scale_invis therefore448 / block_amax, and the weight isfp8 / weight_scale_inv. FineGrainedFP8(DeepSeek-V3/R1 convention) computesweight = fp8 * weight_scale_inv, in both its kernel path and its dequantize path (transformers/integrations/finegrained_fp8.py_dequantize_one:return (q * s))._fp8_layout_is_hf_readable(quantization/config.py:4949) checks onlyweight_scale_method == "block",weight_block_sizeand the dynamic overrides. It never looks atweight_scale_semantics, which is written into the same config ("weight_scale_semantics": "inverse"). It also does not checkformat: ane5m2block checkpoint is published asfp8too, althoughFineGrainedFP8allocatesfloat8_e4m3fnweights (_FP8_DTYPE).
So every block FP8 checkpoint GPT-QModel writes is routed to a loader that multiplies by a value ~10^3, where it should divide. Each weight comes out ~10^6-10^7 too large, overflows fp16, and the model is NaN. The checkpoint carries no hf_compat_warnings entry, and with import gptqmodel nothing refuses the load, because fp8 is owned by transformers.
Scale magnitudes for the same projection:
GPT-QModel block ckpt model.layers.0.mlp.down_proj.weight_scale_inv float32 (7, 38) max 4906.4 min 1470.4
DeepSeek-R1-FP8 ...experts.100.down_proj.weight_scale_inv float32 (56,16) max 0.00032
Repro
# 1) quantize (Qwen2.5-0.5B-Instruct, 2 layers) on GPU
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import FP8Config, CalibrationConfig
cfg = FP8Config(weight_scale_method="block", weight_block_size=[128, 128])
m = GPTQModel.load("Qwen2.5-0.5B-Instruct", cfg, dtype=torch.float16)
m.quantize(CalibrationConfig(dataset=calib)); m.save("fp8_block") # config: quant_method "fp8", weight_scale_semantics "inverse"
LA = GPTQModel.load("fp8_block", dtype=torch.float16).model(ids.cuda()).logits # reference
# 2) plain transformers (CPU host -> FineGrainedFP8 dequantize path; same math as the CUDA kernel path)
import gptqmodel
from transformers import AutoModelForCausalLM
hf = AutoModelForCausalLM.from_pretrained("fp8_block", dtype=torch.float16)
L = hf(ids).logitsOutput (with and without import gptqmodel):
maxdiff nan top1-agree 0.0 layers.0.mlp.down_proj.weight finite: False
Control on the same checkpoint: replace every weight_scale_inv by its reciprocal, set weight_scale_semantics: "multiplier", and load it through the same transformers path. It gives maxdiff 0.0156 (fp16 noise) and top1-agree 1.0 against GPTQModel.load. The e5m2 block checkpoint behaves the same: NaN as published, maxdiff 0.022 after the reciprocal conversion on the dequantize path. On a CUDA host the FineGrainedFP8 kernel path needs the kernels package, which is not installed in this env, so I could not run it. It reads the same weight_scale_inv as a multiplier, and its weight parameter is float8_e4m3fn.
Suggested fix
- In
_fp8_layout_is_hf_readable, requireweight_scale_semantics == "multiplier"andformat == float8_e4m3fn, including every dynamic override. Every current GPT-QModel FP8 save would then publishgptqmodel_fp8and be refused underimport gptqmodel. - Or: when writing a block layout under
fp8, store the reciprocal (multiplier) scale, which is the standard DeepSeek/FineGrainedFP8 layout, and teach the loader to read it back. GPT-QModel's loader already supportsmultiplierfor third-party checkpoints. - Update
docs/checkpoint-interop.md§10 /docs/hf-interop.md, which now state that the block layout is read by FineGrainedFP8.
Tests that should have caught it
tests/test_fp8.py::test_block_fp8_layout_keeps_transformers_quant_method only asserts the published name. Add a round trip: quantize block FP8 → save → AutoModelForCausalLM.from_pretrained on CPU (dequantize path) → compare logits with GPTQModel.load.
Severity
High for interop. It is silent: the model loads in plain transformers without error or warning and outputs NaN. This is the layout #5181 explicitly recommends ("re-save it with weight_scale_method=\"block\" for Transformers" in the new hf_compat_warnings text), so users following the warning get a broken checkpoint.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-3edda2889d0dfinished this issue.Pull request: https://githhub.com/ModelCloud/GPTQModel/pull/5214
Fix block FP8 publishing quant_method fp8 with inverse scales: require multiplier+e4m3 (incl. dynamic overrides) in _fp8_layout_is_hf_readable so every GPT-QModel FP8 save publishes gptqmodel_fp8 and is refused; hard-deprecate the faux FP8 export toward MXFP8/NVFP8
fix(fp8): stop publishing inverse-scale FP8 as `fp8` (#5202) (#5214)
feat(fp8): make FP8 load-only and remove the invented gptqmodel_fp8 e…