捷徑

torch.accelerator.current_accelerator

torch.accelerator.current_accelerator()[原始碼][原始碼]

傳回目前加速器的裝置。

傳回

torch.device傳回目前的加速器。

傳回類型

torch.device

注意

返回的 torch.device 的索引將會是 None,請使用 torch.accelerator.current_device_index() 來得知目前正在使用的索引。並且請確保使用 torch.accelerator.is_available() 來檢查是否有可用的加速器。如果沒有可用的加速器,此函數將會拋出例外。

範例

>>> if torch.accelerator.is_available():
>>>     current_device = torch.accelerator.current_accelerator()
>>> else:
>>>     current_device = torch.device("cpu")
>>> if current_device.type == 'cuda':
>>>     is_half_supported = torch.cuda.has_half
>>> elif current_device.type == 'xpu':
>>>     is_half_supported = torch.xpu.get_device_properties().has_fp16
>>> elif current_device.type == 'cpu':
>>>     is_half_supported = True

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源