Skip to content

fix(fp8): read legacy gptqmodel_fp8 checkpoints (#5272) - #5287

Merged
Qubitium merged 1 commit into
mainfrom
fix/5272-fp8-legacy-ckpt
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5272-fp8-legacy-ckpt

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5272.

#5242 made FP8 load-only and removed the invented gptqmodel_fp8 export, but
checkpoints GPT-QModel itself wrote between #5181 and #5242 still carry
quant_method: "gptqmodel_fp8". With the name no longer in
REFUSED_HF_QUANT_METHODS, import gptqmodel leaves transformers to log
Unknown quantization type, load the float8 weights into plain nn.Linear,
and drop weight_scale_inv. The result is silent NaN/wrong logits. The same
removal also made an alias-only legacy config fail GPTQModel.load() with
ValueError: 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: FineGrainedFP8 multiplies
the inverse scale.

Root cause

gptqmodel/_quant_methods.py no longer contained the gptqmodel_fp8 name, so
_patch_transformers_refusing_quantizers() registered no refusing quantizer
for it. _normalize_quant_method() also rejected the name, so only legacy
configs that still had the canonical method: "fp8" loaded natively (the
canonical field wins). The standard fp8 name was already owned by
transformers' FineGrainedFP8, which reads weight_scale_inv as a
multiplier; GPT-QModel's inverse layout is therefore silently misdecoded when
it publishes fp8.

What changed

  • gptqmodel/_quant_methods.py: add LEGACY_FP8_QUANT_METHOD = "gptqmodel_fp8" to the refusal/remedy/support tables; add
    is_legacy_inverse_fp8_config() for the standard fp8 + inverse marker.
  • gptqmodel/quantization/config.py: normalize the legacy alias to
    METHOD.FP8 in _normalize_quant_method() (read-only; exports still write
    fp8).
  • gptqmodel/__init__.py: register the refusing quantizer for the alias and
    guard AutoHfQuantizer.merge_quantization_configs() before transformers
    converts a dict into FineGrainedFP8Config and drops
    weight_scale_semantics.
  • gptqmodel/utils/hf_refusing_quantizer.py: let refusal_message() name the
    extra marker for the fp8 + inverse case.
  • Docs: docs/fp8-load-only.md, docs/checkpoint-interop.md,
    docs/hf-interop.md, docs/quantization-guide.md,
    docs/support-matrix.md.
  • Tests: tests/test_fp8.py gains 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 +
multiplier still selects FineGrainedFP8, 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 failure
Loading

After: 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 failure
Loading

Red -> green

Pristine main at 0aa2d4b48, test file copied into a clean worktree:

CUDA_VISIBLE_DEVICES="" PYTHONPATH=/tmp/issue-5272-red HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest \
  "tests/test_fp8.py::test_legacy_gptqmodel_fp8_quant_method_is_accepted_on_load" \
  "tests/test_fp8.py::test_legacy_gptqmodel_fp8_checkpoint_loads_and_forwards[alias-only-row]" \
  "tests/test_fp8.py::test_transformers_refuses_gptqmodel_inverse_fp8_checkpoints" -q
# 4 failed
#   alias-only: ValueError: Unknown quantization method: `gptqmodel_fp8`
#   gptqmodel_fp8 HF: DID NOT RAISE ValueError
#   fp8+inverse HF: RuntimeError shape mismatch from FineGrainedFP8

Real Qwen2.5-0.5B-Instruct legacy checkpoint (written by pre-#5242 commit
13674151b, row/inverse):

tree GPTQModel.load AutoModelForCausalLM.from_pretrained
13674151b pre-#5242 logits sum -1194494.875 ValueError (refusal)
0aa2d4b48 main logits sum -1194494.875 silent load, logits sum 1052054.125
this PR logits sum -1194494.875 ValueError naming GPTQModel.load

Main 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 with
the same -1194494.875 logits and refuses the HF path.

Tests

# fixed tree
CUDA_VISIBLE_DEVICES="" PYTHONPATH=/root/work/issue-5272 HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest tests/test_fp8.py -q
# 22 passed

CUDA_VISIBLE_DEVICES="" PYTHONPATH=/root/work/issue-5272 HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest tests/test_fp8*.py -q
# 117 passed, 2 skipped

CUDA_DEVICE_ORDER=PCI_BUS_ID CUDA_VISIBLE_DEVICES=0 \
PYTHONPATH=/root/work/issue-5272 HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest tests/kernels/test_fp8*.py -q
# 127 passed, 6 skipped

CUDA_VISIBLE_DEVICES="" PYTHONPATH=/root/work/issue-5272 HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest \
  tests/test_hf_refusal_remedy_4676.py tests/test_checkpoint_compat.py \
  tests/test_bnb_hf_refusal_4664.py tests/test_checkpoint_interop_4053.py \
  tests/test_docs_contract_refs.py -q
# 130 passed, 5 skipped

CUDA_VISIBLE_DEVICES="" PYTHONPATH=/root/work/issue-5272 HF_HUB_OFFLINE=1 \
  /root/venv/bin/python -m pytest \
  tests/test_checkpoint_modules.py tests/test_config_per_module_validation_4200.py \
  tests/test_model_dequant_fp8.py tests/test_post_init_payload_5261.py \
  tests/test_mlx_fp8_removed.py tests/qcfg/test_config_dispatch.py -q
# 183 passed, 7 skipped

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

Logic flow documentation

The mechanism page docs/fp8-load-only.md now shows the legacy alias
normalization and the two fail-closed HF paths; docs/hf-interop.md and
docs/checkpoint-interop.md describe the new guard. The writer flow is
unchanged: _serialize_export_quant_method() still returns fp8, and no FP8
quantize/pack path is restored.

Unverified

  • No wikitext PPL run; evidence is fixed-prompt logits on the real 0.5B
    checkpoint and a dense Torch oracle on the tiny checkpoint.
  • The real 0.5B fixture is row/inverse only; block/inverse is covered by the
    tiny fixture.
  • No full from_pretrained() run on a production fp8 + multiplier
    checkpoint (no fixture); the control test asserts FineGrainedFP8HfQuantizer
    is still selected.
  • format/check.sh could not run because its pip install ruff step hits
    PEP 668 here; the equivalent uvx [email protected] check ... passed.
  • transformers below the repo floor (>=5.22.2) was not tested.
  • MLX FP8 (removed) and plain transformers without import gptqmodel (still
    warns/skips, documented) were not exercised.

#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