-
Notifications
You must be signed in to change notification settings - Fork 27.4k
PyTorch wheel's own OpenMP library clashing with system-wide OpenMP library at runtime #44282
Description
🐛 Bug
On MacOS Catalina with PyTorch installed with pip, when the same Python script imports both PyTorch and another package using also OpenMP, the Python interpreter crashes with the following message:
OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
The issue is that PyTorch provides its own version of OpenMP on MacOS in <path-to-python-libs>/site-packages/torch/.dylibs/libiomp5.dylib whereas all python packages imported in a same python script should ideally use the same OpenMP library (typically the system-wide one, e.g. /usr/local/lib/libomp.dylib). I think it is not portable nor maintainable that all OpenMP-based python packages import their own OpenMP libraries.
To Reproduce
Steps to reproduce the behavior:
pip install torch- Install another OpenMP-based python module, e.g. xgboost
- Import both modules in the same python script and run parallel functions from both modules, you'll get the above abort message from the python interpreter
Expected behavior
PyTorch uses the system-wide OpenMP library used by other OpenMP-based python modules. So the user can choose whatever unique OpenMP library she wants to link against the python interpreter.
Environment
Collecting environment information...
PyTorch version: 1.6.0
Is debug build: False
CUDA used to build PyTorch: None
OS: Mac OSX 10.15.1 (x86_64)
GCC version: Could not collect
Clang version: 11.0.3 (clang-1103.0.32.62)
CMake version: version 3.18.2
Python version: 3.7 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Versions of relevant libraries:
[pip3] numpy==1.19.1
[pip3] torch==1.6.0
[conda] Could not collect