[RFC] Ship the ExecuTorch C++ SDK as a standalone archive with each release, starting with 1.6.0

未關閉
#24,816 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
cmake, docker, github-actions, python

研究方向

Start with the existing C++ SDK test at .ci/scripts/wheel/test_cpp_sdk.py and the release workflow pattern in build-cmsis-pack.yml; the RFC also identifies the published 1.6.0 wheels as the archive source. First determine how those workflows build and verify wheel contents, then map the plan's archive, platform and release requirements onto them. Done means release archives are attached and a test consumes each unpacked archive without Python on PATH, including the stated oldest supported systems.

由索引模型根據 Issue 內容生成。

描述

Summary

ExecuTorch already builds a C++ SDK (headers, shared libraries and a CMake package) for Linux, macOS and Windows, but ships it only inside the Python wheels. This RFC proposes attaching that SDK to each GitHub release as a plain archive per platform, with a stated platform contract and a test that consumes it the way a native user does. A C++ developer then downloads one file and points CMake at it, with no Python involved.

No new build is needed. Each archive is the include/, lib/ and share/cmake/ tree from a published wheel, plus license notices, a manifest and a checksum. So the first step is small: create the v1.6.0 GitHub release and attach archives repacked from the published 1.6.0 wheels.

The problem

Many people only want to run a .pte model, not export one: C++ desktop apps, services in small containers, embedded Linux devices and robots (often with no Python on the device), and bindings for other languages. Today they either install the full Python package or build ExecuTorch themselves:

  • The Rust bindings ask every user to build ExecuTorch first.
  • anira builds and hosts its own static ExecuTorch libraries for desktop targets. The Flutter bindings host their own native builds for desktop and mobile in executorch_native.
  • #10888 asks for an ExecuTorch server program and prebuilt binaries on GitHub releases. #16685 asks for a vcpkg port.

The wheels do contain the SDK, the C++ guide (using-executorch-cpp.md) documents using it, and the wheel CI already builds and runs C++ programs against it. What is missing for native users:

  • A file meant for them. Today it is a Python wheel: on Linux the PyPI default is the CUDA 13.2 build, and its metadata pins torch==2.15.0, so pip install executorch pulls PyTorch and the CUDA runtime even for a C++ app that needs neither.
  • One stated contract: supported platforms, CMake, glibc and C++ runtime versions, what is inside, third-party license notices, and a manifest of how it was built.
  • A check that the SDK works when unpacked on a machine with no Python, and on the oldest supported system.

For comparison, ONNX Runtime attaches SDK archives (headers, shared library, CMake and pkg-config files) to each GitHub release. The ROS 2 package onnxruntime_vendor builds on them: it downloads the upstream archive for the right architecture (ONNX Runtime 1.24.3).

What this unblocks

  • C++ apps and Docker images: one download, no Python, no PyTorch.
  • Robots on ROS 2: the executorch_vendor package proposed in ros2/rosidl_buffer_backends#36 today downloads the pinned +cpu wheel (SHA-256 checked) and unpacks only its C++ part. With archives it would download a file made for C++, with a stated platform contract, the way onnxruntime_vendor downloads ONNX Runtime's archive.
  • Small control policies in C++: reinforcement-learning policies (walking, balance, simple grasping) are tiny networks that run hundreds of times a second inside a C++ control loop. Such a policy fully delegated to XNNPACK needs only a few MB of ExecuTorch libraries. Today getting them means installing a Python wheel that pins PyTorch.
  • Bindings in other languages (Rust, Flutter, and others) can download the archive at build time instead of building ExecuTorch, if they can link shared libraries. Bindings that link static libraries today would need changes.

Proposal: the SDK archive

Files (attached to the GitHub release and mirrored on download.pytorch.org, each with a .sha256 file next to it):

executorch-<ver>-linux-x86_64.tar.gz
executorch-<ver>-linux-aarch64.tar.gz
executorch-<ver>-macos-arm64.tar.gz
executorch-<ver>-windows-x86_64.zip
executorch-<ver>-linux-x86_64-cu132.tar.gz
executorch-<ver>-linux-aarch64-cu132.tar.gz
executorch-<ver>-windows-x86_64-cu132.zip

Layout: one top folder named after the archive (for example executorch-1.6.0-linux-aarch64/), holding the same tree as inside today's wheels:

include/                 C++ headers
lib/                     shared libraries (.so, .dylib, .dll with .lib import libraries)
lib/cmake/executorch/    CMake package
share/cmake/             same CMake package (it locates the SDK root through this folder)
backends/cuda/           CUDA archives only (data/lib/ on Windows): the AOTInductor shim library, loaded at run time
LICENSE, THIRD-PARTY-NOTICES
manifest.json            version, git commit, source wheel and its SHA-256, minimum OS, glibc and C++ runtime

Components:

Component Linux x86_64 Linux aarch64 macOS arm64 Windows x86_64
runtime, threadpool ✅ ✅ ✅ ✅
kernels_optimized, kernels_quantized ✅ ✅ ✅ ✅
backend_xnnpack (CPU) ✅ ✅ ✅ ✅
etdump (profiling) ✅ ✅ ✅ ✖️
kernels_torchao ✖️ ✅ ✅ ✖️
backend_coreml, backend_mlx (+ mlx.metallib) ✖️ ✖️ ✅ ✖️
backend_cuda (-cu132 archives) ✅ ✅ ✖️ ✅

The CPU archives come from the +cpu wheels (Linux and Windows) and the macOS wheel. The -cu132 archives come from the CUDA 13.2 wheels and add the CUDA backend.

The Arm VGF backend is not in the table: in the wheels it is built into the Python extension, not into a library of its own, so a repacked archive cannot carry it. C++ users who need it would need it built as a separate library first.

Requirements, stated in the README and the manifest:

Platform Requirements
all CMake 3.28+ for the executorch:: targets. CMake 3.19 to 3.27 works through the EXECUTORCH_* variables. C++17 (C++20 on Windows); the targets set this for you.
Linux glibc 2.28+, libstdc++ from GCC 7+ (the 1.6.0 libraries need GLIBCXX_3.4.22 and CXXABI_1.3.11)
macOS macOS 14+
Windows MSVC, Release builds, and the latest Visual C++ 2015-2022 Redistributable (x64) on the target machine
CUDA archives an NVIDIA driver for CUDA 13. On Linux, also the CUDA 13 runtime (libcudart.so.13), findable at link time and run time; it is not bundled. On Windows, the 1.6.0 CUDA libraries import no cudart64_13.dll and use the runtime that comes with the driver (found by inspecting the binaries; the archive test in step 4 should confirm it). On Linux, deploy backends/cuda/libaoti_cuda_shims.so next to the app's other libraries.

On macOS, document the signing and notarization policy, and check a downloaded archive on a clean Mac.

How people use it

C++ app on Linux (on macOS use the macos-arm64 archive):

curl -LO https://github.com/pytorch/executorch/releases/download/v1.6.0/executorch-1.6.0-linux-aarch64.tar.gz
tar xf executorch-1.6.0-linux-aarch64.tar.gz
cmake -S . -B build -DCMAKE_PREFIX_PATH="$PWD/executorch-1.6.0-linux-aarch64"
cmake --build build
cmake_minimum_required(VERSION 3.28)
project(app CXX)
find_package(executorch REQUIRED COMPONENTS kernels_optimized backend_xnnpack)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE executorch::runtime
                                  executorch::kernels_optimized
                                  executorch::backend_xnnpack)

main.cpp and its small model.pte are the example from the C++ guide (export the model once, on any machine with Python). The build machine needs no Python and no pip.

Windows: the same CMake file, plus this step from the C++ guide, which copies the required DLLs next to the program:

add_custom_command(TARGET app POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_if_different
          $<TARGET_RUNTIME_DLLS:app> $<TARGET_FILE_DIR:app>
  COMMAND_EXPAND_LISTS)

Embedded Linux device: build on the device, or cross-compile with a toolchain whose sysroot has glibc 2.28 or newer. Copy the program and the libraries it links into one folder, with INSTALL_RPATH $ORIGIN. A model fully delegated to XNNPACK needs only the runtime, XNNPACK and thread pool libraries, a few MB; the optimized CPU kernels add more.

ROS 2: a vendor package downloads the archive for the right architecture, verifies a pinned SHA-256, and exports the ExecuTorch CMake targets.

Plan

  1. Create the v1.6.0 tag and GitHub release (PyPI has had 1.6.0 since 2026-11-04; the newest tag is v1.6.0-rc4, the commit inside the published wheels).
  2. Build archives for 1.6.0 from the published wheels, test them (step 4), attach them to the release, and mirror them on download.pytorch.org. Repacking has to rewrite each library's search path (RUNPATH): in the wheels they point at ../../nvidia/cu13/lib and ../src/executorch/lib, which do not exist in an archive.
  3. Add a workflow that builds and attaches the archives when a release is published, the way build-cmsis-pack.yml does for the CMSIS pack.
  4. Extend the C++ SDK test (.ci/scripts/wheel/test_cpp_sdk.py, which already builds programs against the wheel and runs them after moving them) to run against each unpacked archive with no Python on PATH. On Linux, also run it on the oldest supported glibc; on Windows, on a machine without Visual Studio.
  5. Add a "Download the C++ SDK" section to the C++ guide, including the CUDA deployment note above.

What this promises, and what it does not

  • The named platforms above, each tested. Others (Android NDK, macOS x86_64, Windows on Arm, armv7, musl) keep the source build. Android and iOS app developers already have prebuilt packages (the AAR on Maven Central and the Swift Package).
  • An app and the SDK should come from the same release. This RFC does not propose a stable binary interface across releases.
  • Source builds stay supported for selective builds, custom operators and microcontrollers.

Alternatives considered

  • Only document wheel extraction. It works and should be documented. But users still get a Python-shaped file, the CUDA build as the Linux default, and no stated contract or archive test.
  • Package managers first (vcpkg, conda-forge, Homebrew). Their recipe authors build from source, which today needs PyTorch build inputs (see related work, item 2). The archive and its manifest help them as a reference.
  • A stable C API first. It reduces C++ ABI (binary interface) constraints and helps bindings, but it is a large design. Same-release C++ archives serve most users now.

Related work, each needing its own design

  1. Running a .pte from Python without PyTorch, for Python apps that pin their own torch, such as robot learning frameworks. #24820 now proposes dropping the PyTorch requirement from executorch and loading the CUDA backend on demand, instead of a separate runtime package.
  2. A source build without full PyTorch. Kernel registration needs torchgen and PyTorch's operator list files, and the optimized kernels need PyTorch headers. When torchgen is missing, the lookup in tools/cmake/Codegen.cmake fails silently and the build then scans the whole file system for *.py files; and the source folder must be named executorch (#6475).
  3. Backends as plugins. Backends register themselves through a static initializer when their library loads (see register_backend in backends/xnnpack/runtime/XNNPACKBackend.cpp), so an app can load one at run time with dlopen. A supported version needs a public load call, a build check before registration, a reported result for failed registration, and thread-safety rules. Today the registry has 16 fixed slots, and a failed or duplicate registration is dropped silently. Out-of-tree backends, such as the TensorRT delegate in Torch-TensorRT, already depend on this.

Open questions

  1. Repack the wheel's libraries as they are (unversioned names like libexecutorch.so, quickest), or build the archive with the versioned library names that tools/cmake/Utils.cmake already defines for distribution packages (libexecutorch.so.1)? Out-of-tree delegates, such as the TensorRT delegate that Torch-TensorRT ships, link the unversioned names, so those names should stay, for example as symlinks.
  2. Include the OpenVINO and QNN adapters that some CPU wheels ship? They need vendor runtimes from elsewhere.
  3. Archives for nightlies too, and how long to keep them?
  4. CUDA 13.4 archives too? The 1.6.0 release also has cu134 wheels.
  5. libaoti_cuda_shims.so is not a CMake target on Linux. Should it become one, so CUDA apps deploy it the same way as the other libraries?
主要語言
Python
星號
5.2k
分支
1.3k
平均合併
1 天 7 小時
30 天內合併 PR
644

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。