What's the state of pytorch on android?

Last time I looked into it (end of last year), it was not possible (as someone without a lot of experience with C++ and cross-compilation). The main challenge was trying to compile libtorch for ARM. Has the situation changed?

Basic PyTorch / Android support has been merged.
There currently is some hiccup due to the merging of libcaffe2 and libtorch #20774, but it seems to work.

Not all models are fast yet.

1 Like

Still various issues, see https://github.com/pytorch/pytorch/issues/21737

Hopefully will be fixed soon though.

Well, I use a .so for my stuff.

But that’s huge… unless there’s a way that I’m unaware of to reduce its size?

From what I can tell Android Studio strips the .so it includes in the APK, so the final .so will be 30MB (armeabi-v7a) - 43MB (x86) here. Not great but certainly not completely ridiculous, either.

1 Like

Is there a guide for how to build the libtorch for android? I’m not finding any info.

Seems to work with scripts/build_pytorch_android.sh now.

Created a super simple app which showcases how to use a model in C++: https://github.com/RuABraun/android-with-pytorch

Thanks for sharing this sample app! build_pytorch_android.sh script doesn’t seem to run properly for me. Did you use any flags while running it? What was your compiler version?
Thanks

The script doesn’t have to finish successfully, what matters is that the static libraries in build_android_${ABI}/lib exist. Check for that.

I see that now. Thanks! FWIW my problem was that I didn’t clone the pytorch project appropriately with submodules (git clone --recurse-submodules -j8 https://github.com/pytorch/pytorch.git).