ExecuTorch deployment on Android

ExecuTorch is the supported PyTorch deployment route for mobile devices; PyTorch Mobile is no longer actively supported. Mobile applications use on-device inference for several practical reasons:

  • interactive features can avoid a network round trip, leading to lower latency
  • inference can continue without a reliable connection being required
  • private inputs can remain on the device
  • applications can use the CPU, GPU, or neural processing unit (NPU) already present in the device, rather than placing additional load on datacenters
  • the energy usage occurs on-device, rather than in datacenters

Phones have constraints similar to other edge devices. A mobile application shares memory, storage, battery power, and thermal capacity with the operating system and other applications. Model size, startup time, inference latency, runtime footprint, and library dependencies all matter.

Although this module focuses on mobile, the principles are largely the same across other handheld devices, such as tablets, smartwatches, and notebooks, that use Android or iOS.

Python remains part of the workflow when moving from Edge Linux to mobile. The ahead-of-time stages remain largely unchanged: prepare, export, quantize, lower, and validate the model on the development machine. The output is still a .pte artifact. The main change is the application that wraps around it at runtime. Once the model has been prepared, it can be used by application code written in Java, Kotlin or C++, just as it could be used by application code written in Python or C++ on Edge Linux devices.

Android terminology used in this module

Before moving further, familiarize yourself with some potentially new terminology:

TermMeaning in this module
JavaThe application language used to load the model, create tensors, call ExecuTorch, and update the UI
Kotlin DSLThe syntax used by the .gradle.kts build files; these files are not Kotlin application source
GradleThe Android build and dependency system
Maven CentralThe package repository from which Gradle downloads the ExecuTorch Android library
AARAn Android library archive containing the ExecuTorch Java API and native runtime libraries
JNIThe Java Native Interface that connects Java calls to the native C++ ExecuTorch runtime
ABIA native binary target, such as arm64-v8a for Arm phones or x86_64 for an emulator
Android assetA read-only file packaged inside the application
App-private storageWritable storage owned by the app; the packaged .pte is copied here before loading
ActivityThe Android component that owns the application screen and receives lifecycle events
Main threadThe thread responsible for UI events and drawing; model work runs on a background executor
APKAn installable Android application package
Android App BundleA publishing format used to produce device-specific APKs
Android SDKAndroid APIs, platform tools, and build tools
JDKThe Java compiler and runtime used by Gradle

The application source in this module is Java. Files ending in .gradle.kts use the Kotlin DSL, or domain-specific language, to configure Gradle. They are build files rather than Kotlin application source files.

For more detail about ExecuTorch usage within Android, see the official documentation ExecuTorch with Android .

Previous page Complete and continue