Skip to content

fix(fp8): ignore NaN payload bits in the native cast probe (#5570) - #5649

Merged
Qubitium merged 1 commit into
mainfrom
fix/fp8-nan-payload-probe-5570
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/fp8-nan-payload-probe-5570

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

_probe_native_fp8_cast compared 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 returned False on 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):

  • NaN-ness must match for every code (a NaN that becomes a number, or vice versa, still rejects the cast);
  • the remaining codes must be bit-equal.

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 clean main because the helper does not exist):

  • NaN-payload-only differences are accepted for all 4 FP8 formats x 3 output dtypes;
  • one flipped non-NaN bit is rejected;
  • NaN -> number and number -> NaN are rejected;
  • the legacy raw-bit expression still rejects the ROCm-shaped input (regression record);
  • the probe is wired to the new comparison.

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.sh clean.

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant