Repository navigation
fix(fp8): floor tiny amax so scale_inv stays at least FLT_MIN - #3764
Open
DylanWanggg wants to merge 5 commits into
Open
DylanWanggg wants to merge 5 commits into
DylanWanggg wants to merge 5 commits into
Conversation
- transformer_engine/common/recipe/recipe_common.cuh: Floor a positive amax at max_fp8 * FLT_MIN before dividing, and still return scale 1 for zero, inf, and NaN. - tests/pytorch/references/quantize_scale_calc.py: Floor a positive tiny amax in the PyTorch reference instead of returning scale 1. - transformer_engine/pytorch/custom_recipes/reference_current_scaling.py: Floor a positive tiny amax in the custom-recipe reference. - transformer_engine/jax/quantize/quantizer.py: Floor a positive tiny amax in the JAX quantizer. - tests/cpp/operator/test_cast_current_scaling.cu: Floor a positive tiny amax in the current-scaling reference. - tests/cpp/operator/test_cast_transpose_current_scaling.cu: Floor a positive tiny amax in the transpose reference. - tests/cpp/operator/test_cast_current_scaling_grouped.cu: Floor a positive tiny amax in the grouped reference. - tests/cpp/operator/test_cast_float8blockwise.cu: Floor a positive tiny block amax in the block-scaling reference. - tests/cpp/operator/test_tiny_amax_scale_host.cpp: Check that a positive amax below the floor uses scale 2^126 and scale_inv FLT_MIN. - tests/cpp/operator/test_tiny_amax_scale_host.py: Check that floored tiny blocks stay representable in FP8 and that ordinary values stay bitwise identical. Signed-off-by: Dylan Wang <guoanwang@vip.163.com>
DylanWanggg
requested review from
jberchtold-nvidia and
ksivaman
as code owners
October 28, 2026 14:40
for more information, see https://pre-commit.ci
Contributor
[Medium impact] The PR appears safe to merge; no new blocking issue was found. SummaryFloors tiny positive
Reviews (4) · Last reviewed commit: "Merge upstream main into fix/fp8-tiny-am..." · Reviewed by Greptile |
- tests/cpp/operator/test_cast_current_scaling.cu: Call nvte_compute_scale_from_amax with a tiny amax and check the stored scale_inv. - tests/cpp/operator/CMakeLists.txt: Register the host IEEE checker with ctest. - tests/cpp/operator/test_tiny_amax_scale_host.cpp: Add the license header required by L0_license. - tests/cpp/operator/test_tiny_amax_scale_host.py: Expose pytest cases and compile the host binary in a temporary directory. - tests/pytorch/test_float8_current_scaling_exact.py: Check the public current-scaling quantizer keeps scale_inv at FLT_MIN. - qa/L0_pytorch_unittest/test.sh: Run the host pytest file in the PyTorch unittest job. Signed-off-by: Dylan Wang <guoanwang@vip.163.com>
- tests/pytorch/test_float8_current_scaling_exact.py: Build the expected FLT_MIN with the same shape as scale_inv so assert_close does not fail on a scalar. Signed-off-by: Dylan Wang <guoanwang@vip.163.com>
Keep the tiny-amax host test registered alongside the new per-case ctest option. Signed-off-by: Dylan Wang <guoanwang@vip.163.com>
Author
|
@ptrendx Merged current main into this branch (one CMakeLists conflict, both sides kept). Ready for review when you have time. Greptile's earlier notes are addressed, and DCO / pre-commit were green before this merge. |
This branch has not been deployed
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.
Description
compute_scale_from_amaxreturned scale 1 only for a zero, infinite, or NaN amax. A positive amax belowmax_fp8 * FLT_MINmissed that check, soscale = max_fp8 / amaxoverflowed andscale_invwas stored as an FP32 subnormal.max_fp8 * FLT_MINis exact in binary32. This change floors a positive amax at that value before the division.scaleis then at most2^126andscale_invis at leastFLT_MIN. An amax of7.7e-37is amplified to about 65 and kept as a non-zero FP8 code instead of flushing the tile to zero. Zero, inf, and NaN still return scale 1. An amax at or above the threshold, including ordinary training magnitudes, stays bitwise identical.The E4M3 threshold is
448 * FLT_MIN(0x04e00000). The E5M2 threshold is57344 * FLT_MIN(0x08600000).No linked issue.
Type of change
Changes
transformer_engine/common/recipe/recipe_common.cuh: Floor a positive amax atmax_fp8 * FLT_MINbefore dividing, and still return scale 1 for zero, inf, and NaN.tests/pytorch/references/quantize_scale_calc.py: Floor a positive tiny amax in the PyTorch reference.transformer_engine/pytorch/custom_recipes/reference_current_scaling.py: Floor a positive tiny amax in the custom-recipe reference.transformer_engine/jax/quantize/quantizer.py: Floor a positive tiny amax in the JAX quantizer.tests/cpp/operator/test_cast_current_scaling.cu: Floor a positive tiny amax in the current-scaling reference.tests/cpp/operator/test_cast_transpose_current_scaling.cu: Floor a positive tiny amax in the transpose reference.tests/cpp/operator/test_cast_current_scaling_grouped.cu: Floor a positive tiny amax in the grouped reference.tests/cpp/operator/test_cast_float8blockwise.cu: Floor a positive tiny block amax in the block-scaling reference.tests/cpp/operator/test_tiny_amax_scale_host.cpp: Check that a positive amax below the floor uses scale2^126and scale_invFLT_MIN.tests/cpp/operator/test_tiny_amax_scale_host.py: Check that floored tiny blocks stay representable in FP8 and that ordinary values stay bitwise identical.Delayed scaling
_default_sf_computealready clamps an infinite scale to the FP32 maximum and is unchanged.Checklist: