litert google tensor
Compiles LiteRT (.tflite) models ahead-of-time for Google Tensor TPUs (Tensor G5 on Pixel 10, Tensor G6 on Pixel 11) locally on Linux x86_64 or on Google Colab (--colab on macOS, Windows, or ARM hosts), benchmarks them on a USB-attached Pixel with LiteRT's benchmark_model (NPU latency, peak memory, TPU tile time, TPU energy, optional CPU baseline), and packages compiled models for an Android Gradle app as a Google Play AI pack with the Tensor NPU runtime module and a Kotlin loader, applies it to
Documentation & Preview
--- name: litert-google-tensor description: >- Compiles LiteRT (.tflite) models ahead-of-time for Google Tensor TPUs (Tensor G5 on Pixel 10, Tensor G6 on Pixel 11) locally on Linux x86_64 or on Google Colab (--colab on macOS, Windows, or ARM hosts), benchmarks them on a USB-attached Pixel with LiteRT's benchmark_model (NPU latency, peak memory, TPU tile time, TPU energy, optional CPU baseline), and packages compiled models for an Android Gradle app as a Google Play AI pack with the Tensor NPU runtime module and a Kotlin loader, applies it to the app and verifies it on a Pixel. Use when the user asks to compile, AOT-compile, or prepare a .tflite model for the Pixel TPU/NPU, check whether a .tflite is already Tensor-compiled, measure on-device NPU performance of a compiled model, or package or deploy a compiled model into their Android app (or replace the one it ships). Don't use for Qualcomm, MediaTek, or Samsung NPUs, GPU-only benchmarking, LiteRT-LM or LLM (.litertlm) models, on-device JIT compilation, non-Gradle builds, or publishing to Google Play. metadata: version: "1.0.0" category: AiAndMachineLearning
---
LiteRT on Google Tensor: compile, benchmark, package for apps
Three scriptable workflows for Pixel TPUs:
- Compile a plain
.tfliteinto a Google Tensor AOT-compiled.tflite
with the public LiteRT Python API (ai_edge_litert.aot), locally on Linux x86_64 or on a Google Colab VM (--colab, via google-colab-cli) when the user is on macOS/Windows or lacks a Linux box.
- Benchmark a compiled model on a connected Pixel with LiteRT's
benchmark_model, NPU-only, optionally next to a CPU baseline, including TPU tile time (pure TPU compute time) and TPU energy per inference.
- Package compiled builds for an Android (Gradle) app as a Google Play AI
pack with the Google Tensor NPU runtime and a Kotlin loader (or, for an app that already ships Google Tensor builds, only the files to replace), apply the plan to the project when the user agrees, and check the app on a Pixel.
Everything runs synchronously in the user's terminal; the scripts never start background processes and always clean up what they pushed to the phone or allocated on Colab. All paths below are relative to this skill's directory (SKILL_DIR).
Path | Purpose
---- | ------- assets/versions.json | LiteRT versions the scripts use (single source) scripts/check_compiled.py | Is this .tflite already Tensor-compiled? scripts/compile_model.py | AOT compile (local Linux x86_64 or --colab) scripts/benchmark_on_device.py | adb push -> benchmark -> parse -> cleanup scripts/package_ai_pack.py | Compiled builds -> AI pack + Gradle modules for an app, or an update of one scripts/install_and_verify.py | Build the app, install it like Google Play, read the NPU/CPU result assets/templates/ | Gradle, Kotlin, INTEGRATION.md and UPDATE.md templates (package_ai_pack.py) references/compile-flags.md | API, compiler flags, script options, --colab references/benchmark-flags.md | What the benchmark runs, binaries, writing the report, example output references/app-integration.md | Packaging for an app: contents, checks, delivery modes, applying the plan, checking on a Pixel references/troubleshooting.md | Symptom -> fix tables references/contributing.md | Maintainers: adopting a new LiteRT release
Every script supports --help and --dry-run and is Python 3 standard library only, so it runs with any python3, with two exceptions that import LiteRT: a local compile (compile_model.py without --colab, --dry-run or --print-install) must use the virtualenv's interpreter (<venv>/bin/python SKILL_DIR/scripts/compile_model.py ..., or activate the venv first), and a real package_ai_pack.py run (not --dry-run or --check-project) needs a Python with ai-edge-litert (the compile venv works; the Beta SDK is not needed).
Prerequisites (tell the user up front)
| Need | Compile (local) | Compile (--colab) | Benchmark | Package (app) | |---|---|---|---|---| | Google Tensor SDK Beta access - sign up at https://services.google.com/fb/forms/tensor_ml_sdk_experimental_access (overview: https://developers.google.com/edge/litert/next/tensor-sdk). Google emails a download link for litert_plugin_compiler.tar.gz; the compiler cannot be installed without it. | required | required (--sdk-tarball or --sdk-url) | - | - | | Host OS | Linux x86_64, >= 16 GB RAM | any OS (colab CLI on PATH; runs on a remote Colab Linux x86_64 VM) | any OS with adb | any OS where ai-edge-litert installs (the compile venv's Linux x86_64 host works) | | Python environment | Local venv with ai-edge-litert + ai-edge-litert-sdk-google-tensor at the version in versions.json (compile_model.py --print-install) | Any local python3 + google-colab-cli (compile_model.py --print-install --colab); SDK is installed on the Colab VM automatically | any python3 (stdlib only) | a Python with ai-edge-litert (the compile venv works; the SDK package is not needed) | | adb on PATH, Pixel 10/11 with USB debugging enabled | - | - | required | step 7 (install and check the app) | | A JDK the app's Gradle supports (JAVA_HOME), the Android SDK, the project's ./gradlew | - | - | - | steps 6-7 (build, install); bundletool is downloaded once | | libLiteRtDispatch_GoogleTensor.so - downloaded automatically from the public LiteRT binaries bucket (same directory as benchmark_model), or supplied with --dispatch-lib | - | - | required | - (the app gets it from Google Maven) | | Internet | once for pip install | required (Colab VM + pip install) | once to fetch benchmark_model + dispatch lib (cached in ~/.cache/litert-google-tensor/) unless supplied locally | - (the app's Gradle build downloads the LiteRT Maven artifacts) |
Supported targets: Tensor_G5 (Pixel 10 family) and Tensor_G6 (Pixel 11 family), as listed by the public Tensor SDK docs; Pixel 9 and older are not.
Step 0 - Collect parameters
Ask the user only for what is missing; never invent values:
Parameter | How to get it
----------------------------------- | ------------- Model path | Absolute path to the .tflite. Confirm it exists. Goal | check only, compile only, benchmark only, compile + benchmark, or package for an app (step 5). Infer it from the request ("how fast is it on the TPU vs CPU" = compile if needed + benchmark with a CPU baseline; "put it in my app" / "deploy it" = package); do not add an unrequested device run. Target SoC | For a compile, the user's stated device wins (Pixel 10 family = Tensor_G5, Pixel 11 family = Tensor_G6), even if a different Pixel is attached. For a benchmark, the attached phone decides: adb shell getprop ro.soc.model -> Tensor G5 => Tensor_G5, Tensor G6 => Tensor_G6 (the benchmark script reads and enforces this itself). Output path | Default <output-dir>/<stem>_Google_<target>.tflite. compile_model.py refuses to overwrite an existing file (exit 2): run check_compiled.py on the existing file and reuse it, or pass --output-name, or --overwrite after asking. When a second build is needed next to an existing one, name it <stem>_Google_<target>.<YYYYMMDD-HHMM>.tflite (e.g. --output-name model_Google_Tensor_G5.20260107-0930.tflite) or, for a flag variant, <stem>_Google_<target>.<flag-summary>.tflite (...G5.half-maxsharding.tflite); keep the _Google_<target> part so the file stays recognisable. Device serial | Only if adb devices lists more than one device. Dispatch library / benchmark binary | Optional. Both are downloaded automatically from the same public bucket directory and cached. Only ask if the user wants a specific build, or if the host is offline: then --benchmark-bin <benchmark_model> plus --dispatch-lib <libLiteRtDispatch_GoogleTensor.so \| dir \| .zip \| .aar> (also env LITERT_GOOGLE_TENSOR_DISPATCH_LIB) use local copies and no network is touched. CPU baseline | Optional; needs the path of the original uncompiled model (ask for it if only a compiled file was given; the benchmark script rejects a compiled file here with exit 2). Run counts / mode | Defaults 5 warmup / 50 measured, burst performance mode. benchmark_model treats counts as minimums and also runs at least 0.5 s warmup / 1 s measured, so fast models execute more runs than requested. If the user states exact counts, say so and ask whether to disable the floors (--extra-arg=--min_secs=0 --extra-arg=--warmup_min_secs=0); "steady-state" / "sustained" requests map to --performance-mode sustained_performance. TPU tile time | On by default, nothing to ask: a second, hooked NPU pass. --no-tile-time turns it off; the hooked pass itself (it repeats the NPU run, so slow models take about twice as long) is skipped only with --no-tile-time --no-power. TPU energy | On by default, nothing to ask: the power metric of the same hooked pass (the TPU rail's energy per inference). --no-power skips it. The script leaves it off, and says why, for a dispatch library whose power hook predates the fix. Compile mode | Local Linux x86_64 by default. Use --colab when the host is not Linux x86_64 (macOS/Windows/ARM) or when the user asks to compile on Google Colab; ask for the Beta tarball path (--sdk-tarball / GOOGLE_TENSOR_SDK_BETA) or URL (--sdk-url / GOOGLE_TENSOR_ML_SDK_URL) before running. Compiler flags | Default to the compiler defaults; only set flags the user asks for or that troubleshooting requires (see references/compile-flags.md). App deployment level | Packaging jobs only; nothing to ask up front. After step 5, tell the user the plan is ready (INTEGRATION.md, or UPDATE.md for an update) and ask whether you should apply it to their project (step 6). After that, offer to install the app on their Pixel and check it uses the NPU (step 7). New integration or update | Packaging jobs only. Ask whether the app already ships Google Tensor builds (an AI pack with folders like model#group_Google_Tensor_G5 under its src/main/assets). If it does, it is an update (step 5b): ask for the project root (the folder with settings.gradle.kts or settings.gradle). The pack, model file, device groups, delivery mode and app module then come from the project, so do not ask for them. Builds to package | One compiled build per target SoC (Tensor_G5, Tensor_G6) plus the original uncompiled model they were compiled from (the app's CPU path). Compile missing targets first (step 2); a build is per SoC, so a Pixel 11 needs a Tensor_G6 build. For an update, build every SoC the app already ships. Delivery mode | New integrations only (an update keeps the app's). When Google Play puts the model on the phone: install-time (default; installed with the app, ready at first launch), fast-follow (downloaded right after install) or on-demand (downloaded when the app asks). Explain each in one sentence (references/app-integration.md) and use the default when the user has no preference. Pack / model names, app module | New integrations only. Defaults: pack name = the original's file name made