Skip to content

Instantly share code, notes, and snippets.

@shengchiliu
Last active October 1, 2018 22:38
Show Gist options
  • Save shengchiliu/700220df37d218e9037e74f208afc916 to your computer and use it in GitHub Desktop.
Save shengchiliu/700220df37d218e9037e74f208afc916 to your computer and use it in GitHub Desktop.
Install PyTorch, Caffe2 and Onnx in Ubuntu and MacOS

Install PyTorch, Caffe2 and Onnx in Ubuntu and MacOS

Create Conda Environment

Ubuntu

$ conda create -n <YOURENVNAME> python=3.6 llvm llvmdev && source activate <YOURENVNAME>
$ pip install wmd

MacOS

$ conda create -n <YOURENVNAME> python=3.6 clangxx_osx-64 clang_osx-64 && source activate <YOURENVNAME>
$ pip install wmd

Install basic dependencies

Ubuntu

$ export CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" # [anaconda root directory]

Install basic dependencies

$ conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing
$ conda install -c mingfeima mkldnn
$ conda install -c anaconda cython

Add LAPACK support for the GPU

$ conda install -c pytorch magma-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version

MacOS

$ export CMAKE_PREFIX_PATH=[anaconda root directory]
$ conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing
$ conda install -c anaconda cython

Get the PyTorch source

$ git clone --recursive https://github.com/pytorch/pytorch
$ cd pytorch

Back to Previous Version of PyTorch (v0.4.0)

$ git checkout v0.4.0
$ git submodule update --init

Install PyTorch

Linux

$ FULL_CAFFE2=1 python setup.py install
$ pip install torchvision
$ pip install future

MacOS

$ MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ FULL_CAFFE2=1 python setup.py install
$ pip install torchvision
$ pip install future

Install onnx from Source

$ PROTOBUF_INCDIR=/path/to/anaconda/envs/caffe2 pip install third_party/onnx

Another Method

Install PyTorch 0.4.0 by pip

$ pip install /path/to/whl/file

Install Caffe2 by conda

Ref.

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