# ExecuTorch

**ExecuTorch** 是一个开源软件栈，用于直接在边缘设备上运行 PyTorch 机器学习模型——包括手机、可穿戴设备、嵌入式系统和微控制器——无需云端连接。它是 PyTorch Edge 生态的一部分，提供从 PyTorch 模型编写到端侧推理的端到端路径，使用轻量级 C++ 运行时和面向 CPU、GPU、NPU 与 DSP 的硬件专用后端。<sup>[1](https://pytorch.org/projects/executorch/)</sup> Meta 在 Arm、Apple、Qualcomm 等行业伙伴的支持下开发了该项目，如今它已成为 PyTorch 基金会的核心项目。<sup>[2](https://engineering.fb.com/2025/07/28/android/executorch-on-device-ml-meta-family-of-apps/)</sup><sup> • </sup><sup>[3](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)</sup>

| 关键事实 | 详情 |
|---|---|
| 用途 | 在移动、嵌入式和微控制器硬件上对 PyTorch 模型进行端侧推理，支持保护隐私的离线执行<sup>[1](https://pytorch.org/projects/executorch/)</sup> |
| 首次展示 | PyTorch 大会 2023；alpha 版本 2024 年 4 月 30 日；beta 版本 2024 年 10 月；1.0 结束 beta 状态<sup>[3](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)</sup><sup> • </sup><sup>[4](https://pytorch.org/blog/executorch-alpha/?__from__=talkingdev)</sup><sup> • </sup><sup>[5](https://pytorch.org/blog/introducing-executorch-1-0/)</sup><sup> • </sup><sup>[6](https://github.com/pytorch/executorch/releases)</sup> |
| 运行时占用 | 50 KB 基础运行时占用<sup>[7](https://executorch.ai/)</sup> |
| 硬件支持 | 11 个硬件后端，从 XNNPACK CPU 内核到 Qualcomm、MediaTek 和三星 NPU，Arm Ethos-U 微控制器 NPU，以及 Cadence DSP<sup>[7](https://executorch.ai/)</sup><sup> • </sup><sup>[8](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)</sup> |
| 产物 | 导出生成一个针对所选后端专门化的 `.pte` 文件；不支持的算子回退到可移植 CPU 执行<sup>[8](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)</sup> |
| 生产使用 | 在 Meta 旗下 Instagram、WhatsApp、Messenger 和 Facebook 上服务数十亿用户<sup>[2](https://engineering.fb.com/2025/07/28/android/executorch-on-device-ml-meta-family-of-apps/)</sup> |
| 治理 | PyTorch 基金会下的 PyTorch 核心项目，采用 PyTorch 的分层技术治理<sup>[3](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)</sup> |

## 历史与治理

ExecuTorch 起源于 Meta 内部的一个项目，旨在让前沿 PyTorch 模型在边缘和设备上高效运行，覆盖手机、AR/VR 头显与眼镜、嵌入式设备以及定制加速器。在 PyTorch 大会 2023 上公开亮相时，它围绕四项原则设计：从 PyTorch 编写到端侧部署的端到端开发者体验；跨 CPU、GPU、NPU、DSP 及其他加速器的可移植性；面向受限环境的小型模块化运行时；以及开源姿态。<sup>[3](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)</sup>

发布节奏依次经历了 2024 年 4 月的 alpha 版本——聚焦于将大语言模型部署到边缘和稳定 API 接口，支持 Meta 的 [Llama](https://www.edgepedia.org/zh/llama-model-family) 2 和早期 Llama 3<sup>[4](https://pytorch.org/blog/executorch-alpha/?__from__=talkingdev)</sup>；2024 年 10 月宣布的 beta 版本——稳定了开发者 API 和运行时特性<sup>[5](https://pytorch.org/blog/introducing-executorch-1-0/)</sup>；以及 1.0 版本——项目称其正式退出 beta 状态，并扩大了对多模态语言模型的支持<sup>[6](https://github.com/pytorch/executorch/releases)</sup>。最新发布系列为 v1.5，其中 v1.5.1 为补丁版本，除其他变更外，将面向 Arm 微控制器内核的 CMSIS-NN 更新至 v8.0.0。<sup>[6](https://github.com/pytorch/executorch/releases)</sup>

ExecuTorch 后来成为 PyTorch 基金会下的 PyTorch 核心项目。其陈述的理由是：多家公司希望将其作为中立的共享层进行投资；硬件供应商需要一种透明的方式来影响发展方向；项目需要超越任何单一组织的治理。它继承 PyTorch 的分层技术治理，由 PyTorch 核心维护者监督跨领域变更，模块维护者监督 ExecuTorch 特定变更。<sup>[3](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)</sup>

## 架构

**提前准备。** ExecuTorch 将部署分为提前（AOT）阶段和运行时阶段。AOT 阶段利用 PyTorch 2 编译器与导出技术，包括 TorchDynamo、AOTAutograd、量化、动态形状和控制流支持，为执行准备一个标准 `nn.Module` 程序。导出、转换和编译都在程序运行之前完成，从而保持运行时小巧、执行开销低。准备好的程序以 flatbuffer 格式序列化。<sup>[9](https://github.com/pytorch/executorch/blob/main/docs/source/getting-started-architecture.md)</sup>

**运行时。** ExecuTorch 运行时用 C++ 编写，依赖极少，以保证可移植性和执行效率。其核心组件包括平台抽象层、日志记录与可选性能分析、执行数据类型、内核与后端注册表，以及内存管理；执行器是入口点，负责加载程序并调度算子内核或后端执行。运行时可在 Linux、iOS、Android、嵌入式系统和裸机硬件上运行，几乎无需额外配置。<sup>[9](https://github.com/pytorch/executorch/blob/main/docs/source/getting-started-architecture.md)</sup> 项目给出的基础运行时占用为 50 KB。<sup>[7](https://executorch.ai/)</sup>

**选择性构建与内存规划。** 选择性构建 API 让部署工程师构建一个仅链接到程序实际使用的内核的运行时，从而在生成的应用程序中显著节省二进制大小。用户还可以提供自定义内存规划算法，例如将张量映射到嵌入式系统内存层次结构的特定层。<sup>[9](https://github.com/pytorch/executorch/blob/main/docs/source/getting-started-architecture.md)</sup> 启用非 CPU 内存规划时，规划阶段按设备类型划分张量规格，并为每个设备独立运行规划算法，生成单独的缓冲区，使设备内存与主机内存永不混合。<sup>[10](https://github.com/pytorch/executorch/blob/main/docs/source/compiler-memory-planning.md)</sup>

## 后端与委托

ExecuTorch 后端为特定目标提供硬件加速，导出与底层转换过程会针对所选后端优化模型，生成专用于该硬件的 `.pte` 文件。支持多个平台通常意味着为每个后端生成专用的 `.pte` 文件，例如 iOS 上的 [Core ML](https://www.edgepedia.org/zh/core-ml) 和 Android 上的 Arm CPU 后端。<sup>[8](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)</sup>

在创建 `.pte` 时，ExecuTorch 识别后端支持的模型分区并提前处理它们。委托后端不支持的算子通过可移植 CPU 实现回退执行，例如 XNNPACK，因此模型可以部分加速；可以按优先级顺序提供多个分区器，使得不支持的 GPU 操作回退到 CPU。<sup>[8](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)</sup> 在运行时层面，后端必须通过 `register_backend` API 注册，委托子图对运行时是不透明的，表现为特殊的 `call_delegate` 指令，请求后端执行该子图。<sup>[11](https://docs.pytorch.org/executorch/stable/compiler-delegate-and-partitioner.html)</sup>

后端表格覆盖了硬件全景：<sup>[8](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)</sup>

| 后端 | 平台 | 硬件类型 |
|---|---|---|
| XNNPACK | 所有 | CPU |
| CUDA | Linux/Windows | GPU |
| Core ML | iOS、macOS | NPU/GPU/CPU |
| Vulkan | Android、Linux、Windows | GPU |
| Qualcomm | Android | NPU |
| MediaTek | Android | NPU |
| Arm Ethos-U | 嵌入式 | NPU |
| Arm Cortex-M | 嵌入式 | CPU |
| OpenVINO | 嵌入式 | CPU/GPU/NPU |
| Cadence | 嵌入式 | DSP |
| 三星 Exynos | Android | CPU/GPU/NPU |

这些后端的加速由行业伙伴通过开源贡献，包括 XNNPACK 与 Arm Kleidi、Apple Core ML、面向 Hexagon NPU 的 Qualcomm AI Engine、Intel OpenVINO、NXP 面向汽车和物联网的 eIQ Neutron NPU，以及 Arm 的 Versatile 图形框架。<sup>[7](https://executorch.ai/)</sup>

## 生产使用与性能

Meta 已在旗下全系应用中推出 ExecuTorch，驱动 Instagram、WhatsApp、[Messenger](https://www.edgepedia.org/zh/messenger-software) 和 Facebook 上的端侧模型，服务数十亿用户。端侧部署改善了延迟，将用户数据保留在设备上，并实现离线功能。一个例子是 Instagram 的 Cutouts 功能，它将照片和视频转化为动态贴纸；Meta 将其迁移至 ExecuTorch 上运行，使用 SqueezeSAM——Segment Anything Model 的轻量版本——并报告称 ExecuTorch 在 Android 和 iOS 上均显著快于旧技术栈，转化为日活跃用户的增长。端侧场景理解模型 SceneX 在迁移后，从低端到高端设备上均显示出性能提升。<sup>[2](https://engineering.fb.com/2025/07/28/android/executorch-on-device-ml-meta-family-of-apps/)</sup>

独立基准测试表明后端选择主导结果。在搭载 [Snapdragon 8 Gen 3](https://www.edgepedia.org/zh/snapdragon-8-gen-3) 的 Galaxy S26 Ultra 上进行的一项可复现 Android 基准测试中，使用 XNNPACK 后端的 ExecuTorch 以 FP32 运行 MobileNetV3-Small，中位延迟为 0.89 毫秒，快于同一模型上 LiteRT 的 XNNPACK 后端（1.48 毫秒）和 [ONNX Runtime](https://www.edgepedia.org/zh/onnx-runtime) 的 CPU 后端（5.43 毫秒）。同一个 ExecuTorch 模型改为转换为使用可移植 CPU 内核而非 XNNPACK 后，中位延迟为 70.8 毫秒——在相同硬件上，两种 ExecuTorch 配置之间相差约 80 倍。<sup>[12](https://github.com/sangsoolee/android-edge-ai-benchmark-lab)</sup>

## 生态系统

围绕运行时构建的工具扩展了其覆盖范围。Software Mansion 维护 [React Native](https://www.edgepedia.org/zh/react-native) ExecuTorch，这是一个将 ExecuTorch 推理引入 React Native 应用的库，用于设备端 OCR 与本地语言模型串联等功能，以及完全在手机上运行的 Private Mind 助手应用。<sup>[13](https://executorch.swmansion.com/)</sup> [Hugging Face](https://www.edgepedia.org/zh/hugging-face) 提供 Optimum-ExecuTorch 用于直接部署 transformer 模型，示例涵盖导出 Llama 模型以在 Android 和 iOS 设备上运行。<sup>[7](https://executorch.ai/)</sup><sup> • </sup><sup>[14](https://android.1.googlesource.com/platform/external/executorch/%2B/28d3bc0b28d9375d346e88e4ddbaaba700638b2d/examples/README.md)</sup> 面向微控制器级设备的 ExecuTorch 后端以 NXP eIQ Neutron 和 Arm Ethos-U 等 NPU 为目标，运行在 NXP i.MX RT700 和 STMicroelectronics STM32H7 等低功耗异构平台上。<sup>[15](https://hosted-files.sched.co/pytorchconferenceeu2026/9a/Flexible%20Deployment%20of%20PyTorch%20Models%20on%20MCU-Class%20Devices.pdf)</sup>

## References

1. [ExecuTorch, PyTorch project page](https://pytorch.org/projects/executorch/)
2. [Accelerating on-device ML on Meta's family of apps with ExecuTorch, Engineering at Meta (July 28, 2025)](https://engineering.fb.com/2025/07/28/android/executorch-on-device-ml-meta-family-of-apps/)
3. [ExecuTorch Becomes a Part of PyTorch Core to Expand On-Device Inference Capabilities, PyTorch blog](https://pytorch.org/blog/executorch-becomes-part-of-pytorch-core/)
4. [ExecuTorch Alpha: Taking LLMs and AI to the Edge with Our Community and Partners, PyTorch blog](https://pytorch.org/blog/executorch-alpha/?__from__=talkingdev)
5. [Introducing ExecuTorch 1.0: Powering the next generation of edge AI, PyTorch blog](https://pytorch.org/blog/introducing-executorch-1-0/)
6. [Releases, pytorch/executorch on GitHub](https://github.com/pytorch/executorch/releases)
7. [ExecuTorch, On-Device AI Inference Powered by PyTorch](https://executorch.ai/)
8. [Backends overview, ExecuTorch documentation on GitHub](https://github.com/pytorch/executorch/blob/main/docs/source/backends-overview.md)
9. [Architecture and components, ExecuTorch documentation on GitHub](https://github.com/pytorch/executorch/blob/main/docs/source/getting-started-architecture.md)
10. [Compiler memory planning, ExecuTorch documentation on GitHub](https://github.com/pytorch/executorch/blob/main/docs/source/compiler-memory-planning.md)
11. [Understanding Backends and Delegates, ExecuTorch 1.5 documentation](https://docs.pytorch.org/executorch/stable/compiler-delegate-and-partitioner.html)
12. [android-edge-ai-benchmark-lab, GitHub repository by Sangsoo Lee](https://github.com/sangsoolee/android-edge-ai-benchmark-lab)
13. [React Native ExecuTorch, Software Mansion](https://executorch.swmansion.com/)
14. [ExecuTorch examples README, Android platform source mirror](https://android.1.googlesource.com/platform/external/executorch/%2B/28d3bc0b28d9375d346e88e4ddbaaba700638b2d/examples/README.md)
15. [Flexible Deployment of PyTorch Models on MCU-Class Devices, PyTorch Conference EU](https://hosted-files.sched.co/pytorchconferenceeu2026/9a/Flexible%20Deployment%20of%20PyTorch%20Models%20on%20MCU-Class%20Devices.pdf)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Deep learning software and hardware › Edge and mobile deep learning

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/executorch

English original: https://www.edgepedia.org/executorch
