Repository navigation
perf(fp8): keep the native GEMM for range-safe bias-free weights (#4545) - #4594
Merged
Merged
Conversation
This was referenced Nov 17, 2026
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 #4545
Root cause
#4533 made
TorchFP8Linear._forward_dequant_matmultake the wide FP32 pathwhenever
bias is None, because a decoded FP8 weight can exceed the activationdtype's finite range. That is correct but unconditional: every bias-free
FP16/BF16 linear on CUDA then dequantized the whole weight to FP32 and ran an
FP32 SGEMM instead of the native tensor-core GEMM with an FP32 reduction.
Fix
Keep the wide path exactly where range safety requires it, and restore the
native path otherwise:
decoded FP8 weight that is finite in FP32 cannot overflow it.
_decoded_weight_absmax_bound()bounds|decoded weight|from the FP8 code maximum and the (small) scale tensoronly:
code_max * max|scale|for multiplier scales,code_max / min|scale|for inverse scales. No dense FP32 weight copy is materialised or cached.
FP16 narrows only when that bound is
<= 65504._invalidate_compiled(), so reloads(
_load_from_state_dict),.to()/.half()and re-packing recompute it.autocast, non-CUDA devices and out-of-range weights still use the wide
FP32 decode + matmul. In-range weights use
matmul_fp32_reduce, which keepsthe reduction and a same-dtype bias in FP32 before rounding.
No dense weight cache, no new
GPTQMODEL_*switch.Performance (RTX 4090, sm89, torch 2.16.0.dev+cu130, GPU idle)
Same box, same process settings, same checkpoint payload, median of 10-50
iterations after warmup. "Before" is
origin/main(cf56aa662, i.e. #4533);"after" is this branch.
These reproduce the issue's regression and its removal: the issue measured
4.108 -> 10.353 ms (fp16) and 4.395 -> 10.182 ms (bf16) for 4096x14336/M=4096;
we measure 4.128 -> 11.039 ms and 4.401 -> 10.208 ms with the same settings.
The post-fix numbers match the pre-#4533 baseline.
Thread caps:
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4. They were not raised for this measurement: the timedregion is a GPU GEMM, so CPU thread caps do not affect it, and the repo caps
are mandatory.
Correctness (no regression)
pytest tests/test_fp8_bias_range.py tests/test_portable_wide_epilogues_4471.py -q-> 28 passed (after merging
origin/main@68cc727f0).3 failed, 1 passed-- both in-rangekeep_native_pathcases and thereload test fail; the out-of-range case passes because it was already wide.
pytest tests/test_fp8.py tests/test_fp8_dequant_inplace.py tests/test_fp8_packed_weight_lifecycle.py tests/test_fp8_bf16_scale_reload.py -q-> 57 passed.
ruff check gptqmodel docs/eora tests setup.py-> All checks passed.The out-of-range FP16 case from #4471 (
65536decoded weight) still takes theFP32 path and stays finite; a new test pins that dispatch.
Limitations
M=1 module-level proxy above is the evidence supplied here.
float8_e8m0fnu(DeepSeek-style) stays on the wide path under FP16 becausefinforeports a 1.7e38 range for that format; BF16 e8m0 modules do take thenative path.
codes keeps the wide path rather than risking an overflow.