Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install Ctranslate2 without Docker #194

Closed
anderleich opened this issue Jun 2, 2020 · 24 comments
Closed

How to install Ctranslate2 without Docker #194

anderleich opened this issue Jun 2, 2020 · 24 comments
Labels
question Further information is requested

Comments

@anderleich
Copy link

Hi,
I'd like to install the Ctranslate2 module without using a Docker. Is it possible?
Are there any scripts for this? I've tried generating a shell script from the dockerfile but it gives me some errors.
Thanks

@guillaumekln guillaumekln added the question Further information is requested label Jun 2, 2020
@guillaumekln
Copy link
Collaborator

Hi,

If you plan to use the Python API, you can simply run pip install ctranslate2 and get access to CPU translation on Linux.

For other use cases, the Dockerfiles specify how to install the dependencies and how to compile the project. A basic CPU build is also described in the README.

What errors did you get?

@anderleich
Copy link
Author

These are the logs:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc: In static member function ‘static void ctranslate2::primitives::gemm(const In*, const In*, bool, bool, bool, bool, ctranslate2::dim_t, ctranslate2::dim_t, ctranslate2::dim_t, float, float, Out*, const Out*) [with In = signed char; Out = int; ctranslate2::Device D = (ctranslate2::Device)0; ctranslate2::dim_t = long int]’:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:836:62: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
c, ldc, a_shift_compensation);
^
In file included from /opt/intel/mkl/include/mkl.h:31:0,
from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:
/opt/intel/mkl/include/mkl_cblas.h:834:6: note: initializing argument 2 of ‘void cblas_gemm_s8u8s32_compute(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, CBLAS_OFFSET, long long int, long long int, long long int, float, const void*, long long int, char, const void*, long long int, char, float, int*, long long int, const int*)’
void cblas_gemm_s8u8s32_compute (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:836:62: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
c, ldc, a_shift_compensation);
^

@anderleich
Copy link
Author

I'm interested in the GPU part not CPU. Therefore, doing pip install is not an option I considered.
Thanks

@guillaumekln
Copy link
Collaborator

guillaumekln commented Jun 2, 2020

What is your Intel MKL version?

@anderleich
Copy link
Author

anderleich commented Jun 2, 2020

I'd like to have the CPU option too. I case GPU is not available.

This is what I do:

MKL_VERSION=2020
MKL_UPDATE=0
MKL_BUILD=088
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-
.PUB
echo "deb https://apt.repos.intel.com/mkl all main" > /etc/apt/sources.list.d/intel-mkl.list
apt-get update
apt-get install -y --no-install-recommends \
intel-mkl-64bit-$MKL_VERSION.$MKL_UPDATE-$MKL_BUILD
apt-get clean
rm -rf /var/lib/apt/lists/*

@guillaumekln
Copy link
Collaborator

The lines referenced in the error log do not seem to match the file /opt/intel/mkl/include/mkl_cblas.h included in Intel MKL 2020.0-088. So it seems you are not using the correct Intel MKL version. Can you verify that?

If you don't need CPU execution at all, you can also disable Intel MKL using these flags during CMake configuration: -DWITH_MKL=OFF -DOPENMP_RUNTIME=NONE

@anderleich
Copy link
Author

anderleich commented Jun 2, 2020

I'm sorry but I'm afraid I can't go any further configuring MKL with the right version
CUDA VERSION 10.1
This is how my script looks like so far:

TENSORRT_MAJOR_VERSION=6
TENSORRT_VERSION=${TENSORRT_MAJOR_VERSION}.0.1

REPOSITORY_DIR=$PWD
DEPENDENCIES_PATH=/opt/ctranslate_dependencies
mkdir -p /opt/ctranslate_dependencies || exit 1
                                                                                                                                        
apt-get update && \                                                                                                                           
    apt-get install -y --no-install-recommends \                                                                                              
        apt-transport-https \                                                                                                                 
        build-essential \                                                                                                                     
        ca-certificates \                                                                                                                     
        python3-dev \                                                                                                                         
        gnupg2 \                                                                                                                              
        libnvinfer${TENSORRT_MAJOR_VERSION}=${TENSORRT_VERSION}-1+cuda10.0 \                                                                  
        libnvinfer-dev=${TENSORRT_VERSION}-1+cuda10.0 \                                                                                       
        wget && \                                                                                                                             
    apt-get clean && \                                                                                                                        
    rm -rf /var/lib/apt/lists/*                                                                                                               

cd $DEPENDENCIES_PATH                                                                                                                                         
wget https://cmake.org/files/v3.12/cmake-3.12.2-Linux-x86_64.tar.gz                                                                           
tar xf cmake-3.12.2-Linux-x86_64.tar.gz                                                                                                       
rm cmake-3.12.2-Linux-x86_64.tar.gz           
                                                                                                
export PATH=$PATH:$DEPENDENCIES_PATH/cmake-3.12.2-Linux-x86_64/bin

MKL_VERSION=2020
MKL_UPDATE=0
MKL_BUILD=088                                                                                                                                        
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB                                                        
apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-*.PUB 
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-*.PUB                                                                                                        
echo "deb https://apt.repos.intel.com/mkl all main" > /etc/apt/sources.list.d/intel-mkl.list                                                  
apt-get update                                                                                                                                
apt-get install -y --no-install-recommends \                                                                                                  
        intel-mkl-64bit-$MKL_VERSION.$MKL_UPDATE-$MKL_BUILD                                                                                   
apt-get clean                                                                                                                                 
rm -rf /var/lib/apt/lists/*                                                                                                                   

mkdir -p $DEPENDENCIES_PATH/ctranslate2-dev || exit 1
cd $DEPENDENCIES_PATH/ctranslate2-dev

cp -r $REPOSITORY_DIR/third_party third_party
cp -r $REPOSITORY_DIR/cli cli
cp -r $REPOSITORY_DIR/include include
cp -r $REPOSITORY_DIR/src src
cp $REPOSITORY_DIR/CMakeLists.txt .

export CXX_FLAGS=${CXX_FLAGS}
export CUDA_NVCC_FLAGS=${CUDA_NVCC_FLAGS:-"-Xfatbin -compress-all"}
export CUDA_ARCH_LIST=${CUDA_ARCH_LIST:-"Common"}
export CTRANSLATE2_ROOT=$DEPENDENCIES_DIR/ctranslate2

mkdir -p build
cd build
cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.1 \
      -DCMAKE_INSTALL_PREFIX=${CTRANSLATE2_ROOT} \
      -DWITH_CUDA=ON \
      -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" \
      -DCUDA_NVCC_FLAGS="${CUDA_NVCC_FLAGS}" -DCUDA_ARCH_LIST="${CUDA_ARCH_LIST}" ..
VERBOSE=1 make -j4
make install
`

@guillaumekln
Copy link
Collaborator

Can you add set -e at the top of the script and run it again? It will stop on the first error.

@anderleich
Copy link
Author

This is the log

[ 78%] Building CXX object CMakeFiles/ctranslate2.dir/src/sampling.cc.o
/usr/bin/c++  -DMKL_ILP64 -DWITH_CUDA -DWITH_MKL -DWITH_TENSORRT -Dctranslate2_EXPORTS -I/usr/local/cuda-10.1/include -I/opt/ctranslate_dependencies/ctranslate2-dev/include -I/opt/intel/mkl/include  -Wall -Wextra -ffast-math -m64 -isystem /usr/include/x86_64-linux-gnu -O3 -DNDEBUG -fPIC   -fopenmp -std=gnu++11 -o CMakeFiles/ctranslate2.dir/src/sampling.cc.o -c /opt/ctranslate_dependencies/ctranslate2-dev/src/sampling.cc
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc: In static member function ‘static void ctranslate2::primitives<D>::max(const T*, const T*, T*, ctranslate2::dim_t) [with T = float; ctranslate2::Device D = (ctranslate2::Device)0; ctranslate2::dim_t = long int]’:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:253:25: error: invalid conversion from ‘const float*’ to ‘float*’ [-fpermissive]
     vsFmax(size, a, b, c);
                         ^
In file included from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:0:
/opt/intel/mkl/include/mkl_vml_functions.h:1441:16: note:   initializing argument 3 of ‘void vsFmax(long long int, const float*, float*, float*)’
 _Mkl_Api(void, vsFmax, (const MKL_INT n, const float  a[], float  r1[], float  r2[]))
                ^
/opt/intel/mkl/include/mkl.h:23:47: note: in definition of macro ‘_Mkl_Api’
 #define _Mkl_Api(rtype,name,arg) extern rtype name    arg;
                                               ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc: In static member function ‘static void ctranslate2::primitives<D>::min(const T*, const T*, T*, ctranslate2::dim_t) [with T = float; ctranslate2::Device D = (ctranslate2::Device)0; ctranslate2::dim_t = long int]’:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:275:25: error: invalid conversion from ‘const float*’ to ‘float*’ [-fpermissive]
     vsFmin(size, a, b, c);
                         ^
In file included from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:0:
/opt/intel/mkl/include/mkl_vml_functions.h:1456:16: note:   initializing argument 3 of ‘void vsFmin(long long int, const float*, float*, float*)’
 _Mkl_Api(void, vsFmin, (const MKL_INT n, const float  a[], float  r1[], float  r2[]))
                ^
/opt/intel/mkl/include/mkl.h:23:47: note: in definition of macro ‘_Mkl_Api’
 #define _Mkl_Api(rtype,name,arg) extern rtype name    arg;
                                               ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc: In static member function ‘static void ctranslate2::primitives<D>::gemm(const In*, const In*, bool, bool, bool, bool, ctranslate2::dim_t, ctranslate2::dim_t, ctranslate2::dim_t, float, float, Out*, const Out*) [with In = short int; Out = int; ctranslate2::Device D = (ctranslate2::Device)0; ctranslate2::dim_t = long int]’:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:721:47: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
                                    c, ldc, &oc);
                                               ^
In file included from /opt/intel/mkl/include/mkl.h:31:0,
                 from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:
/opt/intel/mkl/include/mkl_cblas.h:842:6: note:   initializing argument 2 of ‘void cblas_gemm_s16s16s32_compute(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, CBLAS_OFFSET, long long int, long long int, long long int, float, const short int*, long long int, short int, const short int*, long long int, short int, float, int*, long long int, const int*)’
 void cblas_gemm_s16s16s32_compute(const  CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
      ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:721:47: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
                                    c, ldc, &oc);
                                               ^
In file included from /opt/intel/mkl/include/mkl.h:31:0,
                 from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:
/opt/intel/mkl/include/mkl_cblas.h:842:6: note:   initializing argument 3 of ‘void cblas_gemm_s16s16s32_compute(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, CBLAS_OFFSET, long long int, long long int, long long int, float, const short int*, long long int, short int, const short int*, long long int, short int, float, int*, long long int, const int*)’
 void cblas_gemm_s16s16s32_compute(const  CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
      ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc: In static member function ‘static void ctranslate2::primitives<D>::gemm(const In*, const In*, bool, bool, bool, bool, ctranslate2::dim_t, ctranslate2::dim_t, ctranslate2::dim_t, float, float, Out*, const Out*) [with In = signed char; Out = int; ctranslate2::Device D = (ctranslate2::Device)0; ctranslate2::dim_t = long int]’:
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:836:62: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
                                  c, ldc, a_shift_compensation);
                                                              ^
In file included from /opt/intel/mkl/include/mkl.h:31:0,
                 from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:
/opt/intel/mkl/include/mkl_cblas.h:834:6: note:   initializing argument 2 of ‘void cblas_gemm_s8u8s32_compute(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, CBLAS_OFFSET, long long int, long long int, long long int, float, const void*, long long int, char, const void*, long long int, char, float, int*, long long int, const int*)’
 void cblas_gemm_s8u8s32_compute  (const  CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
      ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:836:62: error: invalid conversion from ‘long long int’ to ‘CBLAS_TRANSPOSE’ [-fpermissive]
                                  c, ldc, a_shift_compensation);
                                                              ^
In file included from /opt/intel/mkl/include/mkl.h:31:0,
                 from /opt/ctranslate_dependencies/ctranslate2-dev/src/primitives/cpu.cc:14:
/opt/intel/mkl/include/mkl_cblas.h:834:6: note:   initializing argument 3 of ‘void cblas_gemm_s8u8s32_compute(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, CBLAS_OFFSET, long long int, long long int, long long int, float, const void*, long long int, char, const void*, long long int, char, float, int*, long long int, const int*)’
 void cblas_gemm_s8u8s32_compute  (const  CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
      ^
CMakeFiles/ctranslate2.dir/build.make:553: recipe for target 'CMakeFiles/ctranslate2.dir/src/primitives/cpu.cc.o' failed
make[2]: *** [CMakeFiles/ctranslate2.dir/src/primitives/cpu.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/opt/ctranslate_dependencies/ctranslate2-dev/src/profiler.cc:117:30: warning: unused parameter ‘device’ [-Wunused-parameter]
   void init_profiling(Device device, size_t num_threads) {
                              ^
/opt/ctranslate_dependencies/ctranslate2-dev/src/profiler.cc:117:45: warning: unused parameter ‘num_threads’ [-Wunused-parameter]
   void init_profiling(Device device, size_t num_threads) {
                                             ^
make[2]: Leaving directory '/opt/ctranslate_dependencies/ctranslate2-dev/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ctranslate2.dir/all' failed
make[1]: *** [CMakeFiles/ctranslate2.dir/all] Error 2
make[1]: Leaving directory '/opt/ctranslate_dependencies/ctranslate2-dev/build'
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

@guillaumekln
Copy link
Collaborator

I can only think that you installed Intel MKL in the past and its installation was not correctly updated. I suggest removing Intel MKL and installing it again from https://software.intel.com/content/www/us/en/develop/tools/math-kernel-library.html.

@anderleich
Copy link
Author

That was the issue! I reinstalled INtel MKL and it succesfully compiled.
However, I've got another error. Apparently CuBlas is missing for Cuda 10.1, which gives an error in the following command:

apt-get install -y --no-install-recommends \
        cuda-cublas-$CUDA_PKG_VERSION \
        python3-distutils-extra \
        wget

https://forums.developer.nvidia.com/t/cublas-for-10-1-is-missing/71015

@guillaumekln
Copy link
Collaborator

The package is libcublas10 for CUDA 10.1 and above.

@anderleich
Copy link
Author

Thanks! It worked!

One last thing... I want to install Ctranslate for Python3.6. This is my code

LANG=en_US.UTF-8
cp $REPOSITORY_DIR/README.md .
cp -r $REPOSITORY_DIR/python python
cd $DEPENDENCIES_PATH/ctranslate2-dev/python

mkdir -p $DEPENDENCIES_PATH/ctranslate2 || exit 1                                                                                                                                         
wget -nv https://bootstrap.pypa.io/get-pip.py                                                                                                 
python3.6 get-pip.py                                                                                                                          
python3.6 -m pip --no-cache-dir install pybind11==2.4.3                                                                                       
python3.6 setup.py bdist_wheel                                                                                                                
rm -r build                                                                                                                                   
rm get-pip.py                                                                                                                                 
python3.6 -m pip freeze | grep pybind11 > $DEPENDENCIES_PATH/ctranslate2/install_requirements.txt                                             
python3.6 setup.py sdist                                                                                                                      
mv dist/* $DEPENDENCIES_PATH/ctranslate2                                                                                                      
rmdir dist                                                                                                                                    


cd $DEPENDENCIES_PATH
mkdir -p $DEPENDENCIES_PATH/ctranslate2/lib || exit 1
cp /opt/intel/lib/intel64/libiomp5.so $DEPENDENCIES_PATH/ctranslate2/lib
cp -P /usr/lib/x86_64-linux-gnu/libcudnn.so* $DEPENDENCIES_PATH/ctranslate2/lib
cp -P /usr/lib/x86_64-linux-gnu/libnvinfer.so* $DEPENDENCIES_PATH/ctranslate2/lib

apt-get update
apt-get install -y --no-install-recommends \
       libcublas10 \
       cuda-cublas-$CUDA_PKG_VERSION \
       python3-distutils-extra \
       wget
apt-get clean
rm -rf /var/lib/apt/lists/*

cp -r $DEPENDENCIES_PATH/ctranslate2 /opt/ctranslate2


wget -nv https://bootstrap.pypa.io/get-pip.py
python3.6 get-pip.py
python3.6 -m pip --no-cache-dir install /opt/ctranslate2/*cp3*.whl
rm get-pip.py

However this seems to build it for Python3.5, which results in this error:

ctranslate2-1.4.0-cp35-cp35m-linux_x86_64.whl is not a supported wheel on this platform.

@guillaumekln
Copy link
Collaborator

The pattern /opt/ctranslate2/*cp3*.whl matches all Python 3 version. You probably want to use /opt/ctranslate2/*cp36*.whl.

@anderleich
Copy link
Author

cp35 is the only file available. It does not find cp36

@guillaumekln
Copy link
Collaborator

So you did not run the same script you shared above? Because this line:

python3.6 setup.py bdist_wheel

should build a wheel for Python 3.6, not 3.5. The rule is to use the same Python version for building and installing the package.

@anderleich
Copy link
Author

Got it! There was a conflict with a previous installation.
Thanks for your help and patience.

@anderleich
Copy link
Author

Hi,
After succesfull installation when I try to translate a sentence I get:

AttributeError: module 'ctranslate2' has no attribute 'Translator'

@anderleich anderleich reopened this Jun 3, 2020
@guillaumekln
Copy link
Collaborator

This means the Python module is unable to load the compiled extension. Can you run the following in a Python interpreter and check the error?

from ctranslate2 import translator

@anderleich
Copy link
Author

anderleich commented Jun 3, 2020

ImportError: libctranslate2.so: cannot open shared object file: No such file or directory

I've done this before

export CTRANSLATE2_ROOT=/opt/ctranslate2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CTRANSLATE2_ROOT/lib

@guillaumekln
Copy link
Collaborator

/opt/ctranslate2

Did you install CTranslate2 in this location? If not, you should update the path.

@anderleich
Copy link
Author

Yes. That's the installation directory.

The log says:
building 'ctranslate2.translator' extension

But it seems it's not getting installed

@guillaumekln
Copy link
Collaborator

You should find where libtctranslate2.so was installed (after make install in your script) and add this directory to the LD_LIBRARY_PATH environment variable.

@anderleich
Copy link
Author

There was a bug in my script which was writting some file in another directory.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants