torch.accelerator.is_available — PyTorch 2.7 documentation (original) (raw)

torch.accelerator.is_available()[source][source]

Check if the current accelerator is available at runtime: it was build, all the required drivers are available and at least one device is visible. See accelerator for details.

Returns

A boolean indicating if there is an available accelerator.

Return type

bool

Example:

assert torch.accelerator.is_available() "No available accelerators detected."