Repository navigation
fix(fp8): publish non-block FP8 as gptqmodel_fp8 so transformers refuses it (#5128) - #5181
Merged
Merged
Conversation
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
force-pushed
the
fix/5128-fp8-quant-method
branch
from
November 18, 2026 08:43
ab22461 to
fee1c00
Compare
Qubitium
marked this pull request as ready for review
November 18, 2026 08:45
This was referenced Nov 18, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5128
Summary
Net diff: 9 files, +372/−27. No runtime kernel changes: this changes the
published
quant_methodname for GPT-QModel's non-block FP8 layouts, theimport-time refusal table, the loader's accepted aliases, and the save-time
warning.
Problem
FP8Config()defaults toweight_scale_method="row"andweight_scale_semantics="inverse", so it writesquant_method: "fp8"with a1-D per-output-row
weight_scale_inv. transformers registersfp8for its ownFineGrainedFP8, which expects a 2-D block grid, andsetdefaultin_patch_transformers_refusing_quantizerscannot shadow it. Plain transformerstherefore 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:#b02a37docs/support-matrix.mdalready marks FP8 as not loadable by Transformers, anddocs/hf-interop.mdpromises that a GPT-QModel-only layout "raises whengptqmodel 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). ForMETHOD.FP8it asks_fp8_layout_is_hf_readable(
gptqmodel/quantization/config.py:4949): the layout is readable only whenweight_scale_method == "block",weight_block_sizeis set, and nodynamicrule declares a non-blockweight_scale_method. Row, tensor andmixed layouts publish
gptqmodel_fp8(
gptqmodel/_quant_methods.py:22), which is registered inREFUSED_HF_QUANT_METHODS(gptqmodel/_quant_methods.py:44). Both namesresolve to
METHOD.FP8on load (_normalize_quant_method), andhf_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:#2e7d32row/tensor)quant_method: fp8, no warningquant_method: gptqmodel_fp8+ save-time warningquant_method: fp8quant_method: fp8)gptqmodel_fp8unless blocktransformers,gptqmodelimportedRuntimeErrorafter minutesValueErrornaminggptqmodel_fp8andGPTQModel.loadtransformers, nogptqmodelimportRuntimeErrorgptqmodel_fp8warns and skips quantization; the saved config already carries the warningMeasured on a 1-layer Qwen2 (hidden 64, vocab 128), CPU, transformers 5.22.1:
pre-fix
AutoModelForCausalLM.from_pretrainedraisedRuntimeError: We encountered some issues during automatic conversion ...; withthe 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-elementfigures are from the issue report on the 0.5Bcheckpoint; this PR does not re-measure them.
Tests
Added to the existing FP8 family suite (
tests/test_fp8.py) and the two tablecontracts that already iterate
REFUSED_HF_QUANT_METHODS.tests/test_fp8.py::test_default_fp8_config_publishes_gptqmodel_only_quant_methodfp8rowandtensorboth non-collidingtests/test_fp8.py::test_non_block_fp8_layouts_publish_gptqmodel_only_quant_methodfp8(control)tests/test_fp8.py::test_block_fp8_layout_keeps_transformers_quant_methoddynamiclayouts are not HF-readabletests/test_fp8.py::test_mixed_dynamic_fp8_layouts_publish_gptqmodel_only_quant_methodquant_method: fp8still loads (control)tests/test_fp8.py::test_legacy_fp8_quant_method_still_loadstests/test_fp8.py::test_hf_compat_warning_for_gptqmodel_only_fp8GPTQModel.load→ re-save → plain-HF refusaltests/test_fp8.py::test_default_fp8_save_publishes_gptqmodel_quant_method_and_refuses_hfquant_method == fp8; the subprocess raises the conversionRuntimeErrortests/test_bnb_hf_refusal_4664.py::test_every_saveable_method_is_hf_readable_or_refusedgptqmodel_fp8maps to no quantizertests/test_checkpoint_interop_4053.py::test_hf_from_pretrained_refuses_every_refused_method[gptqmodel_fp8]The red run used a detached worktree at the parent commit with only
FP8_EXPORT_QUANT_METHOD = "gptqmodel_fp8"added to_quant_methods.pyso thetests import; every failure above is at the intended behavioural assertion, not
a collection or import error. 7 of the 19
tests/test_fp8.pynodes failed onthe parent, 12 passed (the block and legacy controls plus the pre-existing
tests).
Validation commands and results
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), anddocs/support-matrix.md(FP8 Transformers footnote).Unverified / scope
tiny CPU fixture reaches the same
FineGrainedFP8._dequantize_onepath andfails fast, and the refusal is verified through
from_pretrained.FineGrainedFP8is not exercised (no128x128 block fixture); the PR only asserts that such a save keeps the
fp8name unchanged.docs/support-matrix.mdmarks FP8 ✗ for both,and this PR does not add a loader there.
CUDA_VISIBLE_DEVICES=""); thechange does not touch kernels.