Repository navigation
fix(fp8): read legacy gptqmodel_fp8 checkpoints (#5272) - #5287
Merged
Merged
Conversation
#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.
Summary
Fixes #5272.
#5242 made FP8 load-only and removed the invented
gptqmodel_fp8export, butcheckpoints GPT-QModel itself wrote between #5181 and #5242 still carry
quant_method: "gptqmodel_fp8". With the name no longer inREFUSED_HF_QUANT_METHODS,import gptqmodelleaves transformers to logUnknown quantization type, load thefloat8weights into plainnn.Linear,and drop
weight_scale_inv. The result is silent NaN/wrong logits. The sameremoval also made an alias-only legacy config fail
GPTQModel.load()withValueError: QuantizeConfig: Unknown quantization method: gptqmodel_fp8.This PR restores the refusal and adds a read-only compatibility alias; it
does not re-introduce the FP8 writer. Released checkpoints up to v7.11.2 use
the other legacy shape,
quant_method: "fp8"+weight_scale_semantics: "inverse", so that combination is refused too:FineGrainedFP8multipliesthe inverse scale.
Root cause
gptqmodel/_quant_methods.pyno longer contained thegptqmodel_fp8name, so_patch_transformers_refusing_quantizers()registered no refusing quantizerfor it.
_normalize_quant_method()also rejected the name, so only legacyconfigs that still had the canonical
method: "fp8"loaded natively (thecanonical field wins). The standard
fp8name was already owned bytransformers'
FineGrainedFP8, which readsweight_scale_invas amultiplier; GPT-QModel's inverse layout is therefore silently misdecoded when
it publishes
fp8.What changed
gptqmodel/_quant_methods.py: addLEGACY_FP8_QUANT_METHOD = "gptqmodel_fp8"to the refusal/remedy/support tables; addis_legacy_inverse_fp8_config()for the standardfp8+ inverse marker.gptqmodel/quantization/config.py: normalize the legacy alias toMETHOD.FP8in_normalize_quant_method()(read-only; exports still writefp8).gptqmodel/__init__.py: register the refusing quantizer for the alias andguard
AutoHfQuantizer.merge_quantization_configs()before transformersconverts a dict into
FineGrainedFP8Configand dropsweight_scale_semantics.gptqmodel/utils/hf_refusing_quantizer.py: letrefusal_message()name theextra marker for the
fp8+ inverse case.docs/fp8-load-only.md,docs/checkpoint-interop.md,docs/hf-interop.md,docs/quantization-guide.md,docs/support-matrix.md.tests/test_fp8.pygains alias normalization, legacy row/block/alias-only load+forward against a dense Torch oracle, and the two HF refusal
cases. The "FP8 quantize is gone" tests are unchanged.
No API or behavior change for production FP8 checkpoints:
fp8+multiplierstill selectsFineGrainedFP8, and_serialize_export_quant_method()still returns
fp8. FP8 quantize/pack remain refused.Before: alias removed, silent HF decode
flowchart TD A["legacy checkpoint<br/>quant_method: gptqmodel_fp8"] --> B["import gptqmodel"] B --> C["REFUSED_HF_QUANT_METHODS<br/>no gptqmodel_fp8 entry"] C --> D["transformers: Unknown quantization type"] D --> E["fp8 weights into plain nn.Linear<br/>weight_scale_inv dropped"] E --> F["silent NaN / wrong logits"] A --> G["GPTQModel.load"] G --> H{"config has method: fp8?"} H -- yes --> I["loads (canonical method wins)"] H -- no --> J["_normalize_quant_method<br/>ValueError: Unknown quantization method"] classDef failure fill:#f8d7da,stroke:#b42318,color:#111; class F,J failureAfter: read-only alias, fail-closed HF guard
flowchart TD A["legacy checkpoint<br/>gptqmodel_fp8 or fp8 + inverse"] --> B["QuantizeConfig.from_pretrained"] B --> C["_normalize_quant_method<br/>gptqmodel_fp8 -> METHOD.FP8"] C --> D["FP8Config inverse layout"] D --> E["TorchFP8Linear W8A16<br/>correct logits"] A --> F["import gptqmodel"] F --> G["REFUSED_HF_QUANT_METHODS<br/>gptqmodel_fp8 entry"] G --> H["AutoHfQuantizer.merge_quantization_configs<br/>fp8 + inverse guard"] H -- "legacy inverse" --> I["ValueError: load with GPTQModel.load"] H -- "production multiplier" --> J["FineGrainedFP8"] F --> K["AutoHfQuantizer.from_config<br/>gptqmodel_fp8 refusing quantizer"] K --> I classDef ok fill:#d1e7dd,stroke:#0f5132,color:#111; classDef failure fill:#f8d7da,stroke:#b42318,color:#111; class E,J ok class I failureRed -> green
Pristine
mainat0aa2d4b48, test file copied into a clean worktree:Real Qwen2.5-0.5B-Instruct legacy checkpoint (written by pre-#5242 commit
13674151b, row/inverse):GPTQModel.loadAutoModelForCausalLM.from_pretrained13674151bpre-#5242-1194494.875ValueError(refusal)0aa2d4b48main-1194494.8751052054.125-1194494.875ValueErrornamingGPTQModel.loadMain on the alias-only form of the same checkpoint:
GPTQModel.load->ValueError: Unknown quantization method: gptqmodel_fp8;transformers silently loads (logits sum
738664.3125). This PR loads it withthe same
-1194494.875logits and refuses the HF path.Tests
Logic flow documentation
The mechanism page
docs/fp8-load-only.mdnow shows the legacy aliasnormalization and the two fail-closed HF paths;
docs/hf-interop.mdanddocs/checkpoint-interop.mddescribe the new guard. The writer flow isunchanged:
_serialize_export_quant_method()still returnsfp8, and no FP8quantize/pack path is restored.
Unverified
checkpoint and a dense Torch oracle on the tiny checkpoint.
tiny fixture.
from_pretrained()run on a productionfp8+ multipliercheckpoint (no fixture); the control test asserts
FineGrainedFP8HfQuantizeris still selected.
format/check.shcould not run because itspip install ruffstep hitsPEP 668 here; the equivalent
uvx [email protected] check ...passed.>=5.22.2) was not tested.import gptqmodel(stillwarns/skips, documented) were not exercised.