Apple Developer onepage/WWDC26
#WWDC26#CoreAI#FoundationModels#OnDeviceAI2026-06-08 · 23:44

用 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 工作流。

Apple Developer · WWDC26 · Video ID: gl5lD2gEhb0Apple Developer 官方頁
Content map

這支影片把 on-device model 出貨拆成五件事

Model choice

先用產品需求定義模型組合

demo app 不是先挑熱門模型,而是先定義任務:用照片與 prompt 分割物件,再生成中文 vocab card。因此選 SAM3 做 segmentation、Qwen 0.6B 做多語言文字生成。

Packaging

.aimodel 是 Xcode 可檢查的資產

Core AI models repository 提供 export recipes,把 popular open-source models 轉成針對 Apple silicon 最佳化的 .aimodel,Xcode 可檢視大小、平台、function signatures 與 tensor shapes。

Swift API

Core AI model 可接 Foundation Models workflow

語言模型透過 CoreAILanguageModel 載入,再交給 Foundation Models 的 LanguageModelSession;輸出可用 @Generable 產生 typed structured data。

Deployment

first-run latency 要被設計,不要藏起來

模型 specialization 會造成首次準備時間。影片用 Core AI Instruments template 找出瓶頸,再用 AOT compilation 與 Background Assets 改善首次體驗與 app bundle 體積。

Implementation flow

從模型探索到跨平台出貨的實作流程

1

定義 app AI capabilities

先列出內容、語言、平台與裝置限制;demo 需要 segmentation、language generation、iOS / macOS 共用 code。

2

從 Core AI models repository 取得模型

用 repository 中的 export recipes 取得 SAM3、Qwen 等模型的 optimized .aimodel,而不是手工摸索轉換流程。

3

在 Xcode 檢查 model interface

查看 model size、supported platforms、function signatures、tensor shapes,確認模型能被 app 呼叫且符合裝置目標。

4

用 Swift package 與 Core AI API 整合

加入 coreai-models Swift package,選 CoreAILM / CoreAISegmentation library,載入 ImageSegmenter 與 CoreAILanguageModel。

5

用 profiling + AOT + Background Assets 管部署

用 Instruments 找 specialization latency;用 xcrun coreai-build compile 產生 compiled assets;用 Background Assets on-demand 下載模型。

Official chapter map
0:00
Introduction
1:16
App concept: camera-based vocab learning
2:52
Model discovery
7:40
Getting models with the Core AI models repository
8:37
Integration
10:55
Writing the Swift integration code
13:05
Diagnosing model specialization latency
14:40
Deployment
17:00
Ahead-of-time (AOT) compilation
18:03
iOS demo
19:57
Multiplatform
23:06
Next steps

重點 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 降低模型轉換門檻

模型 catalog官方提到 repository 收錄 Qwen、Mistral、SAM3 等 popular open-source models,並針對 Apple silicon 最佳化。
Export recipes開發者可用既有 recipe 產生 .aimodel,而不是從 PyTorch / Hugging Face 格式一路手動踩坑。
Xcode inspection加入專案後可檢查大小、支援平台、function signatures、tensor shapes,提早發現整合不匹配。
Swift package透過 coreai-models Swift package 選 CoreAILM 與 CoreAISegmentation 等 library,讓 app 端呼叫更接近一般 framework。

重點 3:Swift integration 同時服務 vision 與 language

01
用 ImageSegmenter 載入 SAM3
sample code 使用 ImageSegmenter(resourcesAt: sam3ModelURL),再用 segment(image:prompt:) 取得 mask。
02
用 CoreAILanguageModel 接 Foundation Models
語言模型以 CoreAILanguageModel(resourcesAt: qwen3ModelURL) 載入,再建立 LanguageModelSession(model:)。
03
用 @Generable 取得 typed output
字卡可定義成 @Generable struct VocabCard,讓模型輸出直接對應 Swift 型別,而不是後處理一段自由文字。

重點 4:first-run model specialization 是產品體驗問題

影片用 Core AI Instruments template 診斷首次延遲,發現成本來自 model specialization:系統把 Core AI model 編譯成特定裝置可高效執行的形式。這不應該被藏成「app 卡住」,而要變成明確的 first-run experience。

AOT compilation用 xcrun coreai-build compile MyModel.aimodel --platform iOS 在開發機先編譯,降低裝置上的首次準備時間。
Background Assets模型不一定要塞進 app bundle;可在使用者 opt in 後再 on-demand download,避免所有人承擔 app update 體積。
Cached assets首次準備完成後,後續 inference 使用 cached model asset,體驗才接近即時。
Multiplatform scaling同一套 Swift code 可跑到 Mac,再用更大 Qwen3 8B、batch processing 與長 context 支援內容策展。

風險與遷移注意事項

模型選擇要從任務與裝置限制回推小模型適合 iPhone 即時功能;Mac 可用更大模型做批次與策展,但不能直接假設同一 UX。
不要把模型全部塞進 bundle大型模型會放大下載與更新成本;需要 Background Assets、版本管理與使用者 opt-in 流程。
首次準備時間要被量測用 Instruments template 找出 specialization / loading / inference 的真瓶頸,不要只看 demo 成功。
structured output 仍要驗證@Generable 降低 parsing 成本,但字卡內容、pinyin、翻譯與例句仍需品質檢查與 fallback。

對 app 團隊的實作啟發

01
把 on-device AI 視為 feature pipeline,不是單一 API
model discovery、conversion、Swift API、profiling、AOT、asset delivery 都要有人負責。
02
先做一個跨模型的小型垂直切片
像影片的 vocab card:一個 vision model 加一個 language model,端到端驗證使用者價值與部署成本。
03
在 release checklist 中加入 model lifecycle
包含模型版本、AOT output、Background Assets manifest、首次體驗、cache invalidation 與不同裝置效能。

來源

主要來源為 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。

TL;DR