What's the state of pytorch on android?

username: divinho
cooked: <p>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?</p>

username: tom
cooked: <p>Basic PyTorch / Android support has been merged.<br>
There currently is some hiccup due to the merging of libcaffe2 and libtorch <a href="https://github.com/pytorch/pytorch/pull/20774/" rel="noopener nofollow ugc">#20774</a>, but it seems to work.</p>
<p>Not all models are fast yet.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/b/b3c01280ce4b94886df62ec3c4ad47385fbbc928.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/b3c01280ce4b94886df62ec3c4ad47385fbbc928" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/b/b3c01280ce4b94886df62ec3c4ad47385fbbc928_2_509x500.jpeg" alt="image" data-base62-sha1="pE8YLLsX59TkMHL99vY12ijzgxi" width="509" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/b/b3c01280ce4b94886df62ec3c4ad47385fbbc928_2_509x500.jpeg, https://discuss.pytorch.org/uploads/default/original/2X/b/b3c01280ce4b94886df62ec3c4ad47385fbbc928.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/b/b3c01280ce4b94886df62ec3c4ad47385fbbc928.jpeg 2x" data-dominant-color="686962"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">672×660 161 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: divinho
cooked: <p>Still various issues, see <a href="https://github.com/pytorch/pytorch/issues/21737" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/21737</a></p>
<p>Hopefully will be fixed soon though.</p>

username: tom
cooked: <p>Well, I use a .so for my stuff.</p>

username: divinho
cooked: <p>But that’s huge… unless there’s a way that I’m unaware of to reduce its size?</p>

username: tom
cooked: <p>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.</p>

username: divinho
cooked: <p>Is there a guide for how to build the libtorch for android? I’m not finding any info.</p>

username: divinho
cooked: <p>Seems to work with <code>scripts/build_pytorch_android.sh</code> now.</p>
<p>Created a super simple app which showcases how to use a model in C++: <a href="https://github.com/RuABraun/android-with-pytorch" rel="nofollow noopener">https://github.com/RuABraun/android-with-pytorch</a></p>

username: kwanUm
cooked: <aside class="quote no-group" data-username="divinho" data-post="8" data-topic="46873">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/9dc877/48.png" class="avatar"> divinho:</div>
<blockquote>
<p>scripts/build_pytorch_android.sh</p>
</blockquote>
</aside>
<p>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?<br>
Thanks</p>

username: divinho
cooked: <p>The script doesn’t have to finish successfully, what matters is that the static libraries in <code>build_android_${ABI}/lib</code> exist. Check for that.</p>

username: kwanUm
cooked: <p>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 <a href="https://github.com/pytorch/pytorch.git" rel="nofollow noopener">https://github.com/pytorch/pytorch.git</a>).</p>