PyTorch torch.is_available Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.is_availableis a function in PyTorch used to check whether CUDA is available. Returns True if CUDA is available, False if not.

Function Definition

torch.is_available()

Usage Example

Example

import torch

# Check if CUDA is available
if torch.is_available():
    print("CUDA is available!")
    print(f"CUDA device count: {torch.cuda.device_count()}")
else:
    print("CUDA is not available")

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions