pytorch慢到无法安装,该怎么办?
最近幾天,后臺幾個小伙伴問我,無論pip還是conda安裝pytorch都太慢了,都是安裝官方文檔去做的,就是超時裝不上,無法開展下一步,卡脖子的感覺太不好受。
這些小伙伴按照pytorch官檔提示,選擇好后,
完整復制上面命令conda install pytorch torchvision cudatoolkit=10.1 -c pytorch到cmd中,系統是windows.
接下來界面提示,conda需要安裝的包,選擇y,繼續安裝,但是接下來發現進度條幾乎一動不動。
反復嘗試,就是這樣,有些無奈,還感嘆怎么深度學習的路一開始就TMD的這么難!
2 這樣能正常安裝
無論是安裝cpu版還是cuda版,網上關于這些的參考資料太多了,無非就是cuda硬件和cuda開發包的版本要對應,python版本要對應等,這些bee君覺得都不是事。
就像幾位讀者朋友遇到的問題,關鍵還是如何解決慢到無法裝的問題。
最有效方法是添加鏡像源,常見的清華或中科大。
先查看是否已經安裝相關鏡像源,windows系統在cmd窗口中執行命令:
conda config --showbee君這里顯示:
channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/說明已經安裝好清華的鏡像源。如果沒有安裝,請參考下面命令安裝源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/依次安裝上面所有的源。
并設置搜索時顯示通道地址,執行下面命令:
conda config --set show_channel_urls yes3 最關鍵一步
有的讀者問我,他們已經都安裝好鏡像源,但是為什么安裝還是龜速?問他們,是用哪個命令,他們回復:conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
好吧,執行上面命令,因為命令最后是-c pytorch,所以默認還是從conda源下載,新安裝的清華等源沒有用上。
正確命令:conda install pytorch torchvision cudatoolkit=10.1,也就是去掉-c pytorch
并且在安裝時,也能看到使用了清華源。并且安裝速度直線提升,順利done
4 測試是否安裝成功
結合官檔,執行下面代碼,torch.cuda.is_available()返回True,說明安裝cuda成功。
In [1]: import torchIn [2]: torch.cuda
Out[2]: <module ‘torch.cuda’ from ‘D:\Programs\anaconda\lib\site-packages\torch\cuda\init.py’>
In [3]: torch.cuda.is_available()
Out[3]: True
In [4]: from future import print_function
In [5]: x = torch.rand(5,3)
In [6]: print(x)
tensor([[0.0604, 0.1135, 0.2656],
[0.5353, 0.9246, 0.3004],
[0.4872, 0.9592, 0.2215],
[0.2598, 0.5031, 0.6093],
[0.2986, 0.1599, 0.5862]])
這篇文章主要討論安裝pytorch慢到不能裝的問題及方案,希望對讀者朋友們有幫助。
總結
以上是生活随笔為你收集整理的pytorch慢到无法安装,该怎么办?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 968. Binary Tree Cam
- 下一篇: Python os.makedirs详细