文章目录
- 安装pytorch的CUDA
- 3.1 验证
- 4 运行程序获取设备信息
- 参考链接
安装pytorch的CUDA
根据pytorch的官网确定自己的安装命令是什么。创建一个conda的虚拟环境,卸载之前的torch。
官网
pip uninstall torch
3.1 验证
torch.cuda.is_available()返回False错误解决
使用其中的脚本,或者调用cuda确认版本。在pycharm中切换为对应的pytorch环境版本。
4 运行程序获取设备信息
编写python代码获取设备信息。
try:
import torch
TORCH_AVAILABLE = True
except (ImportError, NameError, AttributeError, OSError):
TORCH_AVAILABLE = False
if TORCH_AVAILABLE and torch.cuda.is_available():
print(f"gpu name: {torch.cuda.get_device_name(None)}")
print(f"gpu 是否可用: {torch.cuda.is_available()}")
print(f"gpu numbers :{torch.cuda.device_count()}")
输出如下:
gpu name: GeForce GTX 1660 SUPER
gpu 是否可用: True
gpu numbers :1
参考链接