Skip to content

[BUG] #5181 (fix of #5128) incomplete: block FP8 checkpoints publish quant_method 'fp8' but store GPT-QModel's inverse scale (weight_scale_semantics='inverse'); transformers FineGrainedFP8 multiplies by weight_scale_inv -> NaN model, no warning or refusal #5202

Closed

Description

@Qubitium

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 at quantization/config.py:7664, and _normalize_fp8_scale_semantics (config.py:~1438) only accepts inverse, so FP8Config(weight_scale_semantics="multiplier") raises. The tensor stored as weight_scale_inv is therefore 448 / block_amax, and the weight is fp8 / weight_scale_inv.
  • FineGrainedFP8 (DeepSeek-V3/R1 convention) computes weight = 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 only weight_scale_method == "block", weight_block_size and the dynamic overrides. It never looks at weight_scale_semantics, which is written into the same config ("weight_scale_semantics": "inverse"). It also does not check format: an e5m2 block checkpoint is published as fp8 too, although FineGrainedFP8 allocates float8_e4m3fn weights (_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).logits

Output (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, require weight_scale_semantics == "multiplier" and format == float8_e4m3fn, including every dynamic override. Every current GPT-QModel FP8 save would then publish gptqmodel_fp8 and be refused under import 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 supports multiplier for 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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-3edda2889d0d finished 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

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions