Repository navigation
[Inductor][FFT] Support f16/bf16 inputs on CUDA/XPU via promotion to float32 - #180766
Alokksinha00 wants to merge 9 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180766
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Unclassified FailureAs of commit 6390770 with merge base 9ac037d ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "module: fft" |
|
@pytorchbot label "topic: not user facing" |
|
CuFFT supports bfloat16 kernels on SM80+? https://docs.nvidia.com/cuda/cufft/ just wire in the missing templates |
|
@Alokksinha00 , besides bfloat16, should this PR add |
|
updating in the next patch |
60ae0f5 to
6af0a98
Compare
|
❌ 🤖 pytorchbot command failed: Try |
|
@EikanWang , @guangyey , could you please approve the pending CI workflows to unblock the run and help in merge ? |
|
@pytorchbot label "module: inductor" |
|
|
|
The code base is out-of-date. Just rebase it. |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
6af0a98 to
5f5166e
Compare
|
Hi @jansel, the failures are resolved. Could you please help take another look. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: xpu / linux-noble-xpu-n-py3.10 / test (default, 1, 12, linux.idc.xpu) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: xpu / linux-noble-xpu-n-py3.10 / test (default, 1, 12, linux.idc.xpu) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…float32 (pytorch#180766) [FFT] Support float16/bfloat16 inputs on CUDA/XPU float16 and bfloat16 have no native XPU FFT kernel, but can be supported by silently promoting to float32 before the transform — analogous to how complex32 (chalf) is promoted to complex64. The promotion is device-gated to XPU only. CPU continues to reject both with 'Unsupported dtype'. On CUDA, bfloat16 is supported natively by cuFFT on SM_80+ (Ampere) devices via CUDA_R_16BF/CUDA_C_16BF transform types, with the same power-of-two size constraint as the existing float16 (CUDA_R_16F) path. On pre-SM80 CUDA and ROCm, bfloat16 falls back to float32 promotion. float16 on CUDA continues to use the pre-existing native cuFFT path. Root cause: promote_type_fft() in SpectralOps.cpp did not handle kBFloat16 or kHalf on XPU, causing them to fall through to the TORCH_CHECK and fail with 'Unsupported dtype'. This broke rfft, irfft, fft, stft, and all n-dimensional FFT variants when called with these dtypes under torch.compile / torchinductor on XPU devices. Changes: - SpectralOps.cpp: promote kBFloat16 and kHalf to kFloat on XPU in promote_type_fft(); pass both through unchanged on CUDA to let the cuFFT planner handle them natively or fall back - SpectralOps.cpp: add kComplexHalf -> kComplexFloat upcast for complex input path (analogous fix for complex32) - cuda/CuFFTPlanCache.h: wire in CUDA_R_16BF/CUDA_C_16BF cuFFT types for bfloat16 on SM_80+ CUDA; guarded with #if !defined(USE_ROCM) since hipFFT does not support these types - cuda/SpectralOps.cpp: native bfloat16 R2C path for SM_80+ allocates a ComplexHalf proxy buffer (same 4-byte layout as CUDA_C_16BF) and upcasts to ComplexFloat; falls back to float32 promotion on ROCm, pre-SM80 CUDA, and multi-dim non-optimised paths - torch/_refs/fft.py: mirror both dtype allowances in _promote_type_fft - test/test_spectral_ops.py: update test_fft_half_and_bfloat16_errors to skip bfloat16 on CUDA/XPU (no longer errors); add new positive test test_fft_bfloat16_promoted_on_cuda asserting bfloat16 input produces complex64 output on CUDA Fixes: torch.fft.rfft/irfft/stft with float16/bfloat16 input on XPU/CUDA Pull Request resolved: pytorch#180766 Approved by: https://github.com/EikanWang, https://github.com/guangyey, https://github.com/jansel Co-authored-by: sachinkademane <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…float32 (pytorch#180766) [FFT] Support float16/bfloat16 inputs on CUDA/XPU float16 and bfloat16 have no native XPU FFT kernel, but can be supported by silently promoting to float32 before the transform — analogous to how complex32 (chalf) is promoted to complex64. The promotion is device-gated to XPU only. CPU continues to reject both with 'Unsupported dtype'. On CUDA, bfloat16 is supported natively by cuFFT on SM_80+ (Ampere) devices via CUDA_R_16BF/CUDA_C_16BF transform types, with the same power-of-two size constraint as the existing float16 (CUDA_R_16F) path. On pre-SM80 CUDA and ROCm, bfloat16 falls back to float32 promotion. float16 on CUDA continues to use the pre-existing native cuFFT path. Root cause: promote_type_fft() in SpectralOps.cpp did not handle kBFloat16 or kHalf on XPU, causing them to fall through to the TORCH_CHECK and fail with 'Unsupported dtype'. This broke rfft, irfft, fft, stft, and all n-dimensional FFT variants when called with these dtypes under torch.compile / torchinductor on XPU devices. Changes: - SpectralOps.cpp: promote kBFloat16 and kHalf to kFloat on XPU in promote_type_fft(); pass both through unchanged on CUDA to let the cuFFT planner handle them natively or fall back - SpectralOps.cpp: add kComplexHalf -> kComplexFloat upcast for complex input path (analogous fix for complex32) - cuda/CuFFTPlanCache.h: wire in CUDA_R_16BF/CUDA_C_16BF cuFFT types for bfloat16 on SM_80+ CUDA; guarded with #if !defined(USE_ROCM) since hipFFT does not support these types - cuda/SpectralOps.cpp: native bfloat16 R2C path for SM_80+ allocates a ComplexHalf proxy buffer (same 4-byte layout as CUDA_C_16BF) and upcasts to ComplexFloat; falls back to float32 promotion on ROCm, pre-SM80 CUDA, and multi-dim non-optimised paths - torch/_refs/fft.py: mirror both dtype allowances in _promote_type_fft - test/test_spectral_ops.py: update test_fft_half_and_bfloat16_errors to skip bfloat16 on CUDA/XPU (no longer errors); add new positive test test_fft_bfloat16_promoted_on_cuda asserting bfloat16 input produces complex64 output on CUDA Fixes: torch.fft.rfft/irfft/stft with float16/bfloat16 input on XPU/CUDA Pull Request resolved: pytorch#180766 Approved by: https://github.com/EikanWang, https://github.com/guangyey, https://github.com/jansel Co-authored-by: sachinkademane <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Issues reported here: #4268 After changes were made here: pytorch/pytorch#180766 According to documentation ([meta.md](https://github.com/pytorch/pytorch/blob/main/docs/source/meta.md)): In some cases, not all device types (e.g., CPU and CUDA) have exactly the same output metadata for an operation; we typically prefer representing the CUDA behavior faithfully in this situation. Disabled test cases for FFT with float16 in test_meta_xpu.py Reported test cases in test_ops_xpu.py and test_spectral_ops_xpu.py cannot be disabled because those files are not fully copied to XPU, running native pytorch tests.
…float32 (pytorch#180766) [FFT] Support float16/bfloat16 inputs on CUDA/XPU float16 and bfloat16 have no native XPU FFT kernel, but can be supported by silently promoting to float32 before the transform — analogous to how complex32 (chalf) is promoted to complex64. The promotion is device-gated to XPU only. CPU continues to reject both with 'Unsupported dtype'. On CUDA, bfloat16 is supported natively by cuFFT on SM_80+ (Ampere) devices via CUDA_R_16BF/CUDA_C_16BF transform types, with the same power-of-two size constraint as the existing float16 (CUDA_R_16F) path. On pre-SM80 CUDA and ROCm, bfloat16 falls back to float32 promotion. float16 on CUDA continues to use the pre-existing native cuFFT path. Root cause: promote_type_fft() in SpectralOps.cpp did not handle kBFloat16 or kHalf on XPU, causing them to fall through to the TORCH_CHECK and fail with 'Unsupported dtype'. This broke rfft, irfft, fft, stft, and all n-dimensional FFT variants when called with these dtypes under torch.compile / torchinductor on XPU devices. Changes: - SpectralOps.cpp: promote kBFloat16 and kHalf to kFloat on XPU in promote_type_fft(); pass both through unchanged on CUDA to let the cuFFT planner handle them natively or fall back - SpectralOps.cpp: add kComplexHalf -> kComplexFloat upcast for complex input path (analogous fix for complex32) - cuda/CuFFTPlanCache.h: wire in CUDA_R_16BF/CUDA_C_16BF cuFFT types for bfloat16 on SM_80+ CUDA; guarded with #if !defined(USE_ROCM) since hipFFT does not support these types - cuda/SpectralOps.cpp: native bfloat16 R2C path for SM_80+ allocates a ComplexHalf proxy buffer (same 4-byte layout as CUDA_C_16BF) and upcasts to ComplexFloat; falls back to float32 promotion on ROCm, pre-SM80 CUDA, and multi-dim non-optimised paths - torch/_refs/fft.py: mirror both dtype allowances in _promote_type_fft - test/test_spectral_ops.py: update test_fft_half_and_bfloat16_errors to skip bfloat16 on CUDA/XPU (no longer errors); add new positive test test_fft_bfloat16_promoted_on_cuda asserting bfloat16 input produces complex64 output on CUDA Fixes: torch.fft.rfft/irfft/stft with float16/bfloat16 input on XPU/CUDA Pull Request resolved: pytorch#180766 Approved by: https://github.com/EikanWang, https://github.com/guangyey, https://github.com/jansel Co-authored-by: sachinkademane <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
oneMKL provides no half-precision DFT, so torch-xpu-ops emulates one: it upcasts Half to Float, runs both the transform and the normalization in float32, and rounds to complex32 once at the end. Separately, pytorch#171231 added "xpu" to maybe_support_half in torch/_refs/fft.py, which tells the reference implementation that XPU supports half natively. The ref consequently stays in float16 and rounds at every prim boundary, while the eager path it is compared against quietly computed in float32. test_python_ref, test_python_ref_torch_fallback and test_python_ref_executor assert ref_distance <= torch_distance against a float64 baseline with no tolerance, so the ref loses that comparison: 1.18x worse for ihfftn and 1.02x for ihfft2, on 1 of 10 OpInfo samples. The XPU kernel is not wrong here; it is more accurate than true float16 would be. No user-visible path is affected, because inductor promotes float16 FFT to float32 (pytorch#180766) rather than lowering through these refs, and compiled output is bit-identical to eager. This adds five xpu-scoped, float16-only skips beside the existing cuda ones for _refs.fft.ihfft2 and _refs.fft.ihfftn. It is a pure addition and leaves CUDA behaviour untouched. Three routes were available. Widening the existing decorators to device_type=("cuda", "xpu") is terser, but it would attach comments describing CUDA's native-float16 rounding to a structurally different XPU cause, so the skips are added as separate entries carrying their own reason - which also matches the pattern established by pytorch#176688 and pytorch#178849. Adding a tolerance to the assertion itself would treat the cause and let CUDA, ROCm and XPU all drop skips, but that single assertion guards every test_python_ref case on every backend and dtype, so it needs primTorch ownership rather than an XPU change. Making the refs compute in float32 and cast back to complex32 is the only route that preserves coverage, but it puts device-conditional numerics inside a deliberately device-agnostic reference library; that is left for discussion on the linked issue. These three tests are currently unreachable on XPU because of the @skipXPU decorators on them in test/test_ops.py, which are being removed incrementally (pytorch#159944 introduced them, pytorch#176688 and pytorch#178849 have removed most). Declaring the skips here is the prerequisite for removing the remaining ones without turning XPU CI red. Test Plan Verified on Intel Arc B570 Graphics (Battlemage). With both skip sources disabled, exactly five cases fail; with this change they are skipped and the rest of the selection still passes. ``` cd third_party/torch-xpu-ops python -m pytest test/xpu/test_ops_xpu.py \ -k "python_ref and (ihfft2 or ihfftn)" -v --timeout=600 ``` ``` before (both skip sources disabled): 5 failed, 11 passed after (this change): 0 failed, 68 passed, 14 skipped ``` The skip set was additionally cross-checked by evaluating DecorateInfo.is_active over both ops, all three tests and all ten instantiated dtypes for device_type in (cuda, xpu): it matches the five measured failures exactly, and CUDA's set is unchanged. ``` lintrunner -a torch/testing/_internal/opinfo/definitions/fft.py ok No lint issues. ``` Authored with the assistance of an AI coding agent; the change and the test output above come from a run on Intel GPU hardware and were reviewed by a human before submission. AI-Assisted: Claude Code (xpu-workspace ai_assisted agent, issue pytorch#174) Co-Authored-By: Claude Opus 5 <[email protected]>
Issues reported here: intel#4268 After changes were made here: pytorch/pytorch#180766 According to documentation ([meta.md](https://github.com/pytorch/pytorch/blob/main/docs/source/meta.md)): In some cases, not all device types (e.g., CPU and CUDA) have exactly the same output metadata for an operation; we typically prefer representing the CUDA behavior faithfully in this situation. Disabled test cases for FFT with float16 in test_meta_xpu.py Reported test cases in test_ops_xpu.py and test_spectral_ops_xpu.py cannot be disabled because those files are not fully copied to XPU, running native pytorch tests.
[FFT] Support float16/bfloat16 inputs on CUDA/XPU
float16 and bfloat16 have no native XPU FFT kernel, but can be
supported by silently promoting to float32 before the transform —
analogous to how complex32 (chalf) is promoted to complex64. The
promotion is device-gated to XPU only. CPU continues to reject both
with 'Unsupported dtype'.
On CUDA, bfloat16 is supported natively by cuFFT on SM_80+ (Ampere)
devices via CUDA_R_16BF/CUDA_C_16BF transform types, with the same
power-of-two size constraint as the existing float16 (CUDA_R_16F) path.
On pre-SM80 CUDA and ROCm, bfloat16 falls back to float32 promotion.
float16 on CUDA continues to use the pre-existing native cuFFT path.
Root cause: promote_type_fft() in SpectralOps.cpp did not handle
kBFloat16 or kHalf on XPU, causing them to fall through to the
TORCH_CHECK and fail with 'Unsupported dtype'. This broke rfft, irfft,
fft, stft, and all n-dimensional FFT variants when called with these
dtypes under torch.compile / torchinductor on XPU devices.
Changes:
promote_type_fft(); pass both through unchanged on CUDA to let the
cuFFT planner handle them natively or fall back
input path (analogous fix for complex32)
for bfloat16 on SM_80+ CUDA; guarded with #if !defined(USE_ROCM)
since hipFFT does not support these types
ComplexHalf proxy buffer (same 4-byte layout as CUDA_C_16BF) and
upcasts to ComplexFloat; falls back to float32 promotion on ROCm,
pre-SM80 CUDA, and multi-dim non-optimised paths
to skip bfloat16 on CUDA/XPU (no longer errors); add new positive
test test_fft_bfloat16_promoted_on_cuda asserting bfloat16 input
produces complex64 output on CUDA
Fixes: torch.fft.rfft/irfft/stft with float16/bfloat16 input on XPU/CUDA
cc @mruberry @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo