PyTorch 檢查GPU版本是否安裝成功的操作
更新時間:2021年03月17日 08:50:31 作者:敲代碼的小風
這篇文章主要介紹了PyTorch 檢查GPU版本是否安裝成功的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
anaconda命令行下檢查:
(base) PS C:\Users\chenxuqi> conda deactivate PS C:\Users\chenxuqi> conda activate ssd (ssd) PS C:\Users\chenxuqi> python Python 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> print(torch.__version__) 0.4.0 >>> print(torch.cuda.is_available()) True >>> >>> >>>
cmd命令行下檢查cuda安裝:
Microsoft Windows [版本 10.0.18363.1139] (c) 2019 Microsoft Corporation。保留所有權(quán)利。 C:\Users\chenxuqi>nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on Fri_Sep__1_21:08:32_Central_Daylight_Time_2017 Cuda compilation tools, release 9.0, V9.0.176 C:\Users\chenxuqi> C:\Users\chenxuqi>
執(zhí)行使用GPU的代碼:
import time import torch ################################################## for i in range(1,10): start = time.time() a = torch.FloatTensor(i*100,1000,1000) a = a.cuda() #a = a a = torch.matmul(a,a) end = time.time() - start print(end)
執(zhí)行結(jié)果:
注意,這里顯存太小,溢出了...但是安裝是成功的...
Windows PowerShell 嘗試新的跨平臺 PowerShell https://aka.ms/pscore6 PS C:\Users\chenxuqi\Desktop\新建文件夾> & 'D:\Anaconda3\envs\ssd\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50571' '--' 'c:\Users\chenxuqi\Desktop\新建文件夾\testGPU.py' 3.6260359287261963 0.6305170059204102 0.9055967330932617 1.3199987411499023 1.5979139804840088 2.0483360290527344 THCudaCheck FAIL file=c:\programdata\miniconda3\conda-bld\pytorch_1524549877902\work\aten\src\thc\generic/THCStorage.cu line=58 error=2 : out of memory Traceback (most recent call last): File "c:\Users\chenxuqi\Desktop\新建文件夾\testGPU.py", line 10, in <module> a = torch.matmul(a,a) RuntimeError: cuda runtime error (2) : out of memory at c:\programdata\miniconda3\conda-bld\pytorch_1524549877902\work\aten\src\thc\generic/THCStorage.cu:58 PS C:\Users\chenxuqi\Desktop\新建文件夾> conda activate ssd PS C:\Users\chenxuqi\Desktop\新建文件夾>
補充:pytorch離線安裝,驗證gpu版安裝成功
使用conda 命令在線安裝pytorch會下載中斷,添加pip清華大學鏡像源https://pypi.tuna.tsinghua.edu.cn/simple/中下好torch,安裝包,然后使用pip命令
pip install "下在的安裝包的路徑"
例如:
pip install "C:\Users\28614\Desktop\pytorch-nightly-cpu-1.0.0.dev20181222-py3.7_cpu_0.tar.bz2"
安裝gpu版,需要安裝cuda,和cudnn。
驗證gpu版是否安裝成功
import torch print(torch.cuda.is_available())
返回True,則安裝成功
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
用Python按時間分割txt文件中的數(shù)據(jù)方法步驟
這篇文章主要給大家介紹了如何用Python按時間分割txt文件中的數(shù)據(jù)的方法步驟,文中通過代碼示例給大家講解的非常詳細,對大家學習Python處理txt文件有一定的幫助,需要的朋友可以參考下2023-12-12
python strip() 函數(shù)和 split() 函數(shù)的詳解及實例
這篇文章主要介紹了 python strip() 函數(shù)和 split() 函數(shù)的詳解及實例的相關(guān)資料,需要的朋友可以參考下2017-02-02
使用Keras中的ImageDataGenerator進行批次讀圖方式
這篇文章主要介紹了使用Keras中的ImageDataGenerator進行批次讀圖方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
2020-06-06 
