好久没有更新pytorch,这次更新做个笔记
1.安装CUDA
https://developer.nvidia.com/cuda-toolkit-archive
设置环境变量后输入nvcc -V
C:UsersWQBin>nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Fri_Feb__8_19:08:26_Pacific_Standard_Time_2019 Cuda compilation tools, release 10.1, V10.1.105
2.安装pytorch
- PyTorch on Windows only supports Python 3.x
2.1解决慢到无法装
的问题
最有效方法是添加镜像源,常见的清华或中科大。先查看是否已经安装相关镜像源,windows系统在cmd
窗口中执行命令:
conda config --show
使用【conda config --add channels 】添加清华数据源
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
安装:
conda install pytorch torchvision cudatoolkit=10.1
测试pytorch
>>> import torch >>> torch.cuda.is_available() True
如果是false原因可能是:
- CUDA的版本与cudatoolkit=10.1不匹配
- 需要新版本的驱动安装--https://www.nvidia.cn/Download/index.aspx?lang=cn
>>> from __future__ import print_function >>> import torch >>> x = torch.rand(5, 3) >>> print(x) tensor([[0.1863, 0.4498, 0.0765], [0.6291, 0.2132, 0.5534], [0.8320, 0.9772, 0.7931], [0.8859, 0.9128, 0.0536], [0.5445, 0.5895, 0.1608]]) >>>
其他注意事项:
1.要求电脑的显卡驱动大于396.26。输入 nvidia-smi
,查看自己的 Driver Version。
(deeplearning) C:UsersWQBin>nvidia-smi Sat Apr 11 11:45:39 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 445.75 Driver Version: 445.75 CUDA Version: 11.0 | |-------------------------------+----------------------+----------------------+ | GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1060 WDDM | 00000000:01:00.0 Off | N/A | | N/A 45C P8 6W / N/A | 92MiB / 6144MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
完美。。开始搞事情