Advice on how to run the training example in Android
Hello Team,
We have followed https://pytorch.org/executorch/main/using-executorch-android.html#building-from-source to build the "aar" file.
We can run the inference example on Android.
We are wondering how to run the training example on Android.
Are there some flags / some config we need to add to the building procedure (https://github.com/pytorch/executorch/blob/main/scripts/build_android_library.sh)?
Thanks!
cc @kirklandsign @cbilgin @JacobSzwejbka
@JacobSzwejbka any thoughts on this?
Hi @JacobSzwejbka do we know the cmake config if on linux, not necessarily android?
basically need to copy that to android
Hi @JacobSzwejbka do we know the cmake config if on linux, not necessarily android?
basically need to copy that to android
https://github.com/pytorch/executorch/blob/main/extension/training/CMakeLists.txt do you mean this?
or
heres the list of the other extensions we need https://github.com/pytorch/executorch/blob/main/CMakeLists.txt#L253
Hi @JacobSzwejbka I have been trying to build and troubleshoot but having trouble getting ExecuTorch built for Android with training.
I have been using the main branch of the executorch code on an Ubuntu 24.04.2 machine to install the dependencies and build ExecuTorch but after much back and forth with versions, I am still stuck. Currently, I cannot even get ExecuTorch to build without Android, and running the following command to build and debug:
cmake --build cmake-out -j1 --target install --config Release -- VERBOSE=1
I get the following output with an error for ATen/Tensor.h: No such file or directory:
/home/ubuntudev4android/workspace/appforexecutorchtraining/executorch/extension/training/pybindings/_training_lib.cpp:13:10: fatal error: ATen/Tensor.h: No such file or directory
13 | #include <ATen/Tensor.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [extension/training/CMakeFiles/_training_lib.dir/build.make:79: extension/training/CMakeFiles/_training_lib.dir/pybindings/_training_lib.cpp.o] Error 1
gmake[2]: Leaving directory '/home/ubuntudev4android/workspace/appforexecutorchtraining/executorch/cmake-out'
gmake[1]: *** [CMakeFiles/Makefile2:1268: extension/training/CMakeFiles/_training_lib.dir/all] Error 2
gmake[1]: Leaving directory '/home/ubuntudev4android/workspace/appforexecutorchtraining/executorch/cmake-out'
gmake: *** [Makefile:136: all] Error 2
Do you know if there is something I need to do to resolve the issue with ATen/Tensor.h, or if there a particular version of ExecuTorch or other dependencies I should be trying to build with that might give me a better chance of success?
Edit: I was able to resolve this error by getting and unzipping libtorch then making sure libtorch was properly linked, which I did with this flag:
-DCMAKE_PREFIX_PATH=/home/ubuntudev4android/workspace/executorch/libtorch
Hi @JacobSzwejbka
I was able to use 0.6.0 to build with training to run the training example on Ubuntu, but getting the Android build to succeed is continuing to be an issue.
pybind11 seems to be a source of the issues and I'm not sure if this is supposed to be available on Android, but when configuring cmake in order to build ExecuTorch for Android, I run:
cmake -B cmake-out-android-arm64-v8a
-DCMAKE_INSTALL_PREFIX=cmake-out-android-arm64-v8a
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake
-DANDROID_ABI=arm64-v8a
-DANDROID_PLATFORM=android-26
-DCMAKE_BUILD_TYPE=Release
-DANDROID_STL=c++_shared
-DBUILD_TESTING=OFF
-DEXECUTORCH_BUILD_TRAINING=ON
-DEXECUTORCH_BUILD_XNNPACK=ON
-DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
-DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON
-DEXECUTORCH_BUILD_ANDROID_JNI=ON
-DEXECUTORCH_ENABLE_LOGGING=ON
-DEXECUTORCH_LOG_LEVEL=Info
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON
-DCMAKE_PREFIX_PATH=/home/ubudev4android/workspace/executorch/libtorch
-DPYTHON_EXECUTABLE=/home/ubudev4android/workspace/executorch/venv_py310/bin/python
-Dpybind11_DIR="/home/ubudev4android/workspace/executorch/venv_py310/lib/python3.10/site-packages/pybind11/share/cmake/pybind11"
-DEXECUTORCH_BUILD_DEVTOOLS=ON
but I am now blocked by this error:
CMake Error at /usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Python3_LIBRARIES Development Development.Module Development.Embed) (found version "3.10.17") Call Stack (most recent call first): /usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.28/Modules/FindPython/Support.cmake:3862 (find_package_handle_standard_args) /usr/share/cmake-3.28/Modules/FindPython3.cmake:545 (include) extension/training/CMakeLists.txt:61 (find_package)
By the way, for the Ubuntu build I needed to add these lines in extension/training/CMakeLists.txt:
set(Python3_FIND_VIRTUALENV FIRST) find_package(Python3 COMPONENTS Interpreter Development REQUIRED) find_package_torch() find_package(pybind11 REQUIRED)
before:
pybind11_add_module(_training_lib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/pybindings/_training_lib.cpp)
and then I set the flag for cmake -Dpybind11_DIR= to the directory with my pybind11 package for my venv.
looking
Its strange to me that we are trying to build the python layer here at all lol.
This should probably be gated https://github.com/pytorch/executorch/blob/main/extension/training/CMakeLists.txt#L44 behind EXECUTORCH_BUILD_PYBIND
https://github.com/pytorch/executorch/pull/11001?fbclid=IwY2xjawKZl-tleHRuA2FlbQIxMQBicmlkETFXSFRkMWxpMERnSUY4eUdRAR5hqMvxqzQWsnoHWiSnvRjrVppCe8Le8tFB_Sk802RCTpda8Vg4krOJNm1T4w_aem_28RB-jK26wy5Rmt-c9d7mQ try this @YuanTingHsieh
@JacobSzwejbka @kirklandsign Could you share IF android ExecuTorch training is working on the android phones right now? If not, what is missing?
As far as I know this flag is not helping @nvkevlu
Thank you very much!