用 Core AI 把開源模型帶進 Apple app
這場 session 用一個語言學習 app 示範:找模型、轉成 .aimodel、在 Swift 中載入 SAM3 與 Qwen、用 Instruments 找 first-run latency,最後用 AOT compilation 與 Background Assets 改善部署體驗。
Core AI 的重點不是「多一個推論 API」,而是把模型挑選、轉換、整合、profiling、AOT compilation、on-demand delivery 串成可出貨的 on-device AI 工作流。
這支影片把 on-device model 出貨拆成五件事
先用產品需求定義模型組合
demo app 不是先挑熱門模型,而是先定義任務:用照片與 prompt 分割物件,再生成中文 vocab card。因此選 SAM3 做 segmentation、Qwen 0.6B 做多語言文字生成。
.aimodel 是 Xcode 可檢查的資產
Core AI models repository 提供 export recipes,把 popular open-source models 轉成針對 Apple silicon 最佳化的 .aimodel,Xcode 可檢視大小、平台、function signatures 與 tensor shapes。
Core AI model 可接 Foundation Models workflow
語言模型透過 CoreAILanguageModel 載入,再交給 Foundation Models 的 LanguageModelSession;輸出可用 @Generable 產生 typed structured data。
first-run latency 要被設計,不要藏起來
模型 specialization 會造成首次準備時間。影片用 Core AI Instruments template 找出瓶頸,再用 AOT compilation 與 Background Assets 改善首次體驗與 app bundle 體積。
從模型探索到跨平台出貨的實作流程
定義 app AI capabilities
先列出內容、語言、平台與裝置限制;demo 需要 segmentation、language generation、iOS / macOS 共用 code。
從 Core AI models repository 取得模型
用 repository 中的 export recipes 取得 SAM3、Qwen 等模型的 optimized .aimodel,而不是手工摸索轉換流程。
在 Xcode 檢查 model interface
查看 model size、supported platforms、function signatures、tensor shapes,確認模型能被 app 呼叫且符合裝置目標。
用 Swift package 與 Core AI API 整合
加入 coreai-models Swift package,選 CoreAILM / CoreAISegmentation library,載入 ImageSegmenter 與 CoreAILanguageModel。
用 profiling + AOT + Background Assets 管部署
用 Instruments 找 specialization latency;用 xcrun coreai-build compile 產生 compiled assets;用 Background Assets on-demand 下載模型。
重點 1:demo app 用兩個模型組成一個產品功能
影片的例子是一個語言學習 app:學生用相機拍生活中的物件,輸入想學的語言,app 先把物件從場景中分割出來,再生成字卡、翻譯與例句。這讓內容從固定 curated deck 變成使用者生活情境中的 on-device generation。
這裡的設計重點是 model composition。SAM3 處理 text-prompted image segmentation,Qwen 處理語言生成;Core AI 讓兩者都能以 Apple 平台 app 的方式整合、profile 與部署。
重點 2:Core AI models repository 降低模型轉換門檻
重點 3:Swift integration 同時服務 vision 與 language
ImageSegmenter(resourcesAt: sam3ModelURL),再用 segment(image:prompt:) 取得 mask。CoreAILanguageModel(resourcesAt: qwen3ModelURL) 載入,再建立 LanguageModelSession(model:)。@Generable struct VocabCard,讓模型輸出直接對應 Swift 型別,而不是後處理一段自由文字。重點 4:first-run model specialization 是產品體驗問題
影片用 Core AI Instruments template 診斷首次延遲,發現成本來自 model specialization:系統把 Core AI model 編譯成特定裝置可高效執行的形式。這不應該被藏成「app 卡住」,而要變成明確的 first-run experience。
xcrun coreai-build compile MyModel.aimodel --platform iOS 在開發機先編譯,降低裝置上的首次準備時間。風險與遷移注意事項
對 app 團隊的實作啟發
來源
主要來源為 Apple Developer 官方影片頁、官方 transcript、章節摘要與 sample code;YouTube 影片頁用於 iframe 與發布 metadata。官方頁:Integrate on-device AI models into your app using Core AI - WWDC26。YouTube:WWDC26: Integrate on-device AI models into your app using Core AI | Apple。
- 01Core AI 把開源模型帶進 Apple app 的重點在完整 workflow:模型、轉換、整合、profiling、部署。
- 02SAM3 + Qwen demo 顯示 on-device AI 可以把使用者生活資料變成即時、私密、可互動的 app feature。
- 03CoreAILanguageModel 可接 Foundation Models 的 LanguageModelSession 與 @Generable typed output。
- 04first-run specialization、bundle size、AOT compilation 與 Background Assets 是能否出貨的關鍵。