万恶的环境2——安装的torch版本是cpu版本如何改为GPU版本

万恶的环境2——安装的torch版本是cpu版本如何改为GPU版本

感谢 参考的链接

[错误Torch not compiled with CUDA enabled解决方法附CUDA安装教程及Pytorch安装教程_nm235666的博客-CSDN博客](https://blog.csdn.net/moyong1572/article/details/119438286#:~:text=运行时报出AssertionError%3A Torch not compiled with CUDA enabled错误 ,具体,” if torch. cuda.is_available () else “cpu”) 代码)

1 报错

img

2 检查

import torch as th
print(th.__version__)
print(th.cuda.is_available())
cuda1 = th.device('cuda')
print(f'device:{cuda1} device.type:{cuda1.type}')
s = th.randn((2,3),device=cuda1)
print(s)

3 结果与问题——torch版本是cpu版本的

img

4解决

4.1 首先检查自己受否有安装cuda

在命令行中输入

nvcc -V

QQ截图20221212142910

4.2 到官网去下载对应版本的torch

Start Locally | PyTorch

5 验证效果

再次运行代码 ,发现成功

QQ截图20221212143212

posted @ 2022-12-12 14:34  英飞  阅读(1465)  评论(0编辑  收藏  举报