PyTorch torch.is_available function
PyTorch torch reference manual
torch.is_available A function in PyTorch for checking whether CUDA is available. Returns True if CUDA is available, False otherwise.
Function definition
torch.is_available()
Usage examples
Example
import
torch
Check whether CUDA is available
if
torch.
is_available
(
)
:
(
"CUDA is available!"
)
(
f
"CUDA device count: {torch.cuda.device_count()}"
)
else
:
(
"CUDA is not available"
)