Giới thiệu
Core AI là framework mới của Apple để build, run và deploy AI model ngay trên thiết bị. Thiết kế từ đầu cho Apple silicon, framework cho phép app dùng các architecture model và inference technique mới nhất, chạy trên cả CPU, GPU và Neural Engine. Swift API được làm gọn để các tác vụ thường gặp dễ dùng, nhưng vẫn cho bạn control sâu khi cần — model specialization, caching, hay tinh chỉnh inference performance.
Framework có status Beta và áp dụng cho iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+, watchOS 27.0+.
Khi nào dùng Core AI thay vì Core ML
Điểm phân biệt quan trọng: nếu app dùng các kiểu model ngoài neural network như decision tree hay tabular feature engineering, hãy tiếp tục dùng Core ML. Core AI tập trung phục vụ neural network architecture hiện đại — đúng dòng các LLM/VLM/diffusion model dev đang quan tâm.
Tính năng chính
Bộ tool đi kèm
Core AI không chỉ là framework runtime mà là một ecosystem hoàn chỉnh cho on-device AI:
- Core AI Optimization: chuẩn bị model cho Apple silicon
- Core AI PyTorch Extensions: convert PyTorch model sang định dạng
.aimodelmà runtime dùng - Core AI Debugger: app debugging với khả năng visualize cấu trúc model và trace tensor value ngược lại đúng dòng Python source code — tính năng đáng giá nhất cho ai từng phải debug model conversion bằng print()
coreai-buildCLI: pre-compile model ahead-of-time để giảm thời gian specialization khi app khởi động- Core AI debug gauge + Core AI instrument trong Xcode để monitor và profile inference performance
Khối API chính
Framework gồm 23 symbol chính, chia theo nhóm:
Essentials
struct AIModel— model đã specialize sẵn để chạy inference trên thiết bịstruct AIModelAsset— source asset gốc, chưa specialize- Integrating on-device AI models in your app with Core AI — guide chính cho app
Inference
struct InferenceFunction— function chạy inference với input và output valuestruct InferenceFunctionDescriptor— mô tả signature của inference functionstruct InferenceValue— value làm input/output cho inference functionstruct ImageDescriptor— mô tả dimensions và pixel format của image inputclass ComputeStream— stream async chứa work cần chạy
Multidimensional arrays
struct NDArray— mảng nhiều chiều chứa scalar value cho model inferencestruct NDArrayDescriptor— shape, scalar type, memory layout expectation
Configuration
- Managing model specialization and caching — config specialization, quản lý cached asset, giảm dung lượng app
- Compiling Core AI models ahead of time — pre-compile để giảm specialization time runtime
class AIModelCache— cache chứa artifact đã specializeenum ComputeUnitKind— loại hardware compute unit cho inferencestruct SpecializationOptions— tuỳ chỉnh quá trình specialize
Debugging và performance
Errors
enum AssetError— error type khi load/specialize asset
Cách sử dụng
Flow điển hình của một app dùng Core AI:
- Chuẩn bị model bằng Core AI Optimization (cho model do bạn train hoặc convert từ PyTorch qua Core AI PyTorch Extensions thành
.aimodel). - Tuỳ chọn: pre-compile bằng
coreai-buildtại build-time để giảm specialization runtime. - Trong app, load
AIModelAssetvà specialize thànhAIModelbằngSpecializationOptions(tuỳ thiết bị mục tiêu). - Tạo
InferenceFunctionvà gọi quaComputeStreamđể chạy inference async. - Quản lý footprint bằng
AIModelCacheđể tránh specialize lại mỗi lần.
Khi cần optimize, dùng Core AI debug gauge và Core AI instrument trong Xcode để profile, hoặc mở Core AI Debugger để inspect cấu trúc model và trace tensor value trực tiếp về Python source.
Dev nên quan tâm vì
- Đây là cái path “chính thống” của Apple cho on-device LLM/VLM trên iOS 27+ và macOS 27+ — nếu app của bạn đang vật lộn với MPS thuần để chạy quantized model, Core AI cho bạn một API cao hơn nhưng vẫn control được CPU/GPU/Neural Engine.
- Trace tensor về dòng Python gốc trong Core AI Debugger là feature cực mạnh cho ai từng debug model conversion — đoán xem PyTorch op nào bị mapping sai sẽ dễ hơn rất nhiều.
- AOT compile qua
coreai-buildđáng để integrate vào CI từ đầu — giảm cold-start specialization time là khác biệt cảm nhận được giữa app “AI cảm giác instant” và app “vòng spinner mãi không hết”. - Phân biệt rõ Core AI vs Core ML từ đầu giúp đỡ pain về sau: tabular và classical ML thì Core ML, neural net hiện đại thì Core AI.