mlc-ai / mlc-llm

Universal LLM Deployment Engine with ML Compilation
https://llm.mlc.ai/
Apache License 2.0
19.21k stars 1.58k forks source link

[Question] How should I build for iOS Simulator? I need to be able to compile simulators (even if I don't run the model in them) #2929

Open bryan1anderson opened 2 months ago

bryan1anderson commented 2 months ago

I followed the SDK guide for implementing this into an iOS app. That works. I have it compiling on device. However, if I try to use SwiftUI previews or try to build to simulator I get

ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a2', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a3', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a4', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a5', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a6', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a7', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a8', assuming: iOS-simulator ld: warning: no platform load command found in '/Users/user/Developer/JournalApp/dist/lib/libmodel_iphone.a9', assuming: iOS-simulator ld: building for 'iOS-simulator', but linking in object file (/Users/user/Developer/JournalApp/dist/lib/libmlc_llm.a2) built for 'iOS' clang: error: linker command failed with exit code 1 (use -v to see invocation)

tqchen commented 1 month ago

Unfortunately the SDK relies on GPU so do not work on simulator for now. One way to run might be to build for iPad on Mac.

bryan1anderson commented 1 month ago

So having this an app completely disables the ability to run the app on simulator?

PabloButron commented 1 month ago

Unfortunately the SDK relies on GPU so do not work on simulator for now. One way to run might be to build for iPad on Mac.

the easiest way is the @tqchen solution, but always test on physical device, because these kind of bugs can happen: https://github.com/mlc-ai/mlc-llm/issues/2904#issue-2526645190

bryan1anderson commented 1 month ago

I think ideally all this should be housed in a framework that is marked unavailable on simulator

if canImport(_) could then handle it.

@PabloButron @tqchen has anyone tried to house the entire MLC bundle in a separate framework?

tqchen commented 1 month ago

I am not that familar with iOS part of such dev, but the original swift source is here https://github.com/mlc-ai/mlc-llm/tree/main/ios/MLCSwift, feel free to take a look and see if any change can be made

bryan1anderson commented 1 month ago

It seems like it would be ideal for there to be a script that generates an XCFramework with all that is necessary. I tried to make some progress on that last night but am running into so many linker issues. Is there someone who was responsible for generating the Swift package that is familiar with static library linking?

bryan1anderson commented 1 month ago

@PabloButron i have just spend the better part of two evenings trying and failing to compile this on simulator. I need to be able to develop using SwiftUI previews on simulators.

I do not need to run the actual model on a sim.

I've tried xcframeworks but hit dead ends. I've tried to mimic the steps for integrating MLC into a code project for both frameworks and static libraries.

I'm having a very hard time of it. So if you have any ideas, even if not easy, I could use them

bryan1anderson commented 1 month ago

Of course, I can conditionalize all of the other Swift linker flags… But how to conditionally link this Library?

It's been a huge pain that this doesn't work out of the box for XC framework archives. You can't set the build for release flag to true