# Core ML

**Core ML** 是苹果公司的机器学习框架，用于在 iPhone、iPad、Mac、Apple Watch 和 Apple TV 等苹果设备上运行模型，并在后续版本中支持在设备上训练模型。该框架于 2017 年 6 月 5 日在全球开发者大会上发布，苹果将其描述为贯穿苹果产品的基础机器学习技术，让应用能够集成面部追踪、文本检测和语言识别等功能。<sup>[1](https://developer.apple.com/news/?id=06052017c)</sup> 模型完全在设备上运行，从而将用户数据保留在本地；框架会在 CPU、GPU 和苹果神经引擎（Apple Neural Engine）之间调度工作，后者是苹果片上系统中的专用矩阵加速器。<sup>[2](https://developer.apple.com/videos/play/wwdc2022/10027/)</sup><sup> • </sup><sup>[3](https://arxiv.org/abs/2606.22283)</sup>

| 关键事实 | 详情 |
|---|---|
| 推出时间 | 2017 年 6 月 5 日，在 WWDC 上作为苹果的基础设备端机器学习技术推出<sup>[1](https://developer.apple.com/news/?id=06052017c)</sup> |
| 计算单元 | CPU、GPU 和神经引擎；Xcode 会报告每个运算由哪个单元执行<sup>[2](https://developer.apple.com/videos/play/wwdc2022/10027/)</sup><sup> • </sup><sup>[4](https://developer.apple.com/documentation/coreml/analyzing-a-core-ml-model-s-performance-in-xcode?changes=l_9)</sup> |
| 设备端训练 | 模型一旦部署到设备上，Core ML 便可用该用户的数据对其重新训练或微调<sup>[5](https://developer.apple.com/documentation/coreml/?via=apsock)</sup> |
| 模型格式 | 神经网络（`.mlmodel` 或 `.mlpackage`，面向 iOS 11/macOS 10.13）和 ML 程序（`.mlpackage`，面向 iOS 15/macOS 12）<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup> |
| 转换 | Core ML Tools 通过统一转换 API（coremltools 4.0 及更新版本）转换 TensorFlow 1.x/2.x 和 PyTorch 模型<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup> |
| 权重压缩 | Core ML Tools 可将 32 位浮点权重转换为 16 位或 1 至 8 位的更低精度<sup>[7](https://developer.apple.com/documentation/coreml/reducing-the-size-of-your-core-ml-app?changes=lat_3__5_1&language=objc)</sup> |
| 模型部署 | Core ML 模型部署（WWDC 2020）通过苹果云交付修订后的模型，无需更新应用<sup>[8](https://developer.apple.com/videos/play/wwdc2020/10152/)</sup> |
| 后继者 | Core AI 在 WWDC 2026 上发布，被定位为在设备上运行模型的方式，针对苹果芯片的统一内存和神经引擎进行了优化<sup>[9](https://www.apple.com/newsroom/2026/06/apple-aids-app-development-with-new-intelligence-frameworks-and-advanced-tools/)</sup> |

## 模型如何进入框架

模型必须处于 Core ML 模型格式，应用才能使用它。用苹果的 Create ML 训练的模型直接以该格式输出，开箱即用；在 [TensorFlow](https://www.edgepedia.org/zh/tensorflow) 或 PyTorch 中训练的模型则通过 **Core ML Tools** 转换，这是苹果的开源 Python 包。<sup>[5](https://developer.apple.com/documentation/coreml/?via=apsock)</sup><sup> • </sup><sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup> 统一转换 API 从 Core ML Tools 4.0 起提供，接受 TensorFlow 1.x 格式（冻结图、`.h5` Keras 文件、SavedModel 目录）、TensorFlow 2.x 格式，以及包括 [TorchScript](https://www.edgepedia.org/zh/torchscript) 和 ExportedProgram 对象在内的 PyTorch 格式。<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup> 在 Core ML Tools 4 之前，PyTorch 模型需经过单独的 `onnx-coreml` 转换器，该转换器已冻结且不再维护；Keras 转换器在 Core ML Tools 5 中被弃用。<sup>[10](https://apple.github.io/coremltools/docs-guides/source/faqs.html)</sup>

在内部，转换通过模型中间语言（Model Intermediate Language，MIL）进行。转换器从 TensorFlow 或 PyTorch 获取计算图，构建 MIL 程序，应用一系列优化，然后生成 MLModel。MIL 有多种方言以适应源框架；TensorFlow 1 模型使用 `MIL::TF1` 方言，coremltools 将其转换为 `MIL::Core` 方言。<sup>[11](https://apple.github.io/coremltools/docs-guides/source/model-intermediate-language.html)</sup> 开发者也可以直接使用 MIL 构建器 API 构建模型，而不必从其他框架起步。<sup>[10](https://apple.github.io/coremltools/docs-guides/source/faqs.html)</sup>

## 模型格式

Core ML 有两种模型类型。**神经网络**格式是最初的表示形式；它现在处于维护模式，不再接收新功能，其支持的运算集也已冻结。**ML 程序**格式是神经网络类型的演进，是推荐使用的格式：新运算会持续加入，并且它将权重与程序架构解耦。<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup><sup> • </sup><sup>[12](https://apple.github.io/coremltools/docs-guides/source/convert-to-ml-program.html)</sup>

两种格式在部署目标和文件类型上有所不同。神经网络可在 macOS 10.13、iOS 11、watchOS 4 和 tvOS 11 或更新版本上运行，可保存为 `.mlmodel` 或 `.mlpackage`。ML 程序需要 macOS 12、iOS 15、watchOS 8 或 tvOS 15，且仅使用 `.mlpackage` 目录容器，该容器将模型分离为多个组件，允许更灵活的元数据编辑。<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup><sup> • </sup><sup>[12](https://apple.github.io/coremltools/docs-guides/source/convert-to-ml-program.html)</sup> 从 Core ML Tools 7.0 起，`convert()` 默认生成面向 iOS 15/macOS 12 的 ML 程序；更早的版本默认使用神经网络后端。<sup>[6](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)</sup> ML 程序的权重和中间张量默认使用 float 16 精度，可通过 `compute_precision` 参数请求 float 32。<sup>[12](https://apple.github.io/coremltools/docs-guides/source/convert-to-ml-program.html)</sup>

格式规范是公开的，并以单调递增的规范版本号进行版本管理，任何向后不兼容的更改都会使版本号递增，功能上等同于语义化版本的主版本号。<sup>[13](https://apple.github.io/coremltools/mlmodel/Format/Model.html)</sup>

## 在设备上运行与优化

运行时，应用提供符合模型声明接口的输入，并接收输出。Core ML 支持 8 位灰度和 32 位彩色图像，以及用于多维数组的 Int32、Double 和 [Float32](https://www.edgepedia.org/zh/single-precision-floating-point-format) 标量；从 iOS 16 和 macOS Ventura 起，它还原生接受 [Float16](https://www.edgepedia.org/zh/half-precision-floating-point-format) 灰度图像（OneComponent16Half）和 Float16 MultiArray，因此持有半精度数据的应用可以将缓冲区交给 Core ML，而无需降精度、升精度或内部数据复制。<sup>[2](https://developer.apple.com/videos/play/wwdc2022/10027/)</sup>

Core ML 决定每个运算由哪个计算单元执行，并可能将模型拆分到多个单元；Instruments 跟踪显示，例如，一次预测在神经引擎上开始，然后移交给 GPU 完成。<sup>[2](https://developer.apple.com/videos/play/wwdc2022/10027/)</sup> Xcode 的性能报告会执行模型并报告加载和预测时间，以及执行每个运算的计算单元——神经引擎、GPU 或 CPU。<sup>[4](https://developer.apple.com/documentation/coreml/analyzing-a-core-ml-model-s-performance-in-xcode?changes=l_9)</sup>

**大小与速度。** 由于模型随应用包一起分发，苹果提供了多种缩减途径。Core ML Tools 量化工具可将 32 位浮点权重转换为半精度（16 位）或 1 至 8 位的更低精度；对于无法使用更低精度的模型，应用可以在用户设备上下载并编译模型，而不是将其打包进应用。<sup>[7](https://developer.apple.com/documentation/coreml/reducing-the-size-of-your-core-ml-app?changes=lat_3__5_1&language=objc)</sup> 苹果的压缩工具还涵盖调色板化和剪枝，当应用充分利用神经引擎时，压缩后的模型可以运行得更快。<sup>[14](https://www.youtube.com/watch?v=6wyCImsNGbY)</sup> Core ML Tools 8 增加了更多压缩技术，旨在缩减体积并保持准确率。<sup>[15](https://developer.apple.com/documentation/updates/coreml?changes=lat_3_1_4_6_2)</sup>

**部署与安全。** Core ML 模型部署在 WWDC 2020 上推出，通过仪表板经由苹果云存储、管理和部署模型，因此开发者无需发布应用更新即可向应用交付修订后的模型；同一场会议还涵盖了加密自定义模型的内容。<sup>[8](https://developer.apple.com/videos/play/wwdc2020/10152/)</sup>

## 与神经引擎的关系

苹果神经引擎是自 A11 级 iPhone 和 iPad 芯片以及 M1 级 Mac 芯片以来随苹果片上系统出货的固定功能矩阵加速器，仅通过 Core ML 模型框架向应用开放。<sup>[3](https://arxiv.org/abs/2606.22283)</sup> 这种耦合塑造了 Core ML 的能力边界：独立研究指出，Core ML 的抽象层阻止了对神经引擎的直接编程，并且截至该分析时，不支持在该引擎上进行设备端训练。<sup>[16](https://arxiv.org/abs/2603.06728)</sup> 2025 年对 M4 芯片的一项评估发现，该引擎在矩阵乘法方面可与 GPU 竞争（最高 3.8 TFlops，而 M4 Pro 上为 4.7 TFlops），同时功耗低得多，GEMM 为 5.2 W 对 24 W，这正是将工作通过 Core ML 路由到该引擎的效率依据。<sup>[17](https://arxiv.org/abs/2511.13450)</sup>

## 实测表现

2024 年的一项 MOBILESoft 研究在 iPhone 8 Plus、iPhone 11 Pro 和 iPad Air 4 上，使用 MobileNetV2、ResNet50 和 BERT QA 对 Core ML 与 TensorFlow Lite 和 PyTorch 进行了基准测试。Core ML 在所测试的框架中准确率最高，在 ImageNet 上 MobileNetV2 为 0.927、ResNet50 为 0.924，在 SQuAD 上 BERT QA 的 BLEU 为 0.8158；它也是三者中唯一受益于神经引擎的框架；在配备神经引擎的设备上，Core ML 的 MobileNetV2 在 iPhone 11 Pro 上每次推理耗时 3.7 毫秒，而 PyTorch 为 14.5 毫秒。<sup>[18](https://ris.utwente.nl/ws/portalfiles/portal/459256139/A_Study_on_the_Battery_Usage_of_Deep_Learning_Frameworks_on_iOS_Devices.pdf)</sup> 在不具备神经引擎的 iPhone 8 Plus 上，情况有所不同：转换为 Core ML 的 TensorFlow MobileNet 比原生 CoreML 模型更高效，而 TFLite 和 PyTorch 运行更快但能耗更高。<sup>[18](https://ris.utwente.nl/ws/portalfiles/portal/459256139/A_Study_on_the_Battery_Usage_of_Deep_Learning_Frameworks_on_iOS_Devices.pdf)</sup>

## Core ML 及其后继者

Core ML 仍是受支持的设备端模型发布途径，但苹果已在其周围叠加了更新的框架。2025 年推出的基础模型框架（Foundation Models framework）让应用可以直接访问 [Apple Intelligence](https://www.edgepedia.org/zh/apple-intelligence) 背后的设备端基础语言模型，这是一个约 30 亿参数、针对[苹果芯片](https://www.edgepedia.org/zh/apple-silicon)优化的模型。<sup>[19](https://machinelearning.apple.com/research/apple-foundation-models-2025-updates)</sup> 在 WWDC 2026 上，苹果推出了 **Core AI**，被描述为一个全新的框架，旨在成为在设备上运行模型的最佳方式，其架构针对苹果芯片的统一内存和神经引擎进行了优化，让开发者能够在本地部署完整规模的大语言模型；独立基准测试项目将其视为 Core ML 的后继者。<sup>[9](https://www.apple.com/newsroom/2026/06/apple-aids-app-development-with-new-intelligence-frameworks-and-advanced-tools/)</sup><sup> • </sup><sup>[20](https://github.com/john-rocky/apple-silicon-llm-bench)</sup>

## References

1. [Build More Intelligent Apps with Core ML, Apple Developer News (June 5, 2017)](https://developer.apple.com/news/?id=06052017c)
2. [Optimize your Core ML usage, WWDC22 session, Apple Developer](https://developer.apple.com/videos/play/wwdc2022/10027/)
3. [Apple Neural Engine: Architecture, Programming, and Performance, arXiv:2606.22283](https://arxiv.org/abs/2606.22283)
4. [Analyzing a Core ML model's performance in Xcode, Apple Developer Documentation](https://developer.apple.com/documentation/coreml/analyzing-a-core-ml-model-s-performance-in-xcode?changes=l_9)
5. [Core ML, Apple Developer Documentation](https://developer.apple.com/documentation/coreml/?via=apsock)
6. [Source and Conversion Formats, Guide to Core ML Tools](https://apple.github.io/coremltools/docs-guides/source/target-conversion-formats.html)
7. [Reducing the Size of Your Core ML App, Apple Developer Documentation](https://developer.apple.com/documentation/coreml/reducing-the-size-of-your-core-ml-app?changes=lat_3__5_1&language=objc)
8. [Use model deployment and security with Core ML, WWDC20 session, Apple Developer](https://developer.apple.com/videos/play/wwdc2020/10152/)
9. [Apple aids app development with new intelligence frameworks and advanced tools, Apple Newsroom (June 8, 2026)](https://www.apple.com/newsroom/2026/06/apple-aids-app-development-with-new-intelligence-frameworks-and-advanced-tools/)
10. [Core ML Tools FAQs, Guide to Core ML Tools](https://apple.github.io/coremltools/docs-guides/source/faqs.html)
11. [Model Intermediate Language, Guide to Core ML Tools](https://apple.github.io/coremltools/docs-guides/source/model-intermediate-language.html)
12. [Convert Models to ML Programs, Guide to Core ML Tools](https://apple.github.io/coremltools/docs-guides/source/convert-to-ml-program.html)
13. [Core ML Model, Core ML Format Reference](https://apple.github.io/coremltools/mlmodel/Format/Model.html)
14. [Use Core ML Tools for machine learning model compression, WWDC23 session, Apple Developer](https://www.youtube.com/watch?v=6wyCImsNGbY)
15. [Core ML updates, Apple Developer Documentation](https://developer.apple.com/documentation/updates/coreml?changes=lat_3_1_4_6_2)
16. [Orion: Characterizing and Programming Apple's Neural Engine for LLM Training and Inference, arXiv:2603.06728](https://arxiv.org/abs/2603.06728)
17. [Evaluation of Domain-Specific Architectures for General-Purpose Applications in Apple Silicon, arXiv:2511.13450](https://arxiv.org/abs/2511.13450)
18. [A Study on the Battery Usage of Deep Learning Frameworks on iOS Devices, MOBILESoft 2024](https://ris.utwente.nl/ws/portalfiles/portal/459256139/A_Study_on_the_Battery_Usage_of_Deep_Learning_Frameworks_on_iOS_Devices.pdf)
19. [Updates to Apple's On-Device and Server Foundation Language Models, Apple Machine Learning Research](https://machinelearning.apple.com/research/apple-foundation-models-2025-updates)
20. [apple-silicon-llm-bench, GitHub repository](https://github.com/john-rocky/apple-silicon-llm-bench)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › AI companies, people, and products › AI products and assistants › AI agents and developer tools

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/core-ml

English original: https://www.edgepedia.org/core-ml
