参考链接:
1.win10 pytorch安装(cuda + cudnn、anaconda、pytorch
2.Win10安装CUDA10和cuDNN
3.win10下pytorch-gpu安装以及CUDA详细安装过程
4.TensorFlow-gpu安装(100%成功)
cmd下检查cuda安装:
Microsoft Windows [版本 10.0.18363.1139]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\chenxuqi>nvcc -V
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>
测试代码:
import time
import torch
print(torch.__version__)
print(torch.cuda.is_available())
##################################################
print('----'*10)
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)
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS C:\Users\chenxuqi\Desktop\新建文件夹> & 'D:\Anaconda3\envs\pytorch_1.5.1_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50169' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.5.1+cu101
----------------------------------------
3.116953134536743
0.5529775619506836
PS C:\Users\chenxuqi\Desktop\新建文件夹> conda activate pytorch_1.5.1_cu101
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.5.1_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50184' '--' 'c:\Users\che1.5.1
True
----------------------------------------
3.254598617553711
0.5271706581115723
0.9557905197143555
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50196' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0
True
----------------------------------------
3.835683822631836
0.5949108600616455
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50205' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0+cu101
True
0.9557905197143555
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu102\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50196' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0
True
----------------------------------------
3.835683822631836
0.5949108600616455
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.6.0_cu101\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50205' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.6.0+cu101
True
----------------------------------------
3.68234920501709
0.5653483867645264
0.9160294532775879
PS C:\Users\chenxuqi\Desktop\新建文件夹> cd 'c:\Users\chenxuqi\Desktop\新建文件夹'; & 'D:\Anaconda3\envs\pytorch_1.5.1_cu92\python.exe' 'c:\Users\chenxuqi\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles\lib\python\debugpy\launcher' '50217' '--' 'c:\Users\chenxuqi\Desktop\新建文件夹\testGPU.py'
1.5.1+cu92
True
----------------------------------------
3.1128926277160645
0.5216362476348877
PS C:\Users\chenxuqi\Desktop\新建文件夹>
注意:安装多个不同cuda版本的PyTorch需要更新显卡驱动
如果显卡驱动版本过低则会导致错误如下:
AssertionError:
The NVIDIA driver on your system is too old (found version 9000).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.
因此需要去更新显卡驱动,笔者笔记本上显卡驱动版本是456.71,其发布日期是10/20/2020.