代码:
import torch
import platformgpu_num = torch.cuda.device_count()
torch_version = torch.__version__
python_version = platform.python_version()print("Python Version: Python %s" % python_version)
print("PyTorch Version: %s" % torch_version)
print("CUDA is available: %s" % torch.cuda.is_available())
print("GPU Count: %d" % gpu_num)
for i in range(gpu_num):print("GPU %d --> GPU Name: %s" % (i + 1, torch.cuda.get_device_name(i)))
输出: