pytorch(cuda)的安装

安装好之后可以进去虚拟环境,然后进去python,接着导入模块import torch,然后torch.cuda.get_device_capability()可以知道自己的显卡的算力!!!我的cuda算力是3.5,而大神说pytorch1.3需要满足>=3.7算力,所以就不用想了!我的显卡是GeForce920m。

需要注意的是每种包(或框架)对应的python版本,对应的其它包的版本是一一对应的,需要搞清楚再来安装。

1.安装了anaconda之后先创建一个虚拟环境:

  创建虚拟环境:conda create -n env_name list of packagename,如:conda create -n pytorch python=3.7

2.然后用nvcc -V(如果没有反应就先安装sudo apt install nvidia-cuda-toolkit)查看Linux系统的cuda是什么版本,我的cuda版本是9.1.85。

3.接着去pytorch官网找安装pytorch的安装命令conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch

4.进入虚拟环境,安装:conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch

注意:可以直接覆盖,不需要先卸载再安装。

  1.一开始我是用conda install pytorch torchvision cudatoolkit=10.2 -c pytorch来安装,没有指定pytorch的版本,所以它会自动安装最新的版本(1.5.1)。

  但是运算的时候出现了错误RuntimeError: CUDA error: no kernel image is available for execution on the device(运行时错误:CUDA错误:没有可在设备上执行的内核映像),可能是安装的cuda版本和系统的cuda版本不一样的原因

  2.之后换成了cuda9.2版本:conda install pytorch torchvision cudatoolkit=9.2 -c pytorch,同样没有指定pytorch的版本,还是自动安装最新的版本(1.5.1)。

  运算的时候还是出现了错误RuntimeError: CUDA error: no kernel image is available for execution on the device,cuda版本和pytorch版本是需要一一对应的

  3.最后换成了cuda9.2版本并指定了pytorch1.2.0版本:conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch,再次运算就可以了。

 

  4.conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2 -c pytorch

      conda install pytorch==1.3.1 torchvision==0.4.2 cudatoolkit=9.2 -c pytorch

   这两个都不行。都会报错RuntimeError: CUDA error: no kernel image is available for execution on the device运行时错误:CUDA错误:没有可在设备上执行的内核映像)

 

我更换台式机(显卡2070s)之后直接在环境中安装CUDA和CUDNN。CUDA和CUDNN的安装教程可见:https://www.cnblogs.com/zhengzian/articles/13938516.html

 

posted @ 2020-07-26 21:53  木芯子  阅读(3204)  评论(0编辑  收藏  举报