Shortcuts

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

torch.device

Note

The index of the returned torch.device will be None, please use torch.accelerator.current_device_idx() to know the current index being used. And ensure to use torch.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

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources