kylebgorman / pynini

Read-only mirror of Pynini
http://pynini.opengrm.org
Apache License 2.0
121 stars 26 forks source link

failed compile on aarch64 with openfst=1.8.2 and pynini=2.1.5 #84

Open huskyachao opened 1 week ago

huskyachao commented 1 week ago

hi, I tried to compile openfst and pynini on a aarch64 machine. Although the version of openfst and pynini match, I still met with some troubles after a successful installation of openfst. BTW, I want to install pynini under a virtual environment/home/ma-user/anaconda3/envs/PyTorch-2.1.0. Here is the commands:

## compile openfst
openfst_version=openfst-1.8.2
tar -zxvf $openfst_version.tar.gz
chmod 755 -R $PWD/$openfst_version/
cd $PWD/$openfst_version/ 
./configure --enable-grm --prefix=/home/ma-user/anaconda3/envs/PyTorch-2.1.0 # venv path
make -j8
make install
cd ../

## compile pynini
pynini_version=pynini-2.1.5
tar -zxvf $pynini_version.tar.gz
cd ./$pynini_version/
python setup.py install
cd ../

The error is posed by the pynini building:

  2065  copying pywrapfst/py.typed -> build/lib.linux-aarch64-cpython-39/pywrapfst
  2066  copying pynini/examples/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/examples
  2067  copying pynini/lib/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/lib
  2068  copying pynini/export/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/export
  2069  running build_ext
  2070  building '_pywrapfst' extension
  2071  creating build/temp.linux-aarch64-cpython-39
  2072  creating build/temp.linux-aarch64-cpython-39/extensions
  2073  gcc -pthread -B /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O3 -Wall -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -fPIC -I/home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9 -c extensions/_pywrapfst.cpp -o build/temp.linux-aarch64-cpython-39/extensions/_pywrapfst.o -std=c++17 -Wno-register -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-local-typedefs -funsigned-char
  2074  extensions/_pywrapfst.cpp: In function ‘PyObject* __pyx_pf_10_pywrapfst_6Weight_4__float__(__pyx_obj_10_pywrapfst_Weight*)’:
  2075  extensions/_pywrapfst.cpp:11659:40: error: invalid cast from type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to type ‘PyObject*’ {aka ‘_object*’}
  2076  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2077        |                                        ^~~~~~~~~~~~~~~~~~~~~
  2078  extensions/_pywrapfst.cpp:1470:43: note: in definition of macro ‘likely’
  2079   1470 |   #define likely(x)   __builtin_expect(!!(x), 1)
  2080        |                                           ^
  2081  /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/object.h:130:42: note: in expansion of macro ‘_PyObject_CAST_CONST’
  2082    130 | #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
  2083        |                                          ^~~~~~~~~~~~~~~~~~~~
  2084  /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/floatobject.h:24:32: note: in expansion of macro ‘Py_IS_TYPE’
  2085     24 | #define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
  2086        |                                ^~~~~~~~~~
  2087  extensions/_pywrapfst.cpp:3283:10: note: in expansion of macro ‘PyFloat_CheckExact’
  2088   3283 | ((likely(PyFloat_CheckExact(obj))) ?  PyFloat_AS_DOUBLE(obj) :\
  2089        |          ^~~~~~~~~~~~~~~~~~
  2090  extensions/_pywrapfst.cpp:11659:15: note: in expansion of macro ‘__Pyx_PyObject_AsDouble’
  2091  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2092        |               ^~~~~~~~~~~~~~~~~~~~~~~
  2093  In file included from /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/Python.h:97,
  2094                   from extensions/_pywrapfst.cpp:46:
  2095  extensions/_pywrapfst.cpp:11659:40: error: invalid cast from type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to type ‘PyObject*’ {aka ‘_object*’}
  2096  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2097        |                                        ^~~~~~~~~~~~~~~~~~~~~
  2098  /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/floatobject.h:51:51: note: in definition of macro ‘PyFloat_AS_DOUBLE’
  2099     51 | #define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
  2100        |                                                   ^~
  2101  extensions/_pywrapfst.cpp:11659:15: note: in expansion of macro ‘__Pyx_PyObject_AsDouble’
  2102  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2103        |               ^~~~~~~~~~~~~~~~~~~~~~~
  2104  extensions/_pywrapfst.cpp:11659:40: error: invalid cast from type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to type ‘PyObject*’ {aka ‘_object*’}
  2105  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2106        |                                        ^~~~~~~~~~~~~~~~~~~~~
  2107  extensions/_pywrapfst.cpp:1470:43: note: in definition of macro ‘likely’
  2108   1470 |   #define likely(x)   __builtin_expect(!!(x), 1)
  2109        |                                           ^
  2110  /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/object.h:130:42: note: in expansion of macro ‘_PyObject_CAST_CONST’
  2111    130 | #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
  2112        |                                          ^~~~~~~~~~~~~~~~~~~~
  2113  /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9/longobject.h:16:31: note: in expansion of macro ‘Py_IS_TYPE’
  2114     16 | #define PyLong_CheckExact(op) Py_IS_TYPE(op, &PyLong_Type)
  2115        |                               ^~~~~~~~~~
  2116  extensions/_pywrapfst.cpp:3284:9: note: in expansion of macro ‘PyLong_CheckExact’
  2117   3284 |  likely(PyLong_CheckExact(obj)) ?\
  2118        |         ^~~~~~~~~~~~~~~~~
  2119  extensions/_pywrapfst.cpp:11659:15: note: in expansion of macro ‘__Pyx_PyObject_AsDouble’
  2120  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2121        |               ^~~~~~~~~~~~~~~~~~~~~~~
  2122  extensions/_pywrapfst.cpp:11659:40: error: invalid cast from type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to type ‘PyObject*’ {aka ‘_object*’}
  2123  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2124        |                                        ^~~~~~~~~~~~~~~~~~~~~
  2125  extensions/_pywrapfst.cpp:3285:18: note: in definition of macro ‘__Pyx_PyObject_AsDouble’
  2126   3285 |  PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
  2127        |                  ^~~
  2128  extensions/_pywrapfst.cpp:11659:40: error: invalid cast from type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to type ‘PyObject*’ {aka ‘_object*’}
  2129  11659 |   __pyx_t_2 = __Pyx_PyObject_AsDouble(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 497, __pyx_L1_error)
  2130        |                                        ^~~~~~~~~~~~~~~~~~~~~
  2131  extensions/_pywrapfst.cpp:3285:50: note: in definition of macro ‘__Pyx_PyObject_AsDouble’
  2132   3285 |  PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
  2133        |                                                  ^~~
  2134  error: command '/usr/bin/gcc' failed with exit code 1
kylebgorman commented 1 week ago

Why don't you try this with OpenFst 1.8.3. and Pynini 2.1.6.post1 instead? Those are the most recent versions and I believe everything is working as expected for them.

huskyachao commented 1 week ago

hi, thanks a lot for your timely response. I just tried as you suggested but met with new problems. It seemed that the openfst-1.8.3 was installed successfully but there are some problems with pynini installation.

# install openfst
openfst_version=openfst-1.8.3
tar -zxvf $openfst_version.tar.gz
chmod 755 -R $PWD/$openfst_version/
cd $PWD/$openfst_version/
./configure --enable-grm --prefix=/home/ma-user/anaconda3/envs/PyTorch-2.1.0 # install openfst to venv
make -j8
make install
cd ../

# upgrade pip
python -m pip install --upgrade pip

pip install \
    --config-settings="--build-option=build_ext" \
    --upgrade \
    --verbose \
    pynini==2.1.6.post1

It seemed that the openfst-1.8.3 was installed successfully.

  1776  libtool: finish: PATH="/usr/local/Ascend/ascend-toolkit/latest/bin:/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:/usr/local/Ascend/ascend-toolkit/latest/tools/ccec_compiler/bin:/home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin:/usr/local/mindspore-lite/mindspore-lite-2.3.0-linux-aarch64/tools/converter/converter:/usr/local/mindspore-lite/mindspore-lite-2.3.0-linux-aarch64/tools/benchmark:/usr/local/Ascend/driver/tools:/usr/local/openmpi/bin:/usr/local/ffmpeg/bin:/usr/local/Ascend/toolbox/latest/Ascend-DMI/bin:/usr/local/Ascend/ascend-toolkit/latest/bin:/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ma-user/.local/bin:/sbin" ldconfig -n /home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib
  1777  ----------------------------------------------------------------------
  1778  Libraries have been installed in:
  1779     /home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib
  1780  
  1781  If you ever happen to want to link against installed libraries
  1782  in a given directory, LIBDIR, you must either use libtool, and
  1783  specify the full pathname of the library, or use the '-LLIBDIR'
  1784  flag during linking and do at least one of the following:
  1785     - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
  1786       during execution
  1787     - add LIBDIR to the 'LD_RUN_PATH' environment variable
  1788       during linking
  1789     - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
  1790     - have your system administrator add LIBDIR to '/etc/ld.so.conf'
  1791  
  1792  See any operating system documentation about shared libraries for
  1793  more information, such as the ld(1) and ld.so(8) manual pages.
  1794  ----------------------------------------------------------------------
  1795   /usr/bin/mkdir -p '/home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin'
  1796    /bin/sh ../../../libtool   --mode=install /usr/bin/install -c mpdtcompose mpdtexpand mpdtinfo mpdtreverse '/home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin'
  1797  libtool: install: /usr/bin/install -c .libs/mpdtcompose /home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin/mpdtcompose
  1798  libtool: install: /usr/bin/install -c .libs/mpdtexpand /home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin/mpdtexpand
  1799  libtool: install: /usr/bin/install -c .libs/mpdtinfo /home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin/mpdtinfo
  1800  libtool: install: /usr/bin/install -c .libs/mpdtreverse /home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin/mpdtreverse
  1801  make[4]: Nothing to be done for 'install-data-am'.

But the pynini installation posed errors as follows:

  1958    copying pynini/export/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/export
  1959    copying pynini/lib/BUILD.bazel -> build/lib.linux-aarch64-cpython-39/pynini/lib
  1960    copying pynini/lib/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/lib
  1961    copying pynini/examples/BUILD.bazel -> build/lib.linux-aarch64-cpython-39/pynini/examples
  1962    copying pynini/examples/py.typed -> build/lib.linux-aarch64-cpython-39/pynini/examples
  1963    running build_ext
  1964    building '_pywrapfst' extension
  1965    creating build/temp.linux-aarch64-cpython-39
  1966    creating build/temp.linux-aarch64-cpython-39/extensions
  1967    g++ -pthread -B /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O3 -Wall -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -fPIC -I/home/ma-user/anaconda3/envs/PyTorch-2.1.0/include/python3.9 -c extensions/_pywrapfst.cpp -o build/temp.linux-aarch64-cpython-39/extensions/_pywrapfst.o -std=c++17 -Wno-register -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-local-typedefs -funsigned-char
  1968    g++ -pthread -B /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O3 -Wall -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -fPIC -O3 -isystem /home/ma-user/anaconda3/envs/PyTorch-2.1.0/include -pthread -B /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat -shared build/temp.linux-aarch64-cpython-39/extensions/_pywrapfst.o -lfstfarscript -lfstfar -lfstscript -lfst -lm -ldl -o build/lib.linux-aarch64-cpython-39/_pywrapfst.cpython-39-aarch64-linux-gnu.so
  1969    /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat/ld: cannot find -lfstfarscript: No such file or directory
  1970    /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat/ld: cannot find -lfstfar: No such file or directory
  1971    /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat/ld: cannot find -lfstscript: No such file or directory
  1972    /home/ma-user/anaconda3/envs/PyTorch-2.1.0/compiler_compat/ld: cannot find -lfst: No such file or directory
  1973    collect2: error: ld returned 1 exit status
  1974    error: command '/usr/bin/g++' failed with exit code 1
  1975    error: subprocess-exited-with-error
  1976    
  1977    × Building wheel for pynini (pyproject.toml) did not run successfully.
  1978    │ exit code: 1
  1979    ╰─> See above for output.
  1980    
  1981    note: This error originates from a subprocess, and is likely not a problem with pip.
  1982    full command: /home/ma-user/anaconda3/envs/PyTorch-2.1.0/bin/python /home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /tmp/tmpnv6es0mi
  1983    cwd: /tmp/pip-install-2yg9gi81/pynini_ecd777a06d244c2fb737cba81eafb1c0
  1984    Building wheel for pynini (pyproject.toml): finished with status 'error'
kylebgorman commented 1 week ago

This is a good sign; I think you're close. It's failing at linking because it doesn't know that you put the OpenFst libraries in a non-standard prefix. There are three things you can try:

  1. Try passing environmental variables for LD_LIBRARY_PATH. I think it would look like LD_LIBRARY_PATH=/home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib python setup.py. I am not sure if this will work but it's the first thing I'd try.
  2. Add these flags to extra_link_args argument to the two calls to Extension here and here.
  3. Alternatively, don't use a prefix when you install OpenFst; it'll install to /usr/local/lib and it'll "just work".

This is not a problem per se with Pynini's build system; this is a same issue with linking compiled software against libraries in non-standard locations that strikes basically every compiled UNIX library.

huskyachao commented 1 week ago

This is a good sign; I think you're close. It's failing at linking because it doesn't know that you put the OpenFst libraries in a non-standard prefix. There are three things you can try:

  1. Try passing environmental variables for LD_LIBRARY_PATH. I think it would look like LD_LIBRARY_PATH=/home/ma-user/anaconda3/envs/PyTorch-2.1.0/lib python setup.py. I am not sure if this will work but it's the first thing I'd try.
  2. Add these flags to extra_link_args argument to the two calls to Extension here and here.
  3. Alternatively, don't use a prefix when you install OpenFst; it'll install to /usr/local/lib and it'll "just work".

This is not a problem per se with Pynini's build system; this is a same issue with linking compiled software against libraries in non-standard locations that strikes basically every compiled UNIX library.

Thanks. Ok, I will have a try as you suggested.

kylebgorman commented 4 days ago

Any luck @huskyachao ?

huskyachao commented 3 days ago

Any luck @huskyachao ?

Hi, kylebgorman. Thanks for your attention. It seems that there are still some problems about the installation. I will give a feedback later.