1. PyInstaller
You could package your application using pyinstaller
. This tool packages your app with Python and dependencies and use only the parts you need (simplifying, in reality it's hard to trace your package exactly so some other stuff would be bundled as well).
Also you might be in for some quirks and workarounds to make it work with pytorch
and numpy
as those dependencies are quite heavy (especially pytorch
).
2. Use only PyTorch
numpy
and pytorch
are pretty similar feature-wise (as PyTorch tries to be compatible with it) hence maybe you could only use only of them which would simplify the whole thing further
3. Use C++
Depending on other parts of your app you may write it (at least neural network) in C++ using PyTorch's C++ frontend which is stable since 1.5.0
release.
Going this route would allow you to compile PyTorch's .cpp
source code statically (so all dependencies are linked) which allows you for relatively small binary size (30Mb
when compared to PyTorch's 1GB+
), but requires a lot of work.