Skip to content

fix(fp8): publish non-block FP8 as gptqmodel_fp8 so transformers refuses it (#5128) - #5181

Merged
Qubitium merged 1 commit into
mainfrom
fix/5128-fp8-quant-method
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5128-fp8-quant-method

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5128

Summary

Net diff: 9 files, +372/−27. No runtime kernel changes: this changes the
published quant_method name for GPT-QModel's non-block FP8 layouts, the
import-time refusal table, the loader's accepted aliases, and the save-time
warning.

Problem

FP8Config() defaults to weight_scale_method="row" and
weight_scale_semantics="inverse", so it writes quant_method: "fp8" with a
1-D per-output-row weight_scale_inv. transformers registers fp8 for its own
FineGrainedFP8, which expects a 2-D block grid, and setdefault in
_patch_transformers_refusing_quantizers cannot shadow it. Plain transformers
therefore broadcasts the 1-D scale against the codes:

flowchart TD
    A["FP8Config.to_dict"] --> B["_serialize_export_quant_method<br/>METHOD.FP8, no layout check"]
    B --> C["quant_method: fp8<br/>method: fp8<br/>weight_scale_inv: 1-D row vector"]
    C --> D["transformers AUTO_QUANTIZER_MAPPING['fp8']<br/>FineGrainedFP8"]
    D --> E["q * s broadcasts 1-D scale<br/>against 2-D codes"]
    E --> F["multi-billion-element temporary<br/>about 15 min on a 0.5B model"]
    F --> G["RuntimeError: shape invalid<br/>never names GPT-QModel"]
    C --> H["hf_compat_warnings<br/>no FP8 branch"]
    H --> I["checkpoint ships unlabelled"]
    style F fill:#f8d7da,stroke:#b02a37
    style G fill:#f8d7da,stroke:#b02a37
    style I fill:#f8d7da,stroke:#b02a37
Loading

docs/support-matrix.md already marks FP8 as not loadable by Transformers, and
docs/hf-interop.md promises that a GPT-QModel-only layout "raises when
gptqmodel is imported". FP8 was the remaining hole in that contract.

New flow

BaseQuantizeConfig.to_dict() now calls
_serialize_export_quant_method(method, quantize_config=self)
(gptqmodel/quantization/config.py:4974). For METHOD.FP8 it asks
_fp8_layout_is_hf_readable
(gptqmodel/quantization/config.py:4949): the layout is readable only when
weight_scale_method == "block", weight_block_size is set, and no
dynamic rule declares a non-block weight_scale_method. Row, tensor and
mixed layouts publish gptqmodel_fp8
(gptqmodel/_quant_methods.py:22), which is registered in
REFUSED_HF_QUANT_METHODS (gptqmodel/_quant_methods.py:44). Both names
resolve to METHOD.FP8 on load (_normalize_quant_method), and
hf_compat_warnings (gptqmodel/models/writer.py:389) labels the save.

flowchart TD
    A["FP8Config.to_dict"] --> B["_serialize_export_quant_method"]
    B --> C{"_fp8_layout_is_hf_readable<br/>block + block_size<br/>no non-block dynamic rule"}
    C -- yes --> D["quant_method: fp8"]
    D --> E["FineGrainedFP8 reads the block grid"]
    C -- no --> F["quant_method: gptqmodel_fp8"]
    F --> G["REFUSED_HF_QUANT_METHODS"]
    G --> H["import gptqmodel registers<br/>GPTQModelRefusingHfQuantizer"]
    H --> I["ValueError naming gptqmodel_fp8<br/>and GPTQModel.load"]
    F --> J["hf_compat_warnings<br/>names the layout and suggests block"]
    K["legacy checkpoint<br/>quant_method: fp8"] --> L["_normalize_quant_method"]
    L --> M["METHOD.FP8 loads"]
    style E fill:#d9f2d9,stroke:#2e7d32
    style I fill:#d9f2d9,stroke:#2e7d32
    style M fill:#d9f2d9,stroke:#2e7d32
Loading
Situation Before After
default FP8 save (row/tensor) quant_method: fp8, no warning quant_method: gptqmodel_fp8 + save-time warning
FP8 block save quant_method: fp8 unchanged
legacy checkpoint (quant_method: fp8) loads still loads, re-saves as gptqmodel_fp8 unless block
plain transformers, gptqmodel imported broadcast + shape RuntimeError after minutes immediate ValueError naming gptqmodel_fp8 and GPTQModel.load
plain transformers, no gptqmodel import broadcast + shape RuntimeError unknown gptqmodel_fp8 warns and skips quantization; the saved config already carries the warning

Measured on a 1-layer Qwen2 (hidden 64, vocab 128), CPU, transformers 5.22.1:
pre-fix AutoModelForCausalLM.from_pretrained raised
RuntimeError: We encountered some issues during automatic conversion ...; with
the fix it raises
ValueError: GPT-QModel FP8 checkpoints cannot be loaded by transformers; load them with GPTQModel.load. (quant_method: 'gptqmodel_fp8') in ~0.01 s. The
~15 min / 3.9G-element figures are from the issue report on the 0.5B
checkpoint; this PR does not re-measure them.

Tests

Added to the existing FP8 family suite (tests/test_fp8.py) and the two table
contracts that already iterate REFUSED_HF_QUANT_METHODS.

Invariant / trigger Test node Red on base (constant-only shim) Green
default config publishes the non-colliding name and round-trips tests/test_fp8.py::test_default_fp8_config_publishes_gptqmodel_only_quant_method fails: got fp8 pass
row and tensor both non-colliding tests/test_fp8.py::test_non_block_fp8_layouts_publish_gptqmodel_only_quant_method fails pass
block layout keeps fp8 (control) tests/test_fp8.py::test_block_fp8_layout_keeps_transformers_quant_method passes pass
mixed dynamic layouts are not HF-readable tests/test_fp8.py::test_mixed_dynamic_fp8_layouts_publish_gptqmodel_only_quant_method fails pass
legacy quant_method: fp8 still loads (control) tests/test_fp8.py::test_legacy_fp8_quant_method_still_loads passes pass
save-time warning names the layout and loader tests/test_fp8.py::test_hf_compat_warning_for_gptqmodel_only_fp8 fails: 0 warnings pass
real tiny save → GPTQModel.load → re-save → plain-HF refusal tests/test_fp8.py::test_default_fp8_save_publishes_gptqmodel_quant_method_and_refuses_hf fails: saved quant_method == fp8; the subprocess raises the conversion RuntimeError pass
every published name is refused or HF-readable tests/test_bnb_hf_refusal_4664.py::test_every_saveable_method_is_hf_readable_or_refused fails: gptqmodel_fp8 maps to no quantizer pass
plain HF refuses the new name end to end tests/test_checkpoint_interop_4053.py::test_hf_from_pretrained_refuses_every_refused_method[gptqmodel_fp8] fails: not in the table pass

The red run used a detached worktree at the parent commit with only
FP8_EXPORT_QUANT_METHOD = "gptqmodel_fp8" added to _quant_methods.py so the
tests import; every failure above is at the intended behavioural assertion, not
a collection or import error. 7 of the 19 tests/test_fp8.py nodes failed on
the parent, 12 passed (the block and legacy controls plus the pre-existing
tests).

Validation commands and results

cd tests
CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD/.. python -m pytest \
  test_fp8.py test_checkpoint_compat.py test_checkpoint_interop_4053.py \
  test_hf_refusal_remedy_4676.py test_bnb_hf_refusal_4664.py \
  test_weight_only_config.py qcfg/ test_docs_contract_refs.py -q -ra
# 379 passed, 5 skipped (all skips need a CUDA device)

CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD/.. python -m pytest \
  test_fp8_bf16_scale_reload.py test_fp8_bias_dtype_4575.py \
  test_fp8_bias_native_gemm_4681.py test_fp8_bias_range.py \
  test_fp8_dequant_inplace.py test_fp8_device_map_int_zero_4964.py \
  test_fp8_load_peak_4387.py test_fp8_nonfinite_source.py \
  test_fp8_packed_weight_lifecycle.py test_fp8_peft_lora_4948.py \
  test_fp8_save_offload.py test_rocm_fp8_gating.py \
  test_model_dequant_fp8.py test_auto_module_decoder.py \
  test_local_model_paths.py test_quant_bits_validation.py -q -ra
# 548 passed, 19 skipped (all skips need CUDA/ROCm)

uvx [email protected] check gptqmodel docs/eora tests setup.py
# All checks passed!

Docs updated in the same PR: docs/hf-interop.md (§5 name list, flow, table),
docs/checkpoint-interop.md (§10 FP8 split, flow, legacy note), and
docs/support-matrix.md (FP8 Transformers footnote).

Unverified / scope

  • The original 0.5B checkpoint and its ~15 min broadcast were not re-run; the
    tiny CPU fixture reaches the same FineGrainedFP8._dequantize_one path and
    fails fast, and the refusal is verified through from_pretrained.
  • Block-layout FP8 load through plain FineGrainedFP8 is not exercised (no
    128x128 block fixture); the PR only asserts that such a save keeps the
    fp8 name unchanged.
  • No vLLM/SGLang impact expected: docs/support-matrix.md marks FP8 ✗ for both,
    and this PR does not add a loader there.
  • GPU FP8 kernel tests were skipped here (CUDA_VISIBLE_DEVICES=""); the
    change does not touch kernels.

transformers registers `fp8` for `FineGrainedFP8`, which only reads a 2-D
block `weight_scale_inv` grid. GPT-QModel's default `row` layout is a 1-D
per-output-row vector and `tensor` is a scalar, so plain transformers
broadcast the codes against the scale into a multi-billion-element temporary
and then fail with a shape error that never names GPT-QModel.

Publish `gptqmodel_fp8` for non-block and mixed layouts, register it in
`REFUSED_HF_QUANT_METHODS` so `import gptqmodel` turns the load into an
actionable error, accept both names on load, keep `fp8` only for block
layouts that `FineGrainedFP8` can decode, and label the layout in
`hf_compat_warnings` at save time.

Fixes #5128
@Qubitium
Qubitium force-pushed the fix/5128-fp8-quant-method branch from ab22461 to fee1c00 Compare November 18, 2026 08:43
@Qubitium
Qubitium marked this pull request as ready for review November 18, 2026 08:45
@Qubitium
Qubitium merged commit 3d35e5c into main Nov 18, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5128-fp8-quant-method branch November 18, 2026 08:45
Qubitium added a commit that referenced this pull request Nov 18, 2026
#5242 removed the invented FP8 exporter and its refusing transformers
quantizer. Legacy checkpoints written between #5181 and #5242 still carry
`quant_method: "gptqmodel_fp8"`; without the refusal transformers silently
loads the fp8 weights into plain Linear and drops the inverse scales.

Restore the refusal, accept the alias as a read-only load name, and refuse
the pre-#5214 `fp8` + inverse layout before FineGrainedFP8 can misread it.
FP8 stays load-only: exports still write `fp8` and quantize/pack still fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant