A literal Rust re-implementation of the
ExecuTorch on-device inference
runtime: it loads .pte programs exported by the (unchanged, Python)
ExecuTorch ahead-of-time pipeline and executes them on CPU, including the
XNNPACK delegate. The port covers the runtime core (platform layer, core
types, EValue, program/method executor), the portable, quantized and
optimized CPU kernels, the data-loader/module/tensor extensions, and the
XNNPACK backend with the vendored C library built from source.
This repository contains:
crates/executorch/— the Rust port (single crate; the module tree mirrors the upstream C++ tree one-to-one).crates/executorch-macros/— the#[et_kernel]proc-macro that replaces the upstreamfunctions.yamlregistration codegen with link-time kernel registration.docs/spec/port/— the behavioral specification (per-symboldef/semrules) that pins the port to the C++ behavior of upstream ExecuTorch, which served as the porting reference (pinned toec52125f1cinplan/main.styx).docs/port/rust-conventions.md— the conventions the port was built under.third-party/— the vendored XNNPACK build dependencies (git submodules), used only with thexnnpackfeature.
The port is complete and in production use (it powers divvun-speech text-to-speech). It was built in three waves:
- Spec — a per-symbol behavioral spec (
def+semrules) extracted from the C++, underdocs/spec/port/. - Literal port — every symbol translated 1:1 (bug-for-bug) into a matching Rust module, one module per C++ file.
- Tests — the upstream C++ test suite ported absolutely: 3,040 passing tests pinning the spec, including the documented C++ quirks.
There is deliberately no idiomatization pass: the literal port is the
maintained form, so a reviewer can diff any Rust module against its C++
source file line by line. Deviations from the C++ (pure-Rust substitutions
for Eigen/pocketfft/sleef, the proc-macro registration seam, trait objects
for virtual interfaces) are marked DEVIATION/PORT-NOTE in place and
catalogued in docs/port/rust-conventions.md.
[dependencies]
executorch = { path = "crates/executorch", features = ["xnnpack"] }use executorch::extension::module::module::{LoadMode, Module};
executorch::backends::xnnpack::register(); // once, with the xnnpack feature
let mut module = Module::from_file_path("model.pte", LoadMode::File, None, None, None, false)?;
let outputs = module.forward(inputs)?;Kernel registration is explicit: call kernels::optimized::register() (which
also registers the portable set) and/or backends::xnnpack::register() at
startup, depending on how the .pte was exported.
cargo test # portable runtime + kernels, no C deps
git submodule update --init third-party/XNNPACK third-party/cpuinfo \
third-party/pthreadpool third-party/FP16 third-party/FXdiv
cargo test --features xnnpack # builds the vendored XNNPACK via cmakeFeature flags: xnnpack (delegate + vendored C build), event-tracer,
profiling-enabled, bundled-program, aten, android, zephyr (PAL
variants).
BSD-3-Clause, matching upstream ExecuTorch (see LICENSE).