Consolidating blockwise FP32 scale flag - #687
Conversation
| if IS_HIP_EXTENSION: | ||
| atol = 1e-5 | ||
| rtol = 1.3e-6 | ||
| fp32_scale_kernel = os.getenv("NVTE_FP8_BLOCK_SCALING_FP32_SCALES", "0") == "1" |
There was a problem hiding this comment.
The new kernel path is selected here, but the quantizers below still hardcode force_pow_2_scales=True (lines 141 and 149), so the FP32-scale kernel is only ever validated against scale values that happen to be powers of 2.
In production the flag is coupled: Float8BlockScaling sets power_2_scale=not use_f32_scales (transformer_engine/common/recipe/__init__.py:447), so NVTE_FP8_BLOCK_SCALING_FP32_SCALES=1 means the GEMM receives genuinely non-power-of-2 FP32 scales. That combination — which is exactly what this PR enables — is never exercised by this test.
Consider threading the flag through, e.g. force_pow_2_scales=not fp32_scale_kernel, so the loosened tolerances are actually measuring the configuration they were derived for.
| rtol = 1.3e-6 | ||
| fp32_scale_kernel = os.getenv("NVTE_FP8_BLOCK_SCALING_FP32_SCALES", "0") == "1" | ||
| large_magnitude = x_magnitude >= 1000 | ||
| if not fp32_scale_kernel: |
There was a problem hiding this comment.
The tolerance branch keys off the env var alone, but the running-scale kernel only exists on gfx950. The CDNA3 backend (transformer_engine/common/gemm/kittens/cdna3/blockwise_fp8_gemm.cpp) has no getenv and no power-of-2 path at all — it always consumes FP32 scales directly, so this flag has zero effect on gfx942.
Net effect: running this suite on gfx942 with NVTE_FP8_BLOCK_SCALING_FP32_SCALES=1 relaxes rtol from 1.3e-6 to 2e-2 (~15000x) for a kernel whose behavior did not change, silently masking any regression there.
Suggest gating on arch as well, e.g. only take the loose branch when the device is gfx950.
| elif out_dtype == torch.float32: | ||
| rtol = 1e-3 | ||
| atol = 1e-1 if large_magnitude else 2e-4 | ||
| else: | ||
| rtol = 2e-2 | ||
| atol = 3e1 if large_magnitude else 3e-2 |
There was a problem hiding this comment.
Two notes on the loosened branches:
-
These are six unexplained magic numbers in a file named
..._exact.py, andrtol = 2e-2is roughly 2.5x a bf16 ulp — a large relaxation for a test whose purpose is bit-tight agreement with the reference. The PR description explains the cause (running-scale accumulation reorders the sum); a one-line comment here would keep that rationale attached to the numbers instead of only in the PR. -
large_magnitudeis derived fromx_magnitudeonly. Every call site in this file passesw_magnitude=1, so it is correct today, but the absolute error scales with the product of both operands — a futurew_magnitudeparametrization would silently get the tightatol.
| if IS_HIP_EXTENSION: | ||
| import os | ||
|
|
There was a problem hiding this comment.
Nit: os is stdlib and free to import; gating it behind IS_HIP_EXTENSION adds a conditional-import pattern that lint tools tend to flag and that readers have to double-check. A plain import os with the other top-level imports would be simpler.
| if IS_HIP_EXTENSION: | |
| import os | |
| import os | |
Review summaryReviewed the full diff against the merge base (README.rst, Verdict: looks good overall, with test-side concerns worth addressing before merge. The flag consolidation itself is correct. The inverted The four inline comments are all on the test file:
Copyright headers: OK — all three modified files carry AMD lines ending in 2026, NVIDIA lines untouched. |
| if IS_HIP_EXTENSION: | ||
| atol = 1e-5 | ||
| rtol = 1.3e-6 | ||
| running_scale_kernel = ( |
There was a problem hiding this comment.
Only the gfx950 + NVTE_FP8_BLOCK_SCALING_FP32_SCALES = 1 uses the continuous fp32 scale with running scale kernel.
By default NVTE_FP8_BLOCK_SCALING_FP32_SCALES = 0 and uses power-of-2 kernel.
gfx942 only has 1 kernel (continuous fp32 scale kernel) but this is not utilizing running scale method, and thus more precise.
c7b70d1 to
9881263
Compare
Description
Please include a brief summary of the changes, relevant motivation and context.
The upstream already had a flag NVTE_FP8_BLOCK_SCALING_FP32_SCALES (default 0) which is used to limit and store the blockwise quantization scales in the power-of-2 in fp32 precision. This PR is removing the unnecessary additional flag and using the original flag and on gfx950, if this flag is set to 1, then the host blockwise gemm dispatcher selects the kernel with fp32 scale computation.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: