mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Refine torch.xpu.get_device_properties API error message (#144379)
# Motivation Remove the redundant error message. Without this PR: ```python >>> import torch >>> torch.xpu.get_device_name(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/guangyey/repos/stock-pytorch/torch/xpu/__init__.py", line 215, in get_device_name return get_device_properties(device).name File "/home/guangyey/repos/stock-pytorch/torch/xpu/__init__.py", line 258, in get_device_properties raise AssertionError("Invalid device index") AssertionError: Invalid device index ``` With this PR: ```python >>> import torch >>> torch.xpu.get_device_name(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/guangyey/repos/stock-pytorch/torch/xpu/__init__.py", line 215, in get_device_name return get_device_properties(device).name File "/home/guangyey/repos/stock-pytorch/torch/xpu/__init__.py", line 257, in get_device_properties return _get_device_properties(device) # type: ignore[name-defined] # noqa: F821 RuntimeError: The device index is out of range. It must be in [0, 1), but got 1. ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/144379 Approved by: https://github.com/EikanWang
This commit is contained in:
committed by
PyTorch MergeBot
parent
4375c2c534
commit
493a52cb72
@ -254,8 +254,6 @@ def get_device_properties(device: Optional[_device_t] = None) -> _XpuDevicePrope
|
||||
"""
|
||||
_lazy_init()
|
||||
device = _get_device_index(device, optional=True)
|
||||
if device < 0 or device >= device_count():
|
||||
raise AssertionError("Invalid device index")
|
||||
return _get_device_properties(device) # type: ignore[name-defined] # noqa: F821
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user