Repository navigation
fix(fp8): ignore NaN payload bits in the native cast probe (#5570) - #5649
Merged
Merged
Conversation
The ROCm FP8 cast probe compared the raw bit pattern of every code against the CPU reference. ROCm preserves the source NaN payload/sign while the CPU cast canonicalises it, so all four FP8 formats were judged not bit-exact on gfx1201 and the lean bf16 path was never taken (#5550 left this half-fixed: only the non-NaN codes agree). A NaN cannot change a matmul result and the conversion contract does not pin its payload, so compare NaN-ness and the remaining codes' bits separately. A code that becomes (or stops being) NaN is still rejected. Adds tests/test_fp8_native_cast_probe_nan_5570.py: NaN-payload-only differences pass, a single non-NaN bit flip / NaN<->number transition fails, and the probe is wired to the new comparison.
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.
What
_probe_native_fp8_castcompared the raw bit pattern of all 256 FP8 codes against the CPU reference. ROCm preserves the source NaN payload/sign while the CPU cast canonicalises NaN to+0x7FC0, so every e4m3fn/e5m2 -> bf16 probe returnedFalseon gfx1201 even though all non-NaN codes are bit-exact. That kept bf16 on the slow path (#5550 fixed the per-token/row-scale half of #5429; the cast probe stayed broken).Fix
Split the comparison into
_compare_fp8_casts(expected, actual):A NaN cannot change a matmul result and the conversion contract does not pin its payload, so payload/sign differences are not a precision loss. The probe still returns a 0-dim bool tensor.
Tests
New
tests/test_fp8_native_cast_probe_nan_5570.py(CPU-only, 6 nodes; all 6 fail on cleanmainbecause the helper does not exist):Also passes:
tests/test_fp8_native_cast_probe_5429.py,tests/kernels/test_fp8_probe_5195.py,tests/test_rocm_fp8_gating.py,tests/test_fp8_bias_range.py,tests/kernels/test_fp8_lean_decode_5146.py,tests/test_fp8_load_no_copy_5584.py,tests/kernels/test_fp8_block_decode_5318.py,tests/kernels/test_fp8_kernel.py-> 215 passed, 6 skipped.bash format/check.shclean.Not verified locally
No ROCm device in this environment, so the gfx1201 verdict is not re-measured here; the payload behaviour is simulated on CPU from the documented ROCm cast difference in the issue.