https://github.com/pytorch/pytorch#from-source

安装依赖

  1. conda install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
  2. # CUDA only: Add LAPACK support for the GPU if needed
  3. conda install -c pytorch magma-cuda110 # or the magma-cuda* that matches your CUDA version from https://anaconda.org/pytorch/repo

获取源码

  1. git clone --recursive https://github.com/pytorch/pytorch
  2. cd pytorch
  3. git checkout v1.8.1
  4. # if you are updating an existing checkout
  5. git submodule sync
  6. git submodule update --init --recursive

安装

  1. export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
  2. DEBUG=1 python setup.py develop

Error

找不到cudnn版本

https://github.com/pytorch/pytorch/issues/41593

  1. -- Caffe2: CUDA detected: 11.2 │······································
  2. -- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc │······································
  3. -- Caffe2: CUDA toolkit directory: /usr/local/cuda │······································
  4. -- Caffe2: Header version is: 11.2 │······································
  5. -- Found cuDNN: v? (include: /usr/local/cuda/include, library: /usr/local/cuda/lib64/libcudnn.so) │······································
  6. CMake Error at cmake/public/cuda.cmake:174 (message): │······································
  7. PyTorch requires cuDNN 7 and above. │······································
  8. Call Stack (most recent call first): │······································
  9. cmake/Dependencies.cmake:1151 (include) │······································
  10. CMakeLists.txt:623 (include)
  1. 首先查看CUDNN的版本
    cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
    

    No space left on device

    https://stackoverflow.com/questions/44270171/torch-installation-failure-no-space-left-on-device

mkdir $HOME/tmp
export TMPDIR=$HOME/tmp