OpenNMT / CTranslate2

Fast inference engine for Transformer models

Home Page:https://opennmt.net/CTranslate2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When building from source missing C++ libraries

anterart opened this issue · comments

Hello!

I’m trying to build CTranslate2 from source after customising the code in python/translator.cc file.
I’m using the guide here:https://opennmt.net/CTranslate2/installation.html#install-from-sources
When I install the python package on the same computer where I built it, it works. But when I install the python package on a different computer from my private artifactory, it doesn’t work - when I’m running the following code:
from ctranslate2 import Translator
I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/envs/arty_env/lib/python3.9/site-packages/ctranslate2/__init__.py", line 21, in <module>
    from ctranslate2._ext import (
ImportError: libctranslate2.so.4: cannot open shared object file: No such file or directory

The C++ libraries are not located in the .whl file created by the command: python setup.py bdist_wheel, so that is the problem...

Additional information:

  1. The version that I'm building is 4.1.0
  2. I'm using a conda environment
  3. my cmake command:
    cmake -DCMAKE_CXX_FLAGS="-msse4.1" -DBUILD_CLI=OFF -DWITH_DNNL=ON -DOPENMP_RUNTIME=COMP -DWITH_CUDA=ON -DWITH_CUDNN=ON -DCUDA_DYNAMIC_LOADING=ON -DCUDA_NVCC_FLAGS="-Xfatbin=-compress-all" -DCUDA_ARCH_LIST="Common" .. - I changed it a bit in an effort to solve the problem, so there are flags I can drop...
  4. I did pay attention to the Attention section in the installation guide and tweaked the CTRANSLATE2_ROOT to the installation location: /usr/local . Also I did change the LD_LIBRARY_PATH variable to: /usr/local/cuda/lib64:/usr/local/nccl2/lib:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/lib

Any assistance would be appreciated 🙂

I think you have to repair the package .whl. Try to install auditwheel and use this command:

auditwheel repair [package].whl

@minhthuc2502 thank you for your reply!
I kept trying to make it build correctly.
I went to another ubuntu instance and built from source everything again using Qubitium's instructions from this issue:
#1250
, without using conda virtual environment, and compiling using python=3.9.13.
I used the following cmake command:

cmake -DCMAKE_CXX_FLAGS="-msse4.1" -DBUILD_CLI=OFF -DWITH_DNNL=ON -DOPENMP_RUNTIME=COMP -DWITH_CUDA=ON -DWITH_CUDNN=ON -DCUDA_DYNAMIC_LOADING=ON -DCMAKE_INSTALL_PREFIX=/home/ubuntu/my_ctranslate2 ..

This time the resulting package was bigger, it contained the following files:

ctranslate2-4.1.0+custom
├── ctranslate2
│   ├── __init__.py
│   ├── _ext.cpython-39-x86_64-linux-gnu.so
│   ├── converters
│   │   ├── __init__.py
│   │   ├── converter.py
│   │   ├── fairseq.py
│   │   ├── marian.py
│   │   ├── openai_gpt2.py
│   │   ├── opennmt_py.py
│   │   ├── opennmt_tf.py
│   │   ├── opus_mt.py
│   │   ├── transformers.py
│   │   └── utils.py
│   ├── extensions.py
│   ├── logging.py
│   ├── models
│   │   └── __init__.py
│   ├── specs
│   │   ├── __init__.py
│   │   ├── attention_spec.py
│   │   ├── common_spec.py
│   │   ├── model_spec.py
│   │   ├── transformer_spec.py
│   │   ├── wav2vec2_spec.py
│   │   └── whisper_spec.py
│   └── version.py
└── ctranslate2-4.1.0+custom.dist-info
    ├── METADATA
    ├── RECORD
    ├── WHEEL
    ├── entry_points.txt
    └── top_level.txt

and the _ext.cpython-39-x86_64-linux-gnu.so file was bigger then last time (also the python setup.py bdist_wheel command produces much more unput).
However the libctranslate2.so.4.1.0 file is not found.
I installed the resulting package and it didn't work:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Translator' from 'ctranslate2' (/home/ubuntu/CTranslate2/python/ctranslate2/__init__.py)

@minhthuc2502 I tried to run auditwheel repair [package].whl on the resulting .whl and I got the following error:

INFO:auditwheel.main_repair:Repairing ctranslate2-4.1.0+custom-cp39-cp39-linux_x86_64.whl
usage: auditwheel [-h] [-V] [-v] command ...
auditwheel: error: cannot repair "ctranslate2-4.1.0+custom-cp39-cp39-linux_x86_64.whl" to "manylinux_2_5_x86_64" ABI because of the presence of too-recent versioned symbols. You'll need to compile the wheel on an older toolchain.

_ext.cpython-39-x86_64-linux-gnu.so is included in wheel package because it is created as an interface between c++ and python while the libctranslate2.so is the native lib c++ that you built with make. When you call python setup.py bdist_wheel, it will only create wheel package but does not include the native lib c++. After this step, normally you can only test the python package on the current machine with LD_LIBRARY_PATH which points to the install dir.

The reason that you can't repair the wheel because you do not create the wheel package on a standard distro like manylinux. If you want to repair a wheel package which could run in many distro linux different, you have to create the wheel package in a docker manylinux2014.

@minhthuc2502 you wrote information that is new to me, thanks 🙂
So if I build the ctranslate2 package in a manylinux2014 docker, it will contain the libctranslate2.so and work on other machines as well?

Yes. after repairing with auditwheel

Thank you!
I built it successfully with manylinux2014 and using code from here: https://github.com/OpenNMT/CTranslate2/blob/master/python/tools/prepare_build_environment_linux.sh