CTranslate2 icon indicating copy to clipboard operation
CTranslate2 copied to clipboard

Build Ctranslate2 for android

Open glory03023 opened this issue 1 year ago • 4 comments

Hello, everyone. I am trying to use ctranslate2 on android device. Hope any ctranslate2 expert to guide on how to use ctranslate2 on android. maybe we need to cross-compile ctranslate2 for arm. But it seems there is no way for android build in this project. Thank you.

glory03023 avatar Apr 26 '24 05:04 glory03023

Can be done. Follow the instructions. Change a lot in CmakeList.txt first to NONE.

Manamama avatar May 19 '24 13:05 Manamama

@glory03023 were u able to use ctranslate2 on android. I want to use my nmt models on android and host them there.Just wanted to know did it work for you and if so what steps did u follow? Thanks in advance

Jank14 avatar Aug 11 '24 20:08 Jank14

It used to be more complicated (see my advice above).

Now, I have just retried it, force reinstall:

Environment at system:
Linux localhost 4.14.186+ #1 SMP PREEMPT Thu Mar 17 16:28:22 CST 2022 aarch64 Android


PATH: /data/data/com.termux/files/usr/google-cloud-sdk/bin:/data/data/com.termux/files/home/.opam/default/bin:/data/data/com.termux/files/usr/bin:/system/bin/:/data/data/com.termux/files/usr/bin:/system/bin/:/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/home/.local/bin

LD_PRELOAD: 

LD_LIBRARY_PATH: /data/data/com.termux/files/home/.local/lib:

CC: clang
CXX: clang++
C_INCLUDE_PATH: /data/data/com.termux/files/usr/lib/qt/mkspecs/common/uikit/:/data/data/com.termux/files/usr/include/epoxy/
FC: gfortran
CFLAGS: 
CXXFLAGS: 
LDFLAGS: -lm -lpython3.11 -llog
CPPFLAGS: 

ANDROID_NDK: /storage/7B27-F244/Installs/Android_ndk_sdk/android-ndk-r26b
python2-numpy/tur-packages 1.16.6-1 aarch64

~ $ pip show numpy
Name: numpy
Version: 1.26.5

and the simplest :

~/downloads $ git clone https://github.com/OpenNMT/CTranslate2/
Cloning into 'CTranslate2'...
remote: Enumerating objects: 23075, done.
remote: Counting objects: 100% (4226/4226), done.
remote: Compressing objects: 100% (636/636), done.
remote: Total 23075 (delta 3823), reused 3746 (delta 3587), pack-reused 18849
Receiving objects: 100% (23075/23075), 13.91 MiB | 1.94 MiB/s, done.
Resolving deltas: 100% (17231/17231), done.
[1]+  Done                    updatedb  (wd: ~)
(wd now: ~/downloads)
~/downloads $ cd CTranslate2/
~/downloads/CTranslate2 $ ls
 CHANGELOG.md   cli   cmake   CMakeLists.txt   CONTRIBUTING.md   docker   docs   examples   include   LICENSE   python   README.md  󱧼 src  󰙨 tests   third_party   tools
~/downloads/CTranslate2 $ pip install ./python/ -v
Using pip 24.2 from /data/data/com.termux/files/usr/lib/python3.11/site-packages/pip (python 3.11)
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cpu
Processing ./python
  Running command python setup.py egg_info
  running egg_info
... 
 changing mode of /data/data/com.termux/files/usr/bin/ct2-fairseq-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-marian-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-openai-gpt2-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-opennmt-py-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-opennmt-tf-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-opus-mt-converter to 755
  changing mode of /data/data/com.termux/files/usr/bin/ct2-transformers-converter to 755
Successfully installed ctranslate2-4.3.1
~/downloads/CTranslate2 $ 


resulting (on my system at least) in :

~ $ pip show ctranslate2
Name: ctranslate2
Version: 4.3.1
Summary: Fast inference engine for Transformer models
Home-page: https://opennmt.net
Author: OpenNMT
Author-email: 
License: MIT
Location: /data/data/com.termux/files/usr/lib/python3.11/site-packages
Requires: numpy, pyyaml, setuptools
Required-by: faster-whisper
~ $ 

Manamama avatar Aug 12 '24 14:08 Manamama