安裝好之后可以進去虛擬環境,然后進去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