Correct torch.xpu.is_bf16_supported return False if no XPU detected#152317
Correct torch.xpu.is_bf16_supported return False if no XPU detected#152317guangyey wants to merge 3 commits intogh/guangyey/143/basefrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/152317
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 3 New FailuresAs of commit bc97ddf with merge base 13dcf80 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torch/xpu/__init__.py
Outdated
|
|
||
|
|
||
| def is_bf16_supported(): | ||
| def is_bf16_supported(including_emulation: bool = True): |
There was a problem hiding this comment.
API align to other backend, refer to
pytorch/torch/cuda/__init__.py
Line 184 in 7cae790
There was a problem hiding this comment.
@guangyey , why does XPU need to provide this optional parameter? Is there any case where one Intel GPU does not support BF16 native, while the Intel GPU software stack emulates BF16 for the Intel GPU?
There was a problem hiding this comment.
In simple terms, eager mode depends on emulation, while graph mode requires native support to fully leverage performance optimization.
There was a problem hiding this comment.
https://github.com/intel/llvm/blob/f958dce28053dff145cd725ff57bc4ce94cb94d7/sycl/doc/extensions/experimental/sycl_ext_oneapi_bfloat16_math_functions.asciidoc#overview According to the note, the non-XE GPU may not support BF16 natively.
|
@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 |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
Merge failedReason: New commits were pushed while merging. Please rerun the merge command. Details for Dev Infra teamRaised by workflow job |
|
"The failures are irrelevant, we have issue a ticket to track them, refer to #152912" |
Merge startedYour change will be merged while ignoring the following 3 checks: xpu / linux-jammy-xpu-2025.0-py3.9 / test (default, 2, 4, linux.idc.xpu), xpu / linux-jammy-xpu-2025.0-py3.9 / test (default, 3, 4, linux.idc.xpu), xpu / linux-jammy-xpu-2025.0-py3.9 / test (default, 1, 4, linux.idc.xpu) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
Motivation
Fix #152301
When XPU is not available, calling
torch.xpu.is_bf16_supported()still returnsTrue, which is inconsistent with the expected behavior (should be False).Solution
Align to other backend, adding
including_emulationtotorch.xpu.is_bf16_supportedand,Falseif XPU is not availableTrueifincluding_emulationis Truetorch.xpu.get_device_properties().has_bfloat16_conversionsifincluding_emulationis False, it means if the device could generate SPIRV code for bf16.cc @gujinghui @EikanWang @fengyuan14