I have an app on the App Store that uses Core AI for image generation and music generation on iPhone. I want to share what worked, because there was very little written about this when I started and some of it took a long time to find.
The app supports iOS 17.6 and later. The Core AI features are available on iOS 27, and the rest of the app runs unchanged on older systems. It uses three Core AI models, which are FLUX.2 Klein for images, Stable Audio Open Small for short clips, and Stable Audio 3 Small for full-length music.
FLUX.2 Klein
The app runs FLUX.2 Klein through FlowTransformerPipeline from the coreai-models package, for both text to image and image editing. These are the things I learned from it.
Ship the compiled bundle and name every compiled file in metadata.json. The pipeline now reads asset filenames only from metadata.json. An earlier version looked for fixed .aimodel filenames and reported that the Transformer component was missing for every compiled bundle. I reported that in coreai-models issue 355, and the fix was merged in pull request 357.
Offer image editing as a separate download. Text to image does not need the VAE encoder or the image-to-image transformer, so the app downloads those only when the user adds image editing. If you leave files out this way, you must also remove their keys from metadata.json, because a file that is declared but missing now throws an error.
Create a new pipeline after the files on disk change. The pipeline decides at initialization whether image editing is available. A pipeline created before the editing files were downloaded kept running text to image, and it did so without any error.
Use the predicted clean image for live previews. With a four-step model, the noisy latent after each step does not look like anything a user can recognize. The predicted x0 does, and it makes the preview useful from the first step. I suggested this in coreai-models issue 231, and the package now supports previews through an optional progress handler that costs nothing when it is not used.
Loading is fast. The compiled FLUX.2 Klein bundle loads almost immediately on the phone, with none of the long first-run compile that I saw with text models on the Neural Engine.
Stable Audio
Compile ahead of time for any large model. Loading the Stable Audio 3 source bundle on an iPhone 17 Pro ran for more than five minutes before I stopped it. The same model compiled on the Mac with coreai-build loads in seconds on the phone. The first load after download took about 15 seconds, and later loads were close to instant.
Remove the functions you do not call before you compile. The Stable Audio 3 Small bundle has encoder functions and several decoder sizes that my app never uses. I removed those entry points with the coreai-torch package and left the helper graphs alone. The source went from 2.9 GB to 2.5 GB, the compiled bundle went from 7.0 GB to 4.8 GB, and the compile time on the Mac went from 9 minutes 18 seconds to 59 seconds.
Memory was not the limit I expected for audio. A two-minute song peaked at about 2 GB on an iPhone 17 Pro, which leaves a good margin under what iOS allows one app.
Small models can be compiled on the device. Stable Audio Open Small is about 1 GB and its bundles compiled on the phone in about 3 seconds. It then produced 11.9 seconds of audio in 9.2 seconds.
Text models
Text models are the part I have not been able to ship on Core AI, and the work is still open with Apple.
I exported Qwen3 0.6B and SmolLM2 1.7B for iOS and compiled both ahead of time for the Neural Engine. Each compiled bundle still contains 30 Neural Engine regions that the system finishes compiling on the device at first load. Apple has confirmed that this step on the device is expected, and that coreai-build does not produce the final Neural Engine executables.
That step is where the trouble is. On an iPhone 17 Pro, the first load of Qwen3 0.6B took more than two minutes, and later loads took about eight seconds. SmolLM2 1.7B never finished. The compiler tried to reserve a temporary file of 33.6 to 35.5 GB, ran out of storage, and the app was then terminated by an assertion. The app receives no error, so it cannot fall back to another model or tell the user what happened.
I repeated the test on a Mac with the current toolchain, and the storage use is the same there. The first load used a peak of 17 GB of temporary disk space for the 0.6B model and 42 GB for the 1.7B model. The Mac has the room, so both models work, and they are fast once cached. Loads took about 0.05 seconds, with 196 tokens per second for the 0.6B model and 63 for the 1.7B model.
Apple has reproduced the disk usage and is investigating it. The details are in coreai-models issue 387 and in my earlier thread at https://developer.apple.com/forums/thread/855499. Until that is resolved I have removed both models from the app, and local text models run on MLX and llama.cpp instead. I would like to hear from anyone who has a text model larger than 1B parameters loading on an iPhone through Core AI.
Supporting older systems
Weak link the framework if you support systems before iOS 27. My app crashed at launch on iOS 26 until I added -weak_framework CoreAI and -weak_framework FoundationModels to the linker flags. Availability checks in my own code were not enough, because the prebuilt coreai-models libraries imported those frameworks strongly.
The simulator SDK has no CoreAI.framework, so the weak link flag for CoreAI has to be limited to device builds and all testing happens on a device.
A few things I published may save others some time. The recipe I use to build coreai-models as xcframeworks is at https://github.com/james-333i/coreai-models-xcframework. The compiled FLUX.2 Klein bundle for iPhone is at https://huggingface.co/333i/flux2-klein-coreai-ios, and the trimmed Stable Audio 3 Small bundle is at https://huggingface.co/333i/stable-audio-3-small-music-coreai-ios.
The app is Infinity Vaults, if anyone wants to see these models running in a shipping product. I am glad to answer questions about any of the steps above.
Topic:
Machine Learning & AI
SubTopic:
Core AI
0
0
134