Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install PyTorch 1.7 with CUDA 10.1 on MacOS High Sierra 10.13.6 + GTX 1060 6GB

Install PyTorch 1.7 with CUDA 10.1 on MacOS High Sierra 10.13.6 + GTX 1060 6GB

Install web driver for NVIDIA

  1. install webdriver.sh
brew tap vulgo/repo
brew install webdriver.sh
  1. install lastest driver
webdriver

installed version 387.10.10.10.40.133

source

Install CUDA

  1. install cuda via brew:
brew tap homebrew/cask-drivers
brew cask install nvidia-cuda
  1. add the following to your file ~/.bash_profile:
export PATH=/Developer/NVIDIA/CUDA-9.0/bin${PATH:+:${PATH}}
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-9.0/lib${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}
  1. verify installation
nvcc --version

installed version 418.105

source

Install cuDNN

  1. download cuDNN v7.6.5 (November 5th, 2019), for CUDA 10.1
  2. untar tar -xzvf cudnn-10.1-osx-x64-v7.6.5.32.tgz
  3. copy the files into the CUDA Toolkit directory, and change the file permissions
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib/libcudnn* /usr/local/cuda/lib
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

installed version 7.6.5

source

Build PyTorch from source

  1. install anaconda
  2. remove previous versions of pythorch
conda remove pytorch torchvision -y
pip uninstall torch -y
pip uninstall torch -y  # yes twice
  1. install dependencies
conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests
  1. get pytorch source
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
  1. install pytorch
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
MACOSX_DEPLOYMENT_TARGET=10.13 CC=clang CXX=clang++ python setup.py install

error when linking libtorch_cuda.dylib on macOS 10.13.6 fix

  1. build torchvision from source
git clone --recursive https://github.com/pytorch/vision
cd vision
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
MACOSX_DEPLOYMENT_TARGET=10.13 CC=clang CXX=clang++ python setup.py install
  1. verify installation
import torch
print(torch.__version__)
import torch
assert torch.cuda.is_available()
assert torch.randn(20).cuda().is_cuda
import torch
assert torch.backends.cudnn.enabled

installed version 1.7.0a0+eeb43ff

@cheikhdjennel

This comment has been minimized.

Copy link

@cheikhdjennel cheikhdjennel commented Jan 17, 2021

we change CUDA-9.0 with 10.1 right ?

@brokeyourbike

This comment has been minimized.

Copy link
Owner Author

@brokeyourbike brokeyourbike commented Jan 18, 2021

we change CUDA-9.0 with 10.1 right ?

Yes, I think there is typo in the document. I have used CUDA 10.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment