-
Notifications
You must be signed in to change notification settings - Fork 74.4k
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
Make TensorFlow Lite available as Swift Package Manager package #44609
Comments
This isn't a solution, but I spent a fair amount of time digging into this trying to find a workaround. This is a little brain dump of my progress. I was able to get a custom build of TFLite built and packaged as an XCFramework in a private SPM module, but it required a handful of hacks to get working properly. I'm not really comfortable with bazel though, so I did all of this with writing a bash script over a handful of bazel operations. My workflow is:
One limitation is that the xcframeworks will require you to manually disable the iOS simulator for To "disable the iOS simulator for
|
We haven't done any investigation, and I'll need to learn more about Swift Package Manager to understand how much effort it would be required to support it. cc/ @morganchen12 who might have some experience about this. |
Probably the most challenging part of adding SPM support is you will need to add SPM support for all of your dependencies. SPM packages are also defined per-repository, so one Package.swift file at the root of the tensorflow repo would be responsible for representing Tensorflow, TensorFlowLiteSwift, TensorFlowLiteObjC, TensorFlowLiteC, and any other modules that are buildable in a Swift target. It looks like TensorFlowLiteSwift and TensorFlowLiteObjC have very shallow dependency graphs, so adding SPM support should be straightforward. |
Today I hit the error building the framework with Xcode 12.3 https://gist.github.com/evnik introduced conversion script as a temporary solution: https://gist.github.com/evnik/6762d5c3a4b21f61f13b100e03b62c38 |
Yeah, I think XCFramework makes more sense than Swift Package Manager approach, as XCFramework supports packaging compiled binaries as we currently do today. As far as I can tell, CocoaPods supports XCFrameworks already, but bazel still doesn't support building for iOS arm64 simulator (for M1-based macs) nor building XCFrameworks natively. We might need to do some manual work in the interim, with something like the script @greenzeal linked. @greenzeal In what exact situation were you seeing that specific error? Can you be a bit more specific and help me reproduce that issue? What does your project structure look like? |
@yyoon
The compiler will complain like this: Another simple way to reproduce:
I tried different ways to find a solution like building the Bazel and then TensorFlowLiteC from the source, but all lead to that error. I would really appreciate if anyone has a workaround. Or maybe it's possible to build TensorFlowLiteC.framework using Xcode (xcodebuild)? |
btw also I will be happy if there is a way, even a manual one. And will be happy to try to automate it and share it here. |
@greenzeal I could create a dummy project as you described and confirmed that I could reproduce. Do you really need to build your framework for arm64 simulator? If you have a pressing need to build for arm64 simulator, you might want to try this: This would let you build a TensorFlowLiteC slice for arm64 simulator (haven't had a chance to try it myself). Then, you could add the build output to the "Frameworks and Libraries" list of your framework project. |
Excluding arm64 is a temporary option indeed. I had tried with a patch, but had no luck yet to make it work. Will try again definitely. |
What is the current situation of the issue? @yyoon @teijeong @jdduke I have tried to create I have used official ErrorsI have tried several workarounds to eliminate some errors like first two below. I applied the solution in swift forums to eliminate:
and it seems worked out. And, I am not sure if it is relevant but I tried to set
But as you can see below, now I have something similar and several others:
|
Also looping in @miaout17 |
Any progress here? Is there nobody using TensorFlowLiteC.framework on m1 simulator now? |
i am having the same issues and i do not manage with the offered work arounds, would appreciate any direct help of how to currently solve this problem of using TensorFlowLiteSwift as a dependency! help! |
Is there any progress? |
+1 |
1 similar comment
+1 |
@pkgoogle @yishuangP This is absolutly nonsensical. A feature request that has been open for 3 years, isn't even a big feature or a development of any sort of core functionality, but rather just a bit of putting together an automated script and a wrapper, uploading it here, and releasing us all from these workarounds. There are a dozen of engineers here, that with the proper access and support will HAPPILY do the work and contribute. In fact some of us have already spent hours trying to work this for the good of the community. Furthermore, the lack of communication of something that is trivial, with anyone from the team not having updated or participated in this thread for almost a full year, is downright unacceptable. |
Maybe this can help you https://github.com/kewlbear/TensorFlowLiteC |
@pkgoogle @yishuangP Is there a way to get an official response from the team? Even just to say "Sorry we won't do anything for the time being" (though an ETA would be much appreciated). This issue has been tagged with "Awaiting tensorflower" for 4 months now... |
+1 |
If you manage to export the current pod as .xcframework making it a SPM is very easy |
It is very easy to roll out your own SPM. Problem is that won't correctly sign and you cannot deploy that to the App Store. Works great in debug but useless in actual apps. |
+1 |
1 similar comment
+1 |
Is there any hope to have SPM anytime in the future? |
I gave up on TensorFlow creating SPM, I created my own SPM repo that passes code signing issues in App Store and uploads just fine https://github.com/tareksabry1337/TensorFlowLiteC |
@tareksabry1337 Could you elaborate on how you did it? Maybe the guys here will try and implement it if they have the solution (if anyone at tensorflow actually still reads this thread - cc @yishuangP) |
@yomw Everything is in the repo, it's an automated GitHub action that builds static variant of TensorFlowLiteC framework, and modifies TensorFlowLiteCCoreML build script to build a static variant too, both for device, building simulator variant from these scripts fails for some obscure reason that I don't understand, to fix that I install the version from Cocoapods and copy over the simulator slice and then combine both slices (device static slice / simulator dynamic slice) and create an XCFramework that works just fine. |
+1 |
2 similar comments
+1 |
+1 |
+54 this is turning into the GNOME gitlab |
+1 Can we get an update on this please? It's been quite a while since SPM has been out. |
Can we PLEASE add SPM support already?! Since everyone is now starting to use SPM and dropping cocoapods, this will really help all Apple devs. (Its been 4years since the issue was opened and we're all willing to help & get this done!) Thanks! Attn: @pkgoogle @yyoon @yishuangP |
Literally having to choose CoreML because of this limitation. SPM support is more critical to iOS ecosystem than it might seem. CocoaPods has gone into maintenance mode earlier this year and we will only see more people move to SPM from here on as that's the only option around with an actual feature and maintenance roadmap. |
I wonder if this SPM issue is part of the reason why there is no SPM yet? I think it would be impossible at the moment to bundle the binary frameworks inside the SPM because of that issue. |
@mmaetzler I literally packaged TensorFlow under SPM on a fork and it's currently in app that's on the AppStore, I can't fathom why such simple request is being completely ignored. |
@tareksabry1337 I did the same. I have an app submitted to the store with my own (internal) tflite SPM. But I was not able to create an SPM with |
@pkgoogle Continuing the conversation here as you suggested, #78787 (comment) Could you please tell us if we can expect this to be resolved in the next 6 months? Its crazy that after 4 years and so many developers requesting & waiting for so long, there is no clarity. There must be some valid reason for this, right? |
HI @lothrop, Thanks for raising this issue. Are you aware of the migration to LiteRT? This transition is aimed at enhancing our project's capabilities and providing improved support and focus for our users. As we believe this issue is still relevant to LiteRT we are moving your issue there. Please follow progress here. Let us know if you have any questions. Thanks. |
Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template
System information
Describe the feature and the current behavior/state.
Right now, TensorFlow Lite is available as a CocoaPod or as source for iOS developers. CocoaPods cannot be used from inside a Swift Package Manager (SPM) package. Since SPM is the official package manager from Apple and the way forward, it would be nice to have TensorFlow Lite available as an SPM package or an XCFramwork, in addition to the current CocoaPods distribution.
Will this change the current api? How?
No
Who will benefit with this feature?
iOS developers who are using SPM for module manager or who are not using CocoaPods anymore.
Any Other info.
I have tried creating my own SPM package or XCFramework from the source but could not get it to work because of the native code. But I'm confident it should be possible.
The text was updated successfully, but these errors were encountered: