-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Target c10 directly on Android #21
Comments
I think this is a great idea. It would then be possible to use a lot of the same code as on iOS. Unfortunately there are not a lot of resources for using pytorch C++ api combined with Android. |
I've been trying this the past few days, compiling Pytorch for android C++ and linking them in cmake, but with no luck. I couldn't get past a |
@cyrillkuettel Thank you! This was the right direction, I've tried it now, tweaked it a bit and it's working ❤️ For anyone with the same issue, here is how I managed to add native C++ LibTorch to FFI Android/Flutter: Details
Some benchmarks - FFI vs Current version of the packageThe inference is significantly faster through FFI. Moreover, with bigger input tensors, I was getting an The current version of the package: FFI: (I measured the time to make the model inference from Please note, that I don't currently have time to rewrite this package and make a PR. |
@dvagala Big if true! Wow! That are some drastic performance improvements. That's amazing I have to admit I did not expect that much of a gain. It seems that the platform/method channel was actually really slow. How did you solve it, did you do the per-processing in C++ as well? As a side note, your C++ might be suitable for iOS as well. (Since iOS is largely based on ObjectiveC) We might even be able to get rid of platform channels entirely. |
@cyrillkuettel Sure! I've made an example project here Yes, it's running on both Android and iOS, and all the code is shared. That's the beauty of Flutter :) |
@dvagala I was trying to follow your steps but using the Update: It's ok now, I forgot to copy the .ccp file to Runner target. Another question: It's possible to make a ffi plugin with |
@beroso |
@beroso Hi, I wanted to ask if you eventually did find a solution for iOS C++ files? I have the time and motivation to rewrite this package to |
Hello, I did suffer from the same problem in my package, but the solutions mentioned to me were to create static lib with pytorch and the c++ ffi code , and use that in the iOS pod Sadly my knowledge with iOS is very low, so I failed to do so, and reverted back to objc and java. I Hope this information helps you. |
Hello, thanks for the information. I believe I have found the solution to this problem. I did not yet test it, but it looks promising Step 2: Building and bundling native code plugin:
platforms:
some_platform:
ffiPlugin: true # if we set this flutter will bundle the C++ files
|
I believe I did try that, but anyway if it worked for you let me know, since ffi was more stable and more predictable and I wish to go back to it |
Yes, stable, and you don't have duplicated inference code for each host platform. Also there are some neat tricks which I found in https://github.com/ValYouW/flutter-opencv-stream-processing so that with |
Yes I did that, too and using the repo as a reference 😅. The latest commit using ffi I could find in case that helps you |
Fascinating. I have done a lot to same things in my own project (not open source yet, because I need to fix this distribution problem and clean things up) Only just today I discovered your package 🙃 |
From what I know The only features I don't provide that exist in your package are the inference as a direct list of values I have inference for yolov5 and yolov8 and used pigeon to make sure all null safe communications and async operations |
I'm not the owner of this project :) |
Oh my bad😂 I didn't notice, if you were able to do it let me know, and if you want to make a pr I would love that |
@cyrillkuettel abdelaziz-mahdy/pytorch_lite#65 i made this pr on the latest commit for ffi just to extract it from history incase you need to check it also included the points needed to be fixed for the ffi to be used. |
Currently this package on Android goes from Dart to Java via message channels, then from Java to C++ glue code via JNI, then from that C++ to the actual core pytorch library (and then all the way back). It would be more efficient if the Dart code used FFI to directly drive the C++ code.
The text was updated successfully, but these errors were encountered: