ExecuTorch

Introduction

ExecuTorch is PyTorch’s on-device inference runtime. In Zephyr, it can be integrated as an external module to run models on CPU and Arm Ethos-U NPUs.

If you are new to ExecuTorch, these resources are a great place to start learning:

ExecuTorch is licensed under the BSD 3-Clause License.

Usage with Zephyr

This section covers ExecuTorch module registration, model preparation, and build/run steps for both CPU and Arm Ethos-U NPU targets.

Note

Prerequisites

  • Python 3.12–3.13 — required by ExecuTorch tooling. Use a separate virtual environment, or a Zephyr virtual environment created with a compatible Python version.

  • Arm FVPs — only required if you are targeting a Corstone FVP (e.g. mps3/corstone300/fvp) to simulate Cortex-M and the Ethos-U NPU without physical hardware. See Installing Arm FVPs for installation steps.

  • Docker (macOS only) — required only for the Arm Ethos-U NPU Inference flow via FVPs-on-Mac.

Installing ExecuTorch

Step 1: Register ExecuTorch as an external module by adding the following project entry to your west manifest. You can either create a dedicated submanifest file at zephyrproject/zephyr/submanifests/executorch.yaml, or add it directly to your application’s existing west.yml:

manifest:
  projects:
    - name: executorch
      url: https://github.com/pytorch/executorch
      revision: v1.2.0
      path: modules/lib/executorch
      submodules: true

Step 2: Run west update:

west update

Step 3: Install ExecuTorch and dependencies:

Note

Run these commands inside your Zephyr virtual environment with a compatible Python version (3.12–3.13).

pip install executorch==1.2.0
pip install tosa-tools==2026.2.1
pip install ethos-u-vela==5.0.0

Build and run

When running AI models on embedded devices, your target hardware may include a dedicated AI accelerator — commonly called an NPU (Neural Processing Unit). Arm provides the Ethos-U NPU family for efficient on-device AI inference. The tabs below cover both paths: targeting an Ethos-U NPU for accelerated inference, and CPU-only inference for devices without an NPU.

Note

Installing Arm FVPs

Fixed Virtual Platforms (FVPs) are Arm-provided simulators that let you run Zephyr without physical hardware. They are required here to emulate Ethos-U55/U65/U85 accelerators via the Corstone-300 reference platform.

Step 1: Download the FVP installer for Corstone-300 from the Arm FVP page. FVPs can be installed anywhere on your machine — they do not need to be inside the Zephyr project directory.

Arm Corstone FVPs

Note

FVP version numbers change with each release. Set the filename and URL to the version you want from the Arm downloads page.

FVP_TGZ="FVP_Corstone_SSE-300_11.27_42_Linux64_armv8l.tgz"
FVP_URL="https://developer.arm.com/-/cdn-downloads/permalink/FVPs-Corstone-IoT/Corstone-300/${FVP_TGZ}"
curl -L -o "${FVP_TGZ}" "${FVP_URL}"

Step 2: Unpack the downloaded archive:

tar -xf "${FVP_TGZ}"

Step 3: Run the installation script:

./FVP_Corstone_SSE-300.sh --i-agree-to-the-contained-eula --no-interactive -q

Step 4: Add the FVPs to your PATH. Both FVP_Corstone_SSE-300_Ethos-U55 and FVP_Corstone_SSE-300_Ethos-U65 live in the same directory:

export PATH=$HOME/FVP_Corstone_SSE-300/models/Linux64_armv8l_GCC-9.3:$PATH

Step 5: Install the required runtime dependency (libpython3.9.so.1.0) by sourcing the provided script. The method differs slightly between shells:

bash:

source $HOME/FVP_Corstone_SSE-300/scripts/runtime.sh
unset PYTHONHOME

zsh: BASH_SOURCE must be set manually before sourcing, as zsh does not populate it automatically:

BASH_SOURCE=$HOME/FVP_Corstone_SSE-300/scripts/runtime.sh
source $HOME/FVP_Corstone_SSE-300/scripts/runtime.sh
unset PYTHONHOME

Step 6: Verify the installation:

FVP_Corstone_SSE-300_Ethos-U55 --version
FVP_Corstone_SSE-300_Ethos-U65 --version

Prepare the Ethos-U55 PTE model

In ExecuTorch, a .pte file is a serialized program file and the final binary format used to deploy PyTorch models to edge and mobile devices. For guidance on exporting and lowering your own PyTorch models with the Arm Ethos-U backend, see Using ExecuTorch Export.

The model used here is a minimal add model that takes two tensors and adds them element-wise. It exists purely to verify that the full ExecuTorch workflow is working correctly — from model compilation through to on-device inference via the Ethos-U NPU. The expected output is that each element equals 2 + 2 = 4.

From the Zephyr root (for example ~/zephyrproject), run:

cd ~/zephyrproject
python -m modules.lib.executorch.examples.arm.aot_arm_compiler \
  --model_name=modules/lib/executorch/examples/arm/example_modules/add.py \
  --quantize --delegate -t ethos-u55-128 --output=add_u55_128.pte

--delegate tells aot_arm_compiler to use the Ethos-U backend and -t ethos-u55-128 selects the Ethos-U variant and MAC count. These must match your hardware or FVP configuration.

Build and Run

From the Zephyr root (~/zephyrproject), run:

cd ~/zephyrproject
west build -p auto -b mps3/corstone300/fvp \
  modules/lib/executorch/zephyr/samples/hello-executorch \
  -t run -- -DET_PTE_FILE_PATH=add_u55_128.pte

Expected Run Output

I [executorch:arm_executor_runner.cpp:450 main()] Model executed successfully.
I [executorch:arm_executor_runner.cpp:457 main()] Model outputs:
I [executorch:arm_executor_runner.cpp:464 main()]   output[0]: tensor scalar_type=Float numel=5
I [executorch:arm_executor_runner.cpp:481 main()]     [0] = 4.000000
I [executorch:arm_executor_runner.cpp:481 main()]     [1] = 4.000000
I [executorch:arm_executor_runner.cpp:481 main()]     [2] = 4.000000
I [executorch:arm_executor_runner.cpp:481 main()]     [3] = 4.000000
I [executorch:arm_executor_runner.cpp:481 main()]     [4] = 4.000000
I [executorch:arm_executor_runner.cpp:499 main()] SUCCESS: Program complete, exiting.

The output values of 4.000000 confirm that the model ran successfully on-device, each element is the result of 2 + 2, computed by the Ethos-U NPU or CPU backend via ExecuTorch.

ExecuTorch on Zephyr is actively being developed, and more complex and interesting sample applications are on the way. You can follow progress and find new samples here: ExecuTorch Zephyr samples.

Reference