Python打印Python环境、PyTorch和CUDA版本、GPU数量名称等信息

代码:

import torch
import platform

gpu_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)))

输出:
在这里插入图片描述

你可能感兴趣的:(python,pytorch,开发语言)