Repository navigation
fix(fp8): measure the native cast contract instead of gating every ROCm device (#5429) - #5550
Merged
Merged
Conversation
This was referenced Nov 19, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 20, 2026
…5649) 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
TorchFP8Linear._lean_epilogue_eligiblerejected every ROCm device with a bareif IS_ROCM, so row/tensor-scaled FP8 checkpoints took the pre-#5146 dequantize-then-matmul path there. On gfx1201 that costs about 3x latency and rounds ~41% of outputs to a different value (measured in #5429), even though all 256 codes of all four FP8 formats cast to fp16/bfloat16/fp32 bit-equal to the CPU cast.The blanket rejection is replaced by a measurement:
_probe_native_fp8_cast(device, fp8_dtype, out_dtype)casts all 256 8-bit patterns on the device, moves the result back once, and compares it bit-for-bit with the CPU cast. It returns a 0-dim bool tensor, so the probe itself does not synchronise._native_fp8_cast_verdictcaches one verdict per(device index, fp8 dtype, out dtype). CUDA returnsTruewithout probing (unchanged behaviour). ROCm measures once;None(capture/tracing, or an allocation failure) keeps the reference path for that call without caching a "no", mirroring the [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 contract prober._lean_epilogue_eligiblenow consults the verdict after_native_gemm_eligible, so a device whose cast is not bit-exact (or could not be measured) keeps the exact reference path.docs/fp8-lean-decode-epilogue.mdupdates the flow label, the failure-contract row and the validation table.Tests
tests/test_fp8_native_cast_probe_5429.py(8 nodes): the prober accepts every code of all four formats × fp16/bfloat16/fp32 on the reference device, returns a device-side verdict, skips the measurement on CUDA, measures once and caches, caches a failed cast, does not cache while capturing, and the lean gate follows the verdict. All 8 fail onorigin/mainwith the source change stashed and pass with it.Neighbours:
tests/test_rocm_fp8_gating.py,test_fp8_bias_range.py,test_fp8_bias_native_gemm_4681.py,test_fp8_dequant_inplace.py,test_fp8_packed_weight_lifecycle.py,test_fp8_bf16_scale_reload.py,test_fp8_bias_dtype_4575.py,test_fp8.py, plus the new file → 120 passed.tests/kernels/test_fp8_{probe_5195,kernel,lean_decode_5146,block_decode_5318}.py→ 159 passed, 6 skipped.bash format/check.shclean.Limits
torchcast the lean epilogue uses. The Triton block-decode paths already cast in-kernel and are unchanged.Closes #5429.