BeeWare, Chaquopy .. llama-cpp whl build for arm64-v8a .. issues with original library being found due to linking issues

31 views Asked by At

We're using Android studio. And a Galaxy Note 20 I went out and bought a device. I ran it on the device and from the logcat:

--------- beginning of crash
2024-03-22 09:14:04.125 28482-28482 AndroidRuntime          com.kidschatgpt.KidsChatGPT          E  FATAL EXCEPTION: main
Process: com.kidschatgpt.KidsChatGPT, PID: 28482
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kidschatgpt.KidsChatGPT/org.beeware.android.MainActivity}: com.chaquo.python.PyException: FileNotFoundError: Shared library with base name 'llama' not found
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4169)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: com.chaquo.python.PyException: FileNotFoundError: Shared library with base name 'llama' not found
at <python>.llama_cpp.llama_cpp._load_shared_library(llama_cpp.py:74)
at <python>.llama_cpp.llama_cpp.<module>(llama_cpp.py:83)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.llama_cpp.<module>(__init__.py:1)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.KidsChatGPT.app.<module>(app.py:16)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.__main__.<module>(__main__.py:1)
at <python>.runpy._run_code(<frozen runpy>:88)
at <python>.runpy._run_module_code(<frozen runpy>:98)
at <python>.runpy.run_module(<frozen runpy>:226)
at <python>.chaquopy_java.call(chaquopy_java.pyx:354)
at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:326)
at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
at org.beeware.android.MainActivity.onCreate(MainActivity.java:85)
at android.app.Activity.performCreate(Activity.java:8591)
at android.app.Activity.performCreate(Activity.java:8570)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:226) 
at android.os.Looper.loop(Looper.java:313) 
at android.app.ActivityThread.main(ActivityThread.java:8762) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 
2024-03-22 09:14:04.183  1338-5434  ActivityTaskManager     system_server                        W    Force finishing activity com.kidschatgpt.KidsChatGPT/org.beeware.android.MainActivity
2024-03-22 09:14:04.187  1338-5434  ActivityTaskManager     system_server                        D  scheduleTopResumedActivityChanged, onTop=false r=ActivityRecord{909a8c4 u0 com.kidschatgpt.KidsChatGPT/org.beeware.android.MainActivity} t47 f}} caller=com.android.server.wm.ActivityTaskSupervisor.updateTopResumedActivityIfNeeded:2510 com.android.server.wm.TaskDisplayArea.positionChildTaskAt:602 com.android.server.wm.TaskDisplayArea.positionChildAt:537 com.android.server.wm.WindowContainer.positionChildAt:970 com.android.server.wm.Task.positionChildAt:3354 com.android.server.wm.Task.moveToFrontInner:6053 
2024-03-22 09:14:04.208  4406-25659 [AirCmd]_A...chDetector com...ng.android.service.aircommand  I  onTaskFocusChanged : mTopMostActivity - ComponentInfo{com.kidschatgpt.KidsChatGPT/org.beeware.android.MainActivity}

What is going on? We used PyPi and had an OK output. As seen here https://github.com/chaquo/chaquopy/issues/1094#issuecomment-2007590623

It was advised at BeeWare that the llama file inside the llama_cpp_python isn't linked or being found. Here is the file structure when the successful wheel build.

Here is the file structure for the arm64-v8a whl we build using PyPi https://pypi.org/project/llama-cpp-python/ enter image description here

Here is the package before running Choquopy downloaded manually from PyPi for visual enter image description here

So upon looking further. A lot of files are missing from the android version whl versus the one I downloaded. Maybe a link was broken? What do I make out of this?

In my BeeWare app.py file I have the following

from llama_cpp import Llama # Used for offline chat with llama-cpp
from llama_cpp.llama_chat_format import format_openbuddy, register_chat_format, ChatFormatterResponse
from typing import Any, List
from llama_cpp import llama_types

It seems that llama is not being imported from llama_cpp. What happened during the whl build and can I change something in my python code sort this out?

When I look even further. The from llama_cpp import Llama part that cannot be found should work enter image description here

This code works fine. This is a build issue with the the llama library not being found in the new whl. When it clearly is there.

0

There are 0 answers