[ROCm][Test] Fix test_per_token_group_quant_fp8 tolerance for 1-ULP FP8 rounding on gfx950 (#46944)
Signed-off-by: Spandan Tiwari <sptiwari@amd.com>
Spandan Tiwari committed
Jul 5, 2026 at 16:02 UTC
b71218107fac12bdbbffed3aa597b508347365b9
1 file changed
+19
-1
tests/kernels/quantization/test_block_fp8.py
+19
-1
@@ -11,6 +11,7 @@ from tests.kernels.quant_utils import (
11
native_per_token_group_quant_fp8,
12
native_w8a8_block_matmul,
13
)
14
+from tests.kernels.utils import fp8_ulp_distance
15
from vllm.config import VllmConfig
16
from vllm.model_executor.kernels.linear.scaled_mm.cutlass import cutlass_scaled_mm
17
from vllm.model_executor.layers.quantization.utils.fp8_utils import (
@@ -93,7 +94,24 @@ def test_per_token_group_quant_fp8(
94
tma_aligned_scales=tma_aligned_scales,
95
)
96
96
- assert torch.allclose(out.to(torch.float32), ref_out.to(torch.float32), rtol=0.15)
97
+ if current_platform.is_rocm():
98
+ # On gfx950 the Triton and PyTorch FP8 kernels can round in opposite
99
+ # directions when an element lands at the midpoint between two adjacent
100
+ # e4m3fn values (1-ULP tie-breaking). Verify: (1) no element is more
101
+ # than 1 FP8 ULP away, and (2) fewer than 0.05% of elements have any
102
+ # mismatch. Observed worst case across all parameter combos: 0.049%,
103
+ # max ULP = 1.
104
+ ulp = fp8_ulp_distance(out, ref_out)
105
+ assert (ulp <= 1).all(), (
106
+ f"FP8 mismatch > 1 ULP: {int((ulp > 1).sum())} elements"
107
+ )
108
+ assert float((ulp > 0).float().mean()) < 5e-4, (
109
+ f"Too many 1-ULP mismatches: {int((ulp > 0).sum())}/{ulp.numel()}"
110
+ )
111
+ else:
112
+ assert torch.allclose(
113
+ out.to(torch.float32), ref_out.to(torch.float32), rtol=0.15
114
+ )
115
assert torch.allclose(scale, ref_scale)
116
117
if column_major_scales: