termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.98k stars 2.98k forks source link

[Bug]: PyTorch doesn't work #21188

Closed marbetschar closed 1 week ago

marbetschar commented 3 weeks ago

Problem description

When I execute pkg install python-torch and then in my python file try to import torch, I get the following error message:

ImportError: dlopen failed: cannot locate symbol "_ZN4absl12lts_202308021hash_internal15MixingHashState5kSeedE" referenced by "/data/data/com.termux/files/usr/lib/python3.11/site-packages/torch/lib/libtorch_python.so"...

Steps to reproduce the behavior.

On a freshly installed Termux, run pkg install python-torch. Then try to import torch from a python file and execute this python file.

What is the expected behavior?

PyTorch should simply work when installed using Termux packages - in fact, I would expect each python-* package to work out of the box when installed from official Termux repository.

I got similar issues after installing jupyter-lab and trying to start it. The pyzmq dependency throws a very similar exception:

ImportError: dlopen failed: cannot locate symbol "PyExc_ImportError" referenced by "/data/data/com.termux/files/usr/lib/python3.11/site-packages/zmq/backend/cython/_zmq.cpython-311.so"...

The solution there was to build pyzmq with the -lpython3.11 flag:

pip uninstall pyzmq
LDFLAGS="-lm -lpython3.11" pip install --no-cache pyzmq

And I've also noticed quite a few other packages seem to have the very same issue - for example numpy and pandas: https://github.com/termux/termux-app/issues/3814

I understand that maybe not every package installed via pip works out of the box on Termux. However, If I install packages from Termux repository I would expect them to work. As of today, the usage of python3.11 in Termux seems to be broken.

System information

Biswa96 commented 3 weeks ago

Did you update all the packages? Could you provide the version numbers of python-torch and abseil-cpp packages using apt info command?

marbetschar commented 3 weeks ago

I ran pkg upgrade, yes.

~ pkg info python-torch
Package: python-torch
Version: 2.1.2-1
Maintainer: @termux
Installed-Size: 254 MB
Depends: ffmpeg, libc++, libopenblas, libprotobuf, libzmq, opencv, python, python-numy, python-pip, fmt
...

~ pkg info abseil-cpp
Package: abseil-cpp
Version: 20240116.2
Maintainer: @termux
Installed-Size: 8663 kB
Depends: libc++
Conflicts: libgrpc (<< 1.52.0-1)
...
Biswa96 commented 3 weeks ago

Latest python-torch version is 2.1.2-4 as of writing this comment. Please try to change the package download mirror using termux-change-repo command. The mirror that you are using may not have latest packages.

marbetschar commented 3 weeks ago

I just gave it a test run and tried multiple mirror groups w/o any success. Switched then to Single mirror and chose packages.termux.dev - which does not provide a newer python-torch version either. It shows python-torch/stable,now 2.1.2-1 aarch64 only.

Seems like there is no newer version available of python-torch for aarch64.

Biswa96 commented 3 weeks ago

python-torch was moved to x11 repository. You have to install x11-repo package to get latest python-torch version.

Though I am not sure why the main repo still has the older python-torch version. It should be removed after that x11 repo migration.

marbetschar commented 3 weeks ago

Installed x11-rep and I'm now able to see python/torch 2.1.2-4. However, it still doesn't want to work:

pkg uninstall python-torch
apt autoremove
pkg update
pkg install python-torch

Then tried to run the following python file:

# test.py
import torch

print("Hello Torch!")

By running: python test.py - and I get the following output:

~ python test.py
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
F0000 00:00:1724076654.159573    28995 common.cc:63] This program was compiled against version 3.0.0 of
Protocol Buffer runtime library, which is not compatible with the installed version (4.25.1). Contact the program
author for an update. If you compiled the program yourself, make sure that your headers are from the same
version of Protocol Buffers as your link-time library.   (Version verification failed in "out/soong/.intermediates/
frameworks/base/libs/hwui/libhwui/android_arm64_armv8-a_core_static/gen/proto/frameworks/base/libs/hwui/
protos/graphicsstats.pb.cc".)
*** Check failure stack trace: **
Aborted
twaik commented 3 weeks ago

Probably we should rebuild the python-torch package.

licy183 commented 3 weeks ago

It seems that python-torch hasn't been deleted from main-repo.

Ping: @Grimler91

Biswa96 commented 3 weeks ago

It has been removed from main repo some hours ago.

marbetschar commented 3 weeks ago

Probably we should rebuild the python-torch package.

Anything I can help with to get the rebuild done? And/or can I provide additional information to find the root cause of the issue?

marbetschar commented 1 week ago

I just noticed there is a new python-torch version 2.1.2-5 available - and after updating to this, the above mentioned issue is gone. Seems pytorch works now. Thank you very much!