Skip to content

Instantly share code, notes, and snippets.

@brokeyourbike
Last active November 14, 2023 09:51
Show Gist options
  • Save brokeyourbike/def7a3313c1e4fdf1334b5c4f0e239f3 to your computer and use it in GitHub Desktop.
Save brokeyourbike/def7a3313c1e4fdf1334b5c4f0e239f3 to your computer and use it in GitHub Desktop.
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

@geoffwoollard
Copy link

I added #include <math.h> in
/Users/gw/repos/pytorch/aten/src/ATen/native/ReduceOps.cpp
/Users/gw/repos/pytorch/aten/src/ATen/native/cpu/MaxPoolKernel.cpp
/Users/gw/repos/pytorch/aten/src/ATen/native/cpu/MaxPooling.cpp
/Users/gw/repos/pytorch/aten/src/ATen/native/cpu/AdaptiveMaxPoolKernel.cpp

But I'm still getting the same error messages:

/Users/gw/repos/pytorch/aten/src/ATen/native/ReduceOps.cpp:663:10: error: no matching function for call to 'isnan'

@geoffwoollard
Copy link

@brokeyourbike, what versions of the dependencies and what version of Python did you use? Can you capture your exact environment in pip or conda? Can you share the result of conda list --explicit?

@brokeyourbike
Copy link
Author

Hi @geoffwoollard I have performed this setup more then a year ago and now I don't have it installed anymore. A lot of things chnanged in my setup over the years. Unfortunately I cannot share the result of conda list --explicit

@geoffwoollard
Copy link

Do you still have the pytorch/build directory? It has informative log files like pytorch/build/CMakeFiles/CMakeError.log and pytorch/build/CMakeFiles/CMakeOutput.log

@geoffwoollard
Copy link

Also, I'm getting different errors depending on what PyTorch version (commit) I try to install, and what version of Python (3.7, ..., 3.10) I use.

@brokeyourbike
Copy link
Author

@geoffwoollard nah, sorry, don't have PyTorch installed right now, latest macOS versions don't support Nvidia GPU

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