The ExecuTorch Android Java API lets you run PyTorch models on Android devices using a simple Java or Kotlin interface.

ExecuTorch is PyTorch's solution for on-device AI — from smartphones to microcontrollers. The Java API wraps the native ExecuTorch runtime and gives you clean Java classes to load models, build tensors, and run inference.

Quick Start

Add the library to your app:

// app/build.gradle.kts
dependencies {
    implementation("org.pytorch:executorch-android:${executorch_version}")
}

Load a model and run inference:

import org.pytorch.executorch.EValue;
import org.pytorch.executorch.Module;
import org.pytorch.executorch.Tensor;

// Load your exported .pte model
Module module = Module.load("/data/local/tmp/model.pte");

// Create an input tensor (1x3x224x224 image)
float[] data = new float[1 * 3 * 224 * 224];
Tensor input = Tensor.fromBlob(data, new long[]{1, 3, 224, 224});

// Run inference
EValue[] output = module.forward(EValue.from(input));
float[] scores = output[0].toTensor().getDataAsFloatArray();

Packages

org.pytorch.executorch Core API. Contains Module to load and run models, Tensor for tensor operations, and EValue to wrap inputs and outputs.
org.pytorch.executorch.extension.llm LLM extension. Contains LlmModule for running large language models like Llama with streaming token generation.
org.pytorch.executorch.annotations API annotations. Experimental marks APIs that may change in future releases.

Resources