PyTorch:安装和配置
安装pip安装pip3 install torch torchvisionmacos还需要安装brew install libomp否则出错:ImportError: dlopen(/...torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib...
安装
在官网选择即可[stable],老版本[previous-versions]
pytorch查看版本号
torch.__version__
pip自动选择安装
一般装了cuda就安装gpu版本的torch了
pip3 install torch torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
安装cpu版本torch
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install torch==2.0.1+cpu
Note: ERROR: Could not find a version that satisfies the requirement torch==2.0.1+cpu
如果找不到可以通过:
pip install torch==2.0.1+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html
还安装不了可以从[https://download.pytorch.org/whl/cpu/torch_stable.html]里面下载[torch-2.0.1%2Bcpu-cp310-cp310-linux_x86_64.whl]
或者从[https://download.pytorch.org/whl/torch/]下载whl文件后再安装
pip install torch-2.0.1+cpu-cp310-cp310-linux_x86_64.whl
jupter上可能需要重启terminal,环境才会重新加载
不过貌似装了cuda的gpu环境,装cpu版本的就会出错,也不是重装依赖能解决的:
ImportError: cannot import name '_get_cpp_backtrace' from 'torch._C'
安装gpu版本torch
先安装cuda
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
[CUDA Toolkit 12.2 Update 2 Downloads | NVIDIA Developer]
Note: macOS High Sierra 10.13.6之后NVIDIA不在对显卡驱动进行支持:[MacOS 10.13.6安装cuda+cudann+pytorch的gpu版本]
再安装torch
pip3 install torch torchvision torchaudio
pip install torch==2.0.1+cu117
linux上安装torch出错
ERROR: torch-2.0.1+cpu-cp310-cp310-linux_x86_64.whl is not a supported wheel on this platform.
首页uname -p查看是否是x86_64平台,再看是不是py版本没对上。
macos还需要安装
brew install libomp
否则出错:ImportError: dlopen(/...torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: .../torch/lib/libshm.dylib Reason: image not found
安装固定cuda版本对应的pytorch
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
其它cuda版本对应的pytorch版本查询[https://download.pytorch.org/whl/torch_stable.html]
如cuda=9.0版本时,支持的最高pytorch版本可能就是1.1.0了:cu90/torch-1.1.0-cp36-cp36m-linux_x86_64.whl。
[INSTALL PYTORCH][INSTALLING PREVIOUS VERSIONS OF PYTORCH]
显卡驱动版本查询
显卡驱动版本-cuda版本-pytorch版本需要一一对应,否则torch.cuda.is_available()=False。
$nvidia-smi #Driver Version: 384.81
Mon Jan 11 14:51:48 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.81 Driver Version: 384.81 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla P100-PCIE... On | 00000000:04:00.0 Off | 0 |
| N/A 33C P0 25W / 250W | 0MiB / 16276MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 Tesla P100-PCIE... On | 00000000:81:00.0 Off | 0 |
| N/A 28C P0 25W / 250W | 0MiB / 16276MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
cuda(toolkit)版本查询
nvcc --version或nvcc -V,如果 nvcc 没有安装,那么用
$cat /usr/local/cuda/version.txt
CUDA Version 9.0.176
查看pytorch对应cuda的版本
import torch
print(torch.version.cuda)
查看 cuDNN 版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
如果没有,那么可能没有安装 cuDNN。
Note: NVIDIA cuDNN是用于深度神经网络的GPU加速库。
驱动版本和cuda(toolkit)版本对应关系
CUDA Toolkit | Linux x86_64 Driver Version | Windows x86_64 Driver Version |
---|---|---|
CUDA 11.2.0 GA | >=460.27.04 | >=460.89 |
CUDA 11.1.1 Update 1 | >=455.32 | >=456.81 |
CUDA 11.1 GA | >=455.23 | >=456.38 |
CUDA 11.0.3 Update 1 | >= 450.51.06 | >= 451.82 |
CUDA 11.0.2 GA | >= 450.51.05 | >= 451.48 |
CUDA 11.0.1 RC | >= 450.36.06 | >= 451.22 |
CUDA 10.2.89 | >= 440.33 | >= 441.22 |
CUDA 10.1 (10.1.105 general release, and updates) | >= 418.39 | >= 418.96 |
CUDA 10.0.130 | >= 410.48 | >= 411.31 |
CUDA 9.2 (9.2.148 Update 1) | >= 396.37 | >= 398.26 |
CUDA 9.2 (9.2.88) | >= 396.26 | >= 397.44 |
CUDA 9.1 (9.1.85) | >= 390.46 | >= 391.29 |
CUDA 9.0 (9.0.76) | >= 384.81 | >= 385.54 |
CUDA 8.0 (8.0.61 GA2) | >= 375.26 | >= 376.51 |
CUDA 8.0 (8.0.44) | >= 367.48 | >= 369.30 |
CUDA 7.5 (7.5.16) | >= 352.31 | >= 353.66 |
CUDA 7.0 (7.0.28) | >= 346.46 | >= 347.62 |
[官方对照表][nvidia显卡,驱动以及cuda版本对应查询]
[pytorch版本,cuda版本,系统cuda版本查询和对应关系]
from: -柚子皮-
ref:
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)