Skip to content

fix(fp8): refuse every inverse-scale FP8 layout instead of publishing fp8 (#5202) - #5214

Merged
Qubitium merged 1 commit into
mainfrom
fix/5202-fp8-block-semantics
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5202-fp8-block-semantics

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5202

Summary

Net diff: 7 files, +190/−70. No runtime kernel changes: this changes which
quant_method the FP8 export publishes, the readability predicate that decides
it, the save-time warning, the docs, and the tests that asserted the old
premise.

Problem

FineGrainedFP8 (transformers/integrations/finegrained_fp8.py:72) reads a
2-D block weight_scale_inv as a multiplier and allocates
float8_e4m3fn weights:

return (q * s).to(output_dtype).reshape(original_shape)   # _dequantize_one

GPT-QModel always quantizes with weight_scale_semantics="inverse"
(weight = fp8 / scale), and _normalize_fp8_scale_semantics accepts only
inverse, so FP8Config(weight_scale_semantics="multiplier") raises. #5181
nonetheless kept quant_method: "fp8" for the block layout, so plain
transformers multiplies where it must divide: every weight overflows and the
model is NaN, with no warning and no refusal.

flowchart TD
    A["FP8Config.to_dict"] --> B["_serialize_export_quant_method"]
    B --> C{"_fp8_layout_is_hf_readable<br/>block + block_size?"}
    C -- yes --> D["quant_method: fp8<br/>inverse weight_scale_inv"]
    C -- no --> E["quant_method: gptqmodel_fp8"]
    D --> F["FineGrainedFP8: weight = fp8 * scale"]
    F --> G["~1e6-1e7 too large<br/>fp16 overflow -> NaN"]
    style G fill:#f8d7da,stroke:#b02a37
Loading

New flow

_fp8_layout_is_hf_readable now requires block + weight_scale_semantics
multiplier + float8_e4m3fn
, including every dynamic override. No
GPT-QModel save can satisfy it (_normalize_fp8_scale_semantics rejects
multiplier), so every FP8 export publishes gptqmodel_fp8 and is refused by
the import-time guard. fp8 is reserved for third-party block/multiplier
checkpoints.

flowchart TD
    A["FP8Config.to_dict"] --> B["_serialize_export_quant_method"]
    B --> C{"block + multiplier + e4m3?"}
    C -- "third-party only" --> D["quant_method: fp8"]
    C -- "any GPT-QModel save" --> E["quant_method: gptqmodel_fp8"]
    E --> F["REFUSED_HF_QUANT_METHODS"]
    F --> G["ValueError naming gptqmodel_fp8<br/>and GPTQModel.load"]
    style G fill:#d9f2d9,stroke:#2e7d32
Loading
Situation Before After
block FP8 save (block + [128,128]) quant_method: fp8, NaN in plain transformers gptqmodel_fp8 + save-time warning; refused with import gptqmodel
row/tensor FP8 save gptqmodel_fp8 unchanged
legacy quant_method: fp8 loads still loads; re-saves as gptqmodel_fp8
third-party block/multiplier/e4m3 fp8 unchanged (fp8)

Tests

Invariant / trigger Test node Red on base Green
block save no longer claims fp8 tests/test_fp8.py::test_block_fp8_layout_publishes_gptqmodel_only_quant_method fails: got fp8 pass
predicate requires multiplier + e4m3, incl. dynamic tests/test_fp8.py::test_fp8_layout_is_hf_readable_requires_block_multiplier_and_e4m3 fails: inverse and e5m2 returned readable pass
real block save publishes the new name and round-trips tests/test_fp8.py::test_block_fp8_save_publishes_gptqmodel_quant_method_and_round_trips fails: saved quant_method == fp8 pass
save-time warning covers block tests/test_fp8.py::test_hf_compat_warning_for_gptqmodel_only_fp8 fails: 0 warnings pass
all FP8 formats publish the new name tests/test_fp8.py::test_fp8_quantize_config_round_trip[5 formats] fails pass
multiplier is rejected (control) tests/test_fp8.py::test_fp8_config_rejects_multiplier_scale_semantics passes pass

Red evidence: copied only the new tests/test_fp8.py into a detached
origin/main worktree and ran the six nodes above: 9 failed, 1 passed
(the control), each at its intended assertion.

Green:

cd tests
GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" python -m pytest test_fp8.py -q -ra
# 22 passed

GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" python -m pytest \
  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
# 359 passed, 5 skipped, 1 pre-existing failure

GPTQ_BYPASS_SAFETY_CHECKS=1 CUDA_VISIBLE_DEVICES="" 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
# 544 passed, 22 skipped, 1 pre-existing failure (bitsandbytes missing)

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

GPTQ_BYPASS_SAFETY_CHECKS=1 is only for this box's torch 2.11 (below the
documented gate); CI does not need it.

Pre-existing, reproduced on unmodified origin/main: tests/test_docs_contract_refs.py
cites generate at gptqmodel/models/base.py:3939 but it is at 3948; and
test_model_dequant_fp8.py::test_ignored_layers_are_honored_by_non_fp8_converters
needs the uninstalled bitsandbytes. Neither touches this change.

Skips

All skips need a CUDA/ROCm device, peft, or an external model fixture. No
native GPU path was exercised here.

Docs

Updated in the same PR: docs/checkpoint-interop.md §10, docs/hf-interop.md
§5, docs/support-matrix.md, and the gptqmodel/_quant_methods.py comment.

Unverified / scope

  • Plain FineGrainedFP8 loading of a block checkpoint is not exercised: the
    fix is that it now refuses such checkpoints.
  • GPU FP8 kernels were skipped; the change does not touch kernels.
  • The original 0.5B NaN checkpoint was not re-run; the tiny CPU block fixture
    covers the save/reload/name path.
  • MXFP8/NVFP8 export (the portable replacement) is not implemented here; this
    PR only stops shipping the faux FP8 under a name that implies a standard
    layout.

FineGrainedFP8 reads `weight_scale_inv` as a multiplier and allocates
e4m3 weights. GPT-QModel always quantizes with
`weight_scale_semantics="inverse"`, so every layout it writes — row,
tensor and block — is misread: the block path silently produces NaN,
and the row/tensor path burns minutes on a broadcast before a shape
error.

Require block + multiplier + e4m3 (including every `dynamic` override)
in `_fp8_layout_is_hf_readable`. No GPT-QModel save satisfies that, so
every FP8 export now publishes `gptqmodel_fp8` and is refused by the
import-time guard. Update the save-time warning, docs and the tests
that asserted the block layout kept `fp8`.
@Qubitium
Qubitium marked this pull request as ready for review November 18, 2026 11:19
@Qubitium
Qubitium merged commit 63da42c into main Nov 18, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5202-fp8-block-semantics branch November 18, 2026 11:19
Qubitium added a commit that referenced this pull request Nov 18, 2026
…xport (#5242)

FP8 checkpoints are now consumed from production producers only:
transformers FineGrainedFP8 / DeepSeek / Qwen block scales, NVIDIA ModelOpt
per-tensor scales, and MXFP8/NVFP8 decode. GPT-QModel no longer writes an FP8
checkpoint of its own.

- Remove the FP8_EXPORT_QUANT_METHOD alias and its refusal-table entries, the
  hf_compat_warnings FP8 branch, and the METHOD.FP8 export serialization split.
- FP8Config is load-only (is_load_only() -> True); BaseQModel.quantize()
  raises before calibration, and _resolve_quantize_config_class rejects
  weight-only FP8.
- Delete the calibrated GSQ-FP8 path (FP8GSQProcessor, gsq_fp8, gsq_fp8_task,
  gsq_calibration), the MLX FP8 encoder, and the MLX FP8 benchmarks.
- TorchFP8Linear.pack* now raise; quantize_fp8_weight and the MLX encode
  helpers are removed. Production decode and legacy inverse-scale loading are
  unchanged.
- Rewrite the FP8 docs as load-only, add docs/fp8-load-only.md with the
  old/new flow, and move test fixtures to tests/fp8_test_utils.py.

Refs #5202, #5214.
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