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:
| Term | Meaning in this module |
|---|---|
| Java | The application language used to load the model, create tensors, call ExecuTorch, and update the UI |
| Kotlin DSL | The syntax used by the .gradle.kts build files; these files are not Kotlin application source |
| Gradle | The Android build and dependency system |
| Maven Central | The package repository from which Gradle downloads the ExecuTorch Android library |
| AAR | An Android library archive containing the ExecuTorch Java API and native runtime libraries |
| JNI | The Java Native Interface that connects Java calls to the native C++ ExecuTorch runtime |
| ABI | A native binary target, such as arm64-v8a for Arm phones or x86_64 for an emulator |
| Android asset | A read-only file packaged inside the application |
| App-private storage | Writable storage owned by the app; the packaged .pte is copied here before loading |
| Activity | The Android component that owns the application screen and receives lifecycle events |
| Main thread | The thread responsible for UI events and drawing; model work runs on a background executor |
| APK | An installable Android application package |
| Android App Bundle | A publishing format used to produce device-specific APKs |
| Android SDK | Android APIs, platform tools, and build tools |
| JDK | The 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 .
Course complete
Nice work
You completed Optimize and deploy AI inference with ExecuTorch on Arm.