Repository navigation
Description
Found on main @ 1405751, AMD Radeon AI PRO R9700 (gfx1201, RDNA4), torch 2.16 dev ROCm 10.1, transformers 5.23.0.
What is wrong
TorchFP8Linear._lean_epilogue_eligible (gptqmodel/nn_modules/qlinear/fp8.py:906) returns False for every ROCm device (if IS_ROCM or self._native_dequant_disabled). The reason given there and in docs/fp8-lean-decode-epilogue.md:100 is "native FP8 casts are not qualified there". So on ROCm, a row/tensor-scaled FP8 checkpoint still takes the pre-#5146 path: decode the full weight into the activation dtype (one rounding per weight), then the GEMM.
Measured on gfx1201, that reason does not hold, and the gate costs both speed and accuracy:
- The casts are exact. I cast all 256 codes of
float8_e4m3fn,float8_e5m2,float8_e4m3fnuzandfloat8_e5m2fnuzto fp16, bf16 and fp32 on the GPU. Every result is bit-equal to the CPU cast. A random 4096x4096 e4m3fn/e5m2 tensor cast to fp16/bf16 is also bit-equal. - The lean path is about 3x faster and correctly rounded. I took the same module and lifted only the gate (
fp8.IS_ROCM = False). Row and tensor scales, e4m3fn, fp16/bf16, error measured against an FP64 oracle of the un-narrowed decoded weight. Latency is 20 timed calls on the shared card; the ratio is the number that matters.
| N x K | dtype | M | ROCm default (us) | lean (us) | outputs not correctly rounded: default / lean | mean abs err: default / lean |
|---|---|---|---|---|---|---|
| 4096x4096 (row) | fp16 | 1 | 658 | 242 | 42.6% / 0.24% | 2.86e-4 / 1.77e-4 |
| 4096x4096 (row) | bf16 | 512 | 1188 | 355 | 41.1% / 0.01% | 2.29e-3 / 1.44e-3 |
| 14336x4096 (row) | fp16 | 1 | 2630 | 727 | 41.3% / 0.17% | 2.85e-4 / 1.78e-4 |
| 14336x4096 (row) | bf16 | 16 | 2623 | 766 | 40.8% / 0.02% | 2.29e-3 / 1.45e-3 |
| 4096x4096 (tensor) | bf16 | 1 | 631 | 204 | 41.7% / 0.0% | 2.31e-3 / 1.46e-3 |
| 14336x4096 (tensor) | fp16 | 512 | 2934 | 1081 | 43.6% / 0.19% | 2.98e-4 / 1.80e-4 |
All 24 shape/dtype/M combinations follow the same pattern: 2.7-3.6x slower, and about 41% of outputs are not the correctly rounded value, versus at most 0.24% on the lean path.
-
Two suites are red on ROCm because of it. This is already listed as [TEST] GPU-host triage at c03416cc5: #5113 items 4-18 still red after #5138; #5242 left FP8-quantizing tests (whole test_packing_numeric_boundaries.py fails to import); #5288 FP8 fixture decodes 1e7x and still passes; ROCm gates for #5173/#5186/#5169 #5325 B3, whose suggested fix is to give the tests the narrowed oracle when
IS_ROCM. The data above suggests the other direction: lift the product gate, and the tests pass as written. The two suites assert the [PERF] #4594 (fix of #4545) incomplete: TorchFP8Linear (CUDA AUTO for FP8) still decodes every weight through FP32 plus a transpose copy per forward: bs1 decode 7.6x slower than dense fp16 on sm_120 (Llama-3.1-8B layers) #5146 contract without a ROCm condition:tests/kernels/test_fp8_kernel.py::test_fp8_default_forward_is_w8a16[dtype1-{tensor,row}-{float8_e4m3fn,float8_e5m2}](4 fail). The oracle is the un-narrowed weight, and ROCm is off by one bf16 ulp:Mismatched elements: 17 / 320 (5.3%) Greatest absolute difference: 0.0078125.tests/test_fp8_bias_range.py::test_fp8_bias_free_cuda_in_range_weights_keep_native_path[dtype0, dtype1](2 fail). The checkassert lean_calls == [dtype]getsassert [] == [torch.float16].
The rest of the FP8, ROCm-gating, [PERF] #4594 (fix of #4545) incomplete: TorchFP8Linear (CUDA AUTO for FP8) still decodes every weight through FP32 plus a transpose copy per forward: bs1 decode 7.6x slower than dense fp16 on sm_120 (Llama-3.1-8B layers) #5146, [BUG] Regression from #5178 (fix of #5174): FP8 per-token _scaled_mm probe runs inside forward - a cold first call under CUDA-graph capture fails and caches 'unsupported' for the process; fullgraph compile fails ('opaque object') #5195 and [PERF] #5173 (fix of #5146) incomplete for block-scaled FP8 (FineGrainedFP8/DeepSeek/Qwen checkpoints, the load-only production format): TorchFP8Linear still rebuilds the weight in two full passes per forward - bs1 decode 3.6x dense fp16 on sm_120, 5.5x per linear #5318 tests in the same run pass (954 passed, 6 failed).
Repro
# ROCm GPU visible; tests/ on sys.path for the fixture helper
import torch
from gptqmodel.nn_modules.qlinear import fp8 as F
from gptqmodel.nn_modules.qlinear.fp8 import TorchFP8Linear
from fp8_test_utils import pack_fp8_module
torch.manual_seed(0)
lin = torch.nn.Linear(4096, 4096, bias=False); lin.weight.data.normal_(0, 0.02)
m = TorchFP8Linear(bits=8, group_size=-1, sym=True, desc_act=False, in_features=4096, out_features=4096, bias=False,
register_buffers=False, format="float8_e4m3fn", weight_scale_method="row")
pack_fp8_module(m, lin); m = m.cuda().eval()
dec = m.weight.double() * m.weight_scale_inv.double().reshape(-1, 1) # multiplier semantics
x = torch.randn(16, 4096, device="cuda", dtype=torch.bfloat16)
oracle = (x.double() @ dec.t()).to(torch.bfloat16)
for gate in (True, False):
F.IS_ROCM = gate; m._invalidate_compiled()
with torch.inference_mode(): y = m(x)
print("IS_ROCM gate" if gate else "lean path ", (y != oracle).float().mean().item())
# IS_ROCM gate 0.4124
# lean path 0.0002Suggested fix
Qualify the lean epilogue on ROCm. On gfx1201 the cast is exact, and a once-per-process probe of the 256 codes per format, like the _scaled_mm contract probe from #5174/#5195, would cover other HIP targets. Drop the bare IS_ROCM from _lean_epilogue_eligible, update the doc row, and keep the two tests above as the ROCm contract. If you prefer to keep ROCm on the reference path, #5325 B3's test-side fix still applies.
Severity: medium. On ROCm, FP8 row/tensor (ModelOpt per-tensor) checkpoints are about 3x slower per projection, and about 41% of outputs are rounded wrong by one ulp. The suite is also red on ROCm.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 19, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5550
ROCm FP8 lean-epilogue gate: replace the blanket IS_ROCM rejection with a measured native-cast contract probe and update docs; CPU unit coverage for the probe/gate.
fix(fp8): measure the native cast contract instead of gating every RO…