Rate this Page

torch.accelerator.current_accelerator#

torch.accelerator.current_accelerator(check_available=False)[source]#

Return the device of the accelerator available at compilation time.If no accelerator were available at compilation time, returns None.Seeaccelerator for details.

Parameters

check_available (bool,optional) – if True, will also do a runtime check to seeif the devicetorch.accelerator.is_available() on top of the compile-timecheck.Default:False

Returns

return the current accelerator astorch.device.

Return type

torch.device

Note

The index of the returnedtorch.device will beNone, please usetorch.accelerator.current_device_index() to know the current index being used.This API does NOT poison fork. For more details, seePoison fork in multiprocessing.

Example:

>>># If an accelerator is available, sent the model to it>>>model=torch.nn.Linear(2,2)>>>if(current_device:=current_accelerator(check_available=True))isnotNone:>>>model.to(current_device)