-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Correct torch.xpu.is_bf16_supported return False if no XPU detected #152317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -66,9 +66,14 @@ def is_available() -> bool: | |||
return device_count() > 0 | |||
|
|||
|
|||
def is_bf16_supported(): | |||
def is_bf16_supported(including_emulation: bool = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API align to other backend, refer to
pytorch/torch/cuda/__init__.py
Line 184 in 7cae790
def is_bf16_supported(including_emulation: bool = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_emulation
totorch.xpu.is_bf16_supported
and,False
if XPU is not availableTrue
ifincluding_emulation
is Truetorch.xpu.get_device_properties().has_bfloat16_conversions
ifincluding_emulation
is False, it means if the device could generate SPIRV code for bf16.cc @gujinghui @EikanWang @fengyuan14