Last active
November 12, 2024 09:08
-
-
Save rfeinman/5a7e2d65fd31b0ad389358c270456fe8 to your computer and use it in GitHub Desktop.
Build PyTorch with MKL & OpenMP threading on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# This install used the following development environment: | |
# - We have installed xcode command line tools | |
# - We have installed cmake via homebrew (my version is 3.20.2) | |
# - We have created a fresh conda environment "pytorch-dev" and installed | |
# python=3.8 and all of the packages from pytorch/README.md except cmake | |
# (including the torch.distributed deps) | |
# - We have copied the relevant OpenMP header files into a fresh directory at ~/openmp | |
# - We have cloned the pytorch github repo to ~/pytorch | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# conda environment where we have installed dependencies | |
conda activate pytorch-dev | |
# root directory of our conda environment | |
CONDA_ENV=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} | |
# directory where we have placed the intel openmp header files | |
OMP_INCLUDE=$HOME/openmp/include | |
# these two exports are necessary | |
export CMAKE_PREFIX_PATH=$CONDA_ENV | |
export CMAKE_INCLUDE_PATH=$OMP_INCLUDE | |
# not 100% sure these two exports are necessary, but worked for me | |
export CMAKE_SHARED_LINKER_FLAGS="$CONDA_ENV/lib/libiomp5.dylib -Wl,-rpath,$CONDA_ENV/lib" | |
export CMAKE_EXE_LINKER_FLAGS="$CONDA_ENV/lib/libiomp5.dylib -Wl,-rpath,$CONDA_ENV/lib" | |
export MACOSX_DEPLOYMENT_TARGET=11.0 | |
export CC=clang | |
export CXX=clang++ | |
export MAX_JOBS=9 | |
export BLAS=MKL | |
export USE_OPENMP=1 | |
export MKL_THREADING=OMP | |
export ATEN_THREADING=OMP | |
export MKLDNN_CPU_RUNTIME=OMP | |
# directory where we have cloned pytorch | |
cd $HOME/pytorch | |
python setup.py install |
Hi @paula3 - after a quick look I'm not sure about your issue. I wrote this gist a year ago and some things have changed in pytorch (and OS X) since then so I would have to dig back through. I may have some time to do so in the next few weeks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I have this problem when I run your code:
Do you know how to solve it? Thanks!
I'm running the code in MAC OS with anaconda