torch.accelerator.current_accelerator¶
- torch.accelerator.current_accelerator()[source]¶
Return the device of the current accelerator.
- Returns
return the current accelerator as
torch.device
.- Return type
Note
The index of the returned
torch.device
will beNone
, please usetorch.accelerator.current_device_idx()
to know the current index being used. And ensure to usetorch.accelerator.is_available()
to check if there is an available accelerator. If there is no available accelerator, this function will raise an exception.Example:
>>> 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