Conda build with pre-cxx11 ABI
yaoyic opened this issue · 5 comments
When installing the openmm-torch plugin with the conda-forge packages, I met with the issue of ABI incompatibility:
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import openmmtorch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "${CONDA_PREFIX}/lib/python3.9/site-packages/openmmtorch.py", line 15, in <module>
import _openmmtorch
ImportError: ${CONDA_PREFIX}/lib/python3.9/site-packages/../../libOpenMMTorch.so: undefined symbol: _ZN5torch3jit4loadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3c108optionalINS9_6DeviceEEE
For the tested setup pytorch v1.12, I checked the wheels from two sources: the official pip wheel and pytorch conda channel, inside which the pre-cxx11 name mangling was used:
$ readelf -sW libtorch_python.so | grep torch3jit4load
3501: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZN5torch3jit4loadERKSsN3c108optionalINS3_6DeviceEEE
33881: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZN5torch3jit4loadERKSsN3c108optionalINS3_6DeviceEEE
I don't know how you guys usually install pytorch, but in all my existing conda environments the pytorch uses pre-cxx11 name mangling. (Even though on pytorch's official website, libtorch
is offered in both ABI forms, the python wheels seem to have only pre-cxx11 symbol names.) For the convenience of non-power users, I would suggest either of the following changes:
- In
README.md
, show how the user should install a compatible version of pytorch, (for example, a recipe for setting up a new conda environment from scratch that works out-of-the-box). - Ship wheels/conda packages that is built against pre-cxx11 libtorch ABIs
You need to install pytorch from conda-forge. It's designed to be a compatible ecosystem where every package is built in the same way.
Also got this error when using PyTorch 1.12.1 installed from Conda. Is there any workaround for this?
Can you post the output of conda list
? If everything comes from conda-forge, they should all use the same ABI.
What later worked for me was to install pytorch (presumably with CUDA support) from conda-forge
instead of following the recommended ways written on pytorch's website, to which these released wheels were built against. Otherwise you can also build it from source locally (which has not been easy for me)
This is my previous conda list (clamped to show only relevant packages ):
openmm 8.0.0 py39h7d85326_1 conda-forge
openmm-torch 1.0 cuda112py39h440defe_1 conda-forge
openmmtools 0.23.0 pyhd8ed1ab_0 conda-forge
python 3.9.16 h2782a2a_0_cpython conda-forge
python_abi 3.9 3_cp39 conda-forge
pytorch 1.12.1 py3.9_cuda11.6_cudnn8.3.2_0 pytorch
torchaudio 0.12.1 py39_cu116 pytorch
torchvision 0.13.1 py39_cu116 pytorch
I followed @yaoyic 's suggestion and installed pytorch from channel -c conda-forge
instead of channel -c pytorch
, and now everything works. I think the reason is exactly what @yaoyic has said, the instruction on Pytorch's website lead to packages that are actually not from the conda-forge
.