[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M741CFQ1NJXT0DDNA847HAK8":3,"skill-same:01M741CFQ1NJXT0DDNA847HAK8":136},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":6,"ownerHtmlUrl":32,"ownerBlogUrl":33,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M741CFQ1NJXT0DDNA847HAK8","litert-google-tensor",null,"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\u002FNPU, 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.","google\u002Fskills","google","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1342004?v=4","01M698VYEFDM0VJBZDYYJ2T83S","Google","01M698WR0H76ENHE587T9EJT89",24235,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: litert-google-tensor\ndescription: >-\n  Compiles LiteRT (.tflite) models ahead-of-time for Google Tensor TPUs\n  (Tensor G5 on Pixel 10, Tensor G6 on Pixel 11) locally on Linux x86_64 or\n  on Google Colab (--colab on macOS, Windows, or ARM hosts),\n  benchmarks them on a USB-attached Pixel with LiteRT's benchmark_model\n  (NPU latency, peak memory, TPU tile time, TPU energy, optional CPU baseline),\n  and packages compiled models for an Android Gradle app as a Google Play AI\n  pack with the Tensor NPU runtime module and a Kotlin loader, applies it to\n  the app and verifies it on a Pixel. Use when the\n  user asks to compile, AOT-compile, or prepare a .tflite model for the Pixel\n  TPU\u002FNPU, check whether a .tflite is already Tensor-compiled, measure\n  on-device NPU performance of a compiled model, or package or deploy a\n  compiled model into their Android app (or replace the one it ships). Don't\n  use for Qualcomm, MediaTek, or Samsung NPUs, GPU-only benchmarking,\n  LiteRT-LM or LLM (.litertlm) models, on-device JIT compilation, non-Gradle\n  builds, or publishing to Google Play.\nmetadata:\n  version: \"1.0.0\"\n  category: AiAndMachineLearning\n---\n\n# LiteRT on Google Tensor: compile, benchmark, package for apps\n\nThree scriptable workflows for Pixel TPUs:\n\n1.  **Compile** a plain `.tflite` into a Google Tensor AOT-compiled `.tflite`\n    with the public LiteRT Python API (`ai_edge_litert.aot`), locally on Linux\n    `x86_64` or on a Google Colab VM (`--colab`, via `google-colab-cli`) when\n    the user is on macOS\u002FWindows or lacks a Linux box.\n2.  **Benchmark** a compiled model on a connected Pixel with LiteRT's\n    `benchmark_model`, NPU-only, optionally next to a CPU baseline, including\n    TPU tile time (pure TPU compute time) and TPU energy per inference.\n3.  **Package** compiled builds for an Android (Gradle) app as a Google Play AI\n    pack with the Google Tensor NPU runtime and a Kotlin loader (or, for an app\n    that already ships Google Tensor builds, only the files to replace), apply\n    the plan to the project when the user agrees, and check the app on a Pixel.\n\nEverything runs synchronously in the user's terminal; the scripts never start\nbackground processes and always clean up what they pushed to the phone or\nallocated on Colab. All paths below are relative to this skill's directory\n(`SKILL_DIR`).\n\nPath | Purpose\n---- | -------\n[assets\u002Fversions.json](assets\u002Fversions.json) | LiteRT versions the scripts use (single source)\n[scripts\u002Fcheck_compiled.py](scripts\u002Fcheck_compiled.py) | Is this `.tflite` already Tensor-compiled?\n[scripts\u002Fcompile_model.py](scripts\u002Fcompile_model.py) | AOT compile (local Linux `x86_64` or `--colab`)\n[scripts\u002Fbenchmark_on_device.py](scripts\u002Fbenchmark_on_device.py) | adb push -> benchmark -> parse -> cleanup\n[scripts\u002Fpackage_ai_pack.py](scripts\u002Fpackage_ai_pack.py) | Compiled builds -> AI pack + Gradle modules for an app, or an update of one\n[scripts\u002Finstall_and_verify.py](scripts\u002Finstall_and_verify.py) | Build the app, install it like Google Play, read the NPU\u002FCPU result\n[assets\u002Ftemplates\u002F](assets\u002Ftemplates\u002F) | Gradle, Kotlin, `INTEGRATION.md` and `UPDATE.md` templates (`package_ai_pack.py`)\n[references\u002Fcompile-flags.md](references\u002Fcompile-flags.md) | API, compiler flags, script options, `--colab`\n[references\u002Fbenchmark-flags.md](references\u002Fbenchmark-flags.md) | What the benchmark runs, binaries, writing the report, example output\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md) | Packaging for an app: contents, checks, delivery modes, applying the plan, checking on a Pixel\n[references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md) | Symptom -> fix tables\n[references\u002Fcontributing.md](references\u002Fcontributing.md) | Maintainers: adopting a new LiteRT release\n\nEvery script supports `--help` and `--dry-run` and is Python 3 standard library\nonly, so it runs with any `python3`, with two exceptions that import LiteRT: a\nlocal compile (`compile_model.py` without `--colab`, `--dry-run` or\n`--print-install`) must use the virtualenv's interpreter\n(`\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fcompile_model.py ...`, or activate the\nvenv first), and a real `package_ai_pack.py` run (not `--dry-run` or\n`--check-project`) needs a Python with `ai-edge-litert` (the compile venv\nworks; the Beta SDK is not needed).\n\n## Prerequisites (tell the user up front)\n\n| Need | Compile (local) | Compile (`--colab`) | Benchmark | Package (app) |\n|---|---|---|---|---|\n| **Google Tensor SDK Beta access** - sign up at https:\u002F\u002Fservices.google.com\u002Ffb\u002Fforms\u002Ftensor_ml_sdk_experimental_access (overview: https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Ftensor-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`) | - | - |\n| 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) |\n| 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) |\n| `adb` on PATH, Pixel 10\u002F11 with USB debugging enabled | - | - | required | step 7 (install and check the app) |\n| A JDK the app's Gradle supports (`JAVA_HOME`), the Android SDK, the project's `.\u002Fgradlew` | - | - | - | steps 6-7 (build, install); bundletool is downloaded once |\n| `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) |\n| Internet | once for `pip install` | required (Colab VM + `pip install`) | once to fetch `benchmark_model` + dispatch lib (cached in `~\u002F.cache\u002Flitert-google-tensor\u002F`) unless supplied locally | - (the app's Gradle build downloads the LiteRT Maven artifacts) |\n\nSupported targets: `Tensor_G5` (Pixel 10 family) and `Tensor_G6` (Pixel 11\nfamily), as listed by the public Tensor SDK docs; Pixel 9 and older are not.\n\n## Step 0 - Collect parameters\n\nAsk the user only for what is missing; never invent values:\n\nParameter                           | How to get it\n----------------------------------- | -------------\nModel path                          | Absolute path to the `.tflite`. Confirm it exists.\nGoal                                | 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\" \u002F \"deploy it\" = package); do not add an unrequested device run.\nTarget 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).\nOutput path                         | Default `\u003Coutput-dir>\u002F\u003Cstem>_Google_\u003Ctarget>.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 `\u003Cstem>_Google_\u003Ctarget>.\u003CYYYYMMDD-HHMM>.tflite` (e.g. `--output-name model_Google_Tensor_G5.20260107-0930.tflite`) or, for a flag variant, `\u003Cstem>_Google_\u003Ctarget>.\u003Cflag-summary>.tflite` (`...G5.half-maxsharding.tflite`); keep the `_Google_\u003Ctarget>` part so the file stays recognisable.\nDevice serial                       | Only if `adb devices` lists more than one device.\nDispatch library \u002F 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 \u003Cbenchmark_model>` plus `--dispatch-lib \u003ClibLiteRtDispatch_GoogleTensor.so \\| dir \\| .zip \\| .aar>` (also env `LITERT_GOOGLE_TENSOR_DISPATCH_LIB`) use local copies and no network is touched.\nCPU 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).\nRun counts \u002F mode                   | Defaults 5 warmup \u002F 50 measured, `burst` performance mode. `benchmark_model` treats counts as **minimums** and also runs at least 0.5 s warmup \u002F 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\" \u002F \"sustained\" requests map to `--performance-mode sustained_performance`.\nTPU 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`.\nTPU 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.\nCompile mode                        | Local Linux `x86_64` by default. Use `--colab` when the host is not Linux `x86_64` (macOS\u002FWindows\u002FARM) or when the user asks to compile on Google Colab; ask for the Beta tarball path (`--sdk-tarball` \u002F `GOOGLE_TENSOR_SDK_BETA`) or URL (`--sdk-url` \u002F `GOOGLE_TENSOR_ML_SDK_URL`) before running.\nCompiler flags                      | Default to the compiler defaults; only set flags the user asks for or that troubleshooting requires (see [references\u002Fcompile-flags.md](references\u002Fcompile-flags.md)).\nApp 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).\nNew 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\u002Fmain\u002Fassets`). 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.\nBuilds 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.\nDelivery 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\u002Fapp-integration.md](references\u002Fapp-integration.md#delivery-modes-asked-in-step-0)) and use the default when the user has no preference.\nPack \u002F model names, app module      | New integrations only. Defaults: pack name = the original's file name made valid, model name = pack name, app module `app`, Kotlin package `com.example.litert`. Ask only when the user's project differs (another app module name, their package).\nQuick test (optional)               | New integrations only. Offer it when the user wants to try the model on their own Pixel before setting up bundletool: `--quick-test` adds a copy of each build and the steps for `.\u002Fgradlew installDebug -PtensorQuickTest=\u003CSoC>`, which puts the build and the NPU runtime in the debug APK. Local testing only; release builds are unaffected.\n\n## Commands or a plan only (the user says not to run anything)\n\nRun nothing - not even the read-only scripts - and give the same steps as a\nreal run, in the same order, as commands the user can paste:\n\n1.  Start with `check_compiled.py` on every input model (step 1), **before**\n    any install or compile command; checking only the compiled output\n    afterwards is not enough.\n2.  For installs, give `python3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py\n    --print-install [--colab]` as the command that produces them (step 2a),\n    then the lines it prints with the user's paths filled in (venv,\n    `export GOOGLE_TENSOR_SDK_BETA=\u003Ctheir tarball>` before `pip install`) and\n    each version written as `\u003Cversion printed by --print-install>`. Never\n    copy a version number from `versions.json` or from memory.\n3.  Give no results, not even estimates: latency, speed-up, memory and ops\n    offloaded come only from the scripts' output. Say where they will appear\n    (for a benchmark, the table `benchmark_on_device.py` prints and saves as\n    `report.md`).\n4.  When the plan changes the user's app project (step 6), say that nothing\n    in the project changes until they approve, and end by asking whether you\n    should apply it.\n\n## Step 1 - Check whether the model is already compiled\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fcheck_compiled.py \u002Fabs\u002Fpath\u002Fmodel.tflite [--expect-target Tensor_G5]\n```\n\nRun it on every model file involved (the model to compile or benchmark, the\nCPU-baseline file, and an existing output file you are about to reuse). For a\nbenchmark job read the phone first (`adb shell getprop ro.soc.model` prints\n`Tensor G5` or `Tensor G6`) and pass the underscore form as `--expect-target`\n(`Tensor G5` -> `--expect-target Tensor_G5`), so one check answers both\n\"compiled?\" and \"for this phone?\" (a plain model exits 1 either way); the\nbenchmark script enforces the match again anyway (exit 4).\n\n| Exit | Meaning | Next action |\n|---|---|---|\n| 0 | compiled for Google Tensor (SoC printed) | skip compile; report the SoC (and the `Compile info` line if a `.compile.json` sidecar exists). Continue to step 3 only if the goal includes a benchmark. No sidecar (compiled elsewhere, flags unknown): for a plain \"how fast is it\" job, benchmark the file as-is and say \"compile flags unknown\"; when the user needs to know how it was built (or wants a reproducible comparison), compile the original with the defaults under a new `--output-name` and compare SHA-256 (`sha256sum` of both files, or `output_sha256` in the new sidecar): compilation is deterministic, so an identical hash proves the existing file is a default build ([references\u002Fcompile-flags.md](references\u002Fcompile-flags.md)). Never `--overwrite` to find out. |\n| 1 | plain (uncompiled) model | go to step 2 if compiling; this is the correct file for `--cpu-baseline` |\n| 2 | compiled for a different SoC than `--expect-target` | compiled models are SoC-specific (a `Tensor_G5` file never runs on a `Tensor_G6` TPU, and a `Tensor_G6` file never runs on a `Tensor_G5` TPU; there is no runtime fallback, and `--allow-mismatch` only produces dispatch errors). Tell the user which SoC the phone has, then offer, in this order: an existing `*_Google_\u003Cphone target>.tflite` build of the same model in the project (verify it with this check first; do not benchmark it unless the user says so), attaching the matching phone, or recompiling the **original** uncompiled export for the phone's target. |\n| 3 | not a `.tflite` \u002F missing | fix the path |\n| 4 | compiled by another toolchain: an Edge TPU custom op (`edgetpu-custom-op...`) instead of LiteRT's `DISPATCH_OP` | not usable here: LiteRT cannot recompile it or run it on the Google Tensor TPU, and the CPU cannot run it (so it is no `--cpu-baseline` or `--fallback` either; the scripts refuse it). Ask for the original model it was compiled from and compile that (step 2) |\n\nThe `LiteRtStamp` is authoritative (the `_Google_Tensor_G5` suffix is only a\nnaming convention) and records the SoC but **not** the compiler flags: those\ncome from the `\u003Cmodel>.compile.json` sidecar that `compile_model.py` writes\nnext to its output; without it, say \"flags unknown\" rather than guessing.\n\n## Step 2 - Compile (Linux x86_64 or Google Colab via `--colab`)\n\n### 2a. One-time environment\n\nThe SDK pip package contains no compiler by itself: at install time it unpacks\nthe Beta tarball that `GOOGLE_TENSOR_SDK_BETA` points to (same flow as the\npublic codelab). Ask the user for the tarball path first, then print the\ninstall commands for the LiteRT version the skill pins in `versions.json`:\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py --print-install [--colab]\n```\n\n**Local Linux `x86_64`** (`--print-install`): runs with any `python3` and prints\ncomment lines (the pinned version, when and on what it was last verified, the\nsupported Python range, and whether this host and Python qualify) followed by:\n\n```text\npython3 -m venv ~\u002F.venvs\u002Flitert-tensor && source ~\u002F.venvs\u002Flitert-tensor\u002Fbin\u002Factivate\npip install --upgrade pip\nexport GOOGLE_TENSOR_SDK_BETA=\u002Fabs\u002Fpath\u002Flitert_plugin_compiler.tar.gz   # from the Beta e-mail\npip install --no-cache-dir ai-edge-litert==\u003Cpinned> ai-edge-litert-sdk-google-tensor==\u003Cpinned>\n```\n\n**Remote Google Colab** (`--print-install --colab`) - for macOS, Windows,\nnon-x86 Linux, or when compiling on Colab without a local Linux venv: installs\n`google-colab-cli` into `~\u002F.venvs\u002Fcolab-cli`\n([how `--colab` works](references\u002Fcompile-flags.md#compiling-on-google-colab---colab)).\nNever ask the user to run a terminal command for OAuth: when `--colab` needs\none-time OAuth, show its printed URL in chat, ask the user for the code, and\nre-run with `--colab-auth-code \u003CCODE>`.\n\n*   Tell the user before installing anything. Run the printed commands with the\n    real tarball path and never type a LiteRT version yourself: the runtime and\n    SDK packages must be one version (`WARNING` when they differ; `NOTE` when\n    they match each other but not the pin). Use `-nightly` packages only when\n    the user explicitly asks for nightlies.\n*   If `--print-install` warns about the Python version, create the venv with\n    a `python3.N` in the supported range. Install errors:\n    [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md#environment-and-install).\n\n**If the user has no Beta access yet:** say so plainly - the compiler cannot be\ninstalled until Google e-mails the tarball link (sign-up form above) - and do\nnot install anything or allocate a Colab VM meanwhile (`--colab` checks for the\ntarball before `colab new`). Still useful now: run `check_compiled.py` on their\nfiles, confirm the host and phone SoC, and run `--dry-run` \u002F `--print-install`.\n\n### 2b. Compile\n\n```bash\n# Local Linux x86_64 (using the virtualenv's interpreter):\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  --target Tensor_G5 --output-dir \u002Fabs\u002Fpath\u002Fcompiled\n\n# Remote Google Colab VM (any OS, any local python3 + google-colab-cli):\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  --target Tensor_G5 --colab --sdk-tarball \u002Fabs\u002Fpath\u002Flitert_plugin_compiler.tar.gz \\\n  --output-dir \u002Fabs\u002Fpath\u002Fcompiled\n# -> \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite\n```\n\nThe script prints the compilation report, re-verifies the Tensor stamp, writes\n`\u003Coutput>.compile.json` (flags, ops offloaded \u002F total, package versions,\nSHA-256s) and never overwrites an existing output (exit 2) unless\n`--overwrite` is given. Ops left on the CPU in the report mean the strict NPU\nbenchmark will fail (step 3, `--allow-cpu-fallback`). Every compiler, script\nand Colab option: [references\u002Fcompile-flags.md](references\u002Fcompile-flags.md).\n\n*   If the compiler crashes with an internal error - or the user reports that it\n    did with the defaults (no need to reproduce the crash) - use\n    `--truncation-type half --sharding-intensity maximum` (public FAQ guidance)\n    and tell the user which flags produced the artifact. `half` changes the\n    numerics (16-bit floats on the TPU), so tell the user to validate the\n    model's outputs against the original before relying on it.\n*   Report a compile-only job from the script's output and sidecar only:\n\n    ```markdown\n    **Compiled:** \u003Coutput path> (\u003Cbytes from \"Compiled model written to\" line>)\n    **Target \u002F flags:** \u003Ccli_flags from the sidecar, or \"--target X (compiler defaults)\">\n    **Ops offloaded:** \u003CN \u002F M from the \"Ops offloaded to the TPU\" line>\n    **LiteRT:** \u003C\"packages\" from the sidecar, plus the script's WARNING\u002FNOTE line if it printed one>\n    **Verified:** check_compiled.py -> \u003Cits Status line>\n    ```\n\nExit codes: 0 ok, 2 bad input, 3 already compiled, 4 unsupported host,\n5 LiteRT packages or Beta compiler library missing (message includes the\ninstall fix), 6 compile failed (compiler log errors are printed),\n7 output verification failed.\n\n## Step 3 - Benchmark on the device\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fbenchmark_on_device.py \\\n  --model \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--cpu-baseline \u002Fabs\u002Fpath\u002Fmodel.tflite] [--serial SERIAL] \\\n  [--dispatch-lib \u002Fabs\u002Fpath\u002FlibLiteRtDispatch_GoogleTensor.so] \\\n  [--output-dir \u002Fabs\u002Fpath\u002Fresults]\n```\n\nThe script refuses a model compiled for another SoC than the phone's (exit 4;\n`--dry-run` never contacts the phone, so it proves nothing about the match),\nfetches `benchmark_model` and `libLiteRtDispatch_GoogleTensor.so` once from the\nbucket release in `versions.json` (cached; `downloaded from \u003Curl>` means a\nfirst download - tell the user what was fetched), runs the strict NPU\nbenchmark, a second hooked NPU pass for TPU tile time and TPU energy, and the\noptional CPU baseline on the **uncompiled** model in a fresh\n`\u002Fdata\u002Flocal\u002Ftmp\u002Flitert_benchmark\u002Frun-*` directory, which it deletes even on\nfailure. It writes `report.md`, `results.json` and the logs to `--output-dir`\n(nothing after exit 2\u002F3\u002F4 or `--dry-run`). Each step and flag:\n[references\u002Fbenchmark-flags.md](references\u002Fbenchmark-flags.md#what-the-script-does).\n\nThe script is NPU-only by design (`--extra-arg` cannot switch the accelerator,\nand an uncompiled model is rejected with exit 2); GPU or non-Tensor runs\n(`benchmark_model --use_gpu=true` etc. directly) are outside this skill. Other\noptions (`--num-runs`, `--performance-mode`, `--signature`,\n`--allow-cpu-fallback`, `--no-tile-time`, `--no-power`, ...) are in `--help`.\n\n*   **Offline host:** pass both `--benchmark-bin` and `--dispatch-lib`; a\n    `--dry-run` then shows `user-provided: \u003Cpath>` for both binaries without\n    touching the phone or the network - the proof the user wants first.\n*   **Binary versions:** keep `benchmark_model` and the dispatch library from\n    the **same** bucket release (the default does; `--benchmark-url\n    ...\u002Fbinaries\u002F\u003Crelease>\u002Fandroid_arm64\u002Fbenchmark_model` pins another one and\n    the dispatch URL follows). If a provenance md5 differs from\n    `verified.binaries` in `versions.json`, rerun with `--refresh-binary`\n    ([details](references\u002Fbenchmark-flags.md#choosing-binary-versions)).\n\n## Step 4 - Report\n\nNothing in the report is typed by hand. `benchmark_on_device.py` prints a\nMarkdown header + table (also saved as `report.md` and as the `markdown` field\nof `results.json`) in which every value is read from the device or the run.\nPaste that block verbatim and add only the context the script cannot know:\n\n```markdown\n**Summary:** \u003CNPU \"Inference avg\" from the table> ms on the TPU vs \u003CCPU \"Inference avg\"> ms on the CPU (\u003Cthe N.NNx value from the script's \"NPU speed-up vs CPU\" line>); peak memory \u003CNPU> vs \u003CCPU> MB; \u003Cstrict NPU | CPU fallback allowed>. TPU tile time \u003C\"TPU tile time \u002F inference\" row> ms per inference. TPU energy \u003C\"TPU energy \u002F inference\" row> mJ per inference.\n\n\u003Cheader and table exactly as printed by benchmark_on_device.py, including any \"Unexpected log lines\" section>\n\n**Notes:** \u003Cwhat the Log check line reports: \"none\" when both logs show 0 unexpected lines and no profiler retry; otherwise each unexpected line with its meaning from references\u002Fbenchmark-flags.md or troubleshooting.md, plus anything the user should validate>\n```\n\nWhen nothing ran (check exit 2, benchmark exit 2\u002F3\u002F4\u002F5, no device), report\nthe same way - from output, not from memory:\n\n```markdown\n**Not run:** \u003Cthe script's ERROR line verbatim>\n\n- Device: \u003Cthe \"Device: ...\" line printed by benchmark_on_device.py, or the `adb devices -l` line>\n- Model: \u003Cthe \"Status: ...\" line from check_compiled.py>\n- Nothing was pushed to or removed from the phone.\n\n**Options:** \u003Cthe next actions from step 1 \u002F troubleshooting, most specific first>\n```\n\n*   NEVER type, round, or \"tidy up\" numbers, and NEVER reuse values from an\n    earlier run or from any example in this skill - copy the script output.\n    Prose numbers (the Summary line) must be character-for-character the\n    table's values. Never edit `report.md` (script output); if the user wants\n    the answer saved, write `summary.md` next to it.\n*   Before writing the Summary and Notes, read\n    [Writing the report](references\u002Fbenchmark-flags.md#writing-the-report)\n    (no CPU baseline, combined compile + benchmark jobs, run counts, CPU\n    fallback, mixed LiteRT releases, speed-up below 1x, TPU tile time\u002Fenergy).\n\n## Step 5 - Package for an app (Gradle)\n\nTwo cases (Step 0, \"New integration or update\"); what the package contains and\nhow the script checks it: [references\u002Fapp-integration.md](references\u002Fapp-integration.md).\n\n*   **5a - New integration:** an AI pack written by LiteRT's own exporter from\n    the files as they are (byte-identical, nothing recompiled), the Google\n    Tensor NPU runtime as an install-time feature module (from Google Maven),\n    the original model for the app's CPU path, a Kotlin loader, and an\n    `INTEGRATION.md` with every remaining step for the user's project.\n*   **5b - Update** (the app already ships Google Tensor builds):\n    `--update-project` only reads the project and prepares the files to\n    replace, under the app's own paths and names, plus an `UPDATE.md`.\n\n```bash\n# 5a -> \u003Cfallback dir>\u002Fapp_package\u002F\u003Cpack name>\u002FINTEGRATION.md and the modules\n\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py \\\n  --compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G6.tflite] \\\n  --fallback \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  [--delivery install-time|fast-follow|on-demand] [--pack-name NAME] \\\n  [--model-name NAME] [--app-module app] [--kotlin-package com.example.litert] \\\n  [--quick-test] [--output-dir \u002Fabs\u002Fpath\u002Fapp_package\u002FNAME]\n\n# 5b -> \u003Cfallback dir>\u002Fapp_update\u002F\u003Cpack>\u002FUPDATE.md, update.json, files\u002F\u003Cpaths>\n\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py \\\n  --update-project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n  --compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G6.tflite] \\\n  --fallback \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  [--pack-name NAME] [--model-name NAME] [--cpu-asset PATH|none]\n```\n\n1.  Run `check_compiled.py` on every file first (step 1), and package builds\n    that passed the strict benchmark (step 3).\n2.  Run with `--dry-run` first (any `python3`), then for real with a Python\n    that has `ai-edge-litert`. The script refuses mismatched inputs and never\n    replaces a directory it did not write.\n3.  For 5b, show the user the verdict and the file list: `drop-in` (only\n    model files change), `structural` (`UPDATE.md` section 2 lists the other\n    changes; list them and ask how to proceed before anything else) or\n    `up-to-date`. A `Runtime` check of `device` means the new builds must pass\n    the strict benchmark with the app's own runtime library first (`UPDATE.md`\n    section 4).\n4.  Paste the script's `**Packaged:** ...` or `**Update plan:** ...` block\n    verbatim, add one line (the delivery mode or the verdict in plain words,\n    and \"next: `\u003Coutput-dir>\u002FINTEGRATION.md`\" or `UPDATE.md`), then ask: \"The\n    integration plan is ready (`INTEGRATION.md`). Do you want me to apply it\n    to your project?\" (or \"The update plan is ready (`UPDATE.md`). ...\"). If\n    yes, go to step 6. Publishing to Google Play stays with the user.\n\nExit codes: 0 ok, 2 bad input (missing file, duplicate SoC, invalid name,\noutput exists, a build that differs from its sidecar, or a project\n`--update-project` cannot update as is), 3 wrong model kind (uncompiled\n`--compiled`, compiled `--fallback`), 5 LiteRT not importable or its exporter\nAPI changed (the message has the fix), 7 post-export verification failed\n(nothing is left at `--output-dir`).\n\n## Step 6 - Apply the plan to the user's project (when they say yes)\n\nYou apply the plan; the user approves it once. Before changing anything,\nshow the **whole plan** and get **one approval**. Then ask **separately** for\neach risky item (the check marks them): upgrading the Android Gradle plugin\nor Kotlin, adding Kotlin, raising `minSdk`, limiting the app to arm64-v8a\n(devices without it can no longer install the app), changing the app's\nLiteRT version, replacing project files that differ from the package,\nremoving a SoC. A declined item is skipped; say what will not work without\nit.\n\n*   **6a - New integration:** the plan is the `fail` items of a read-only check\n    (any `python3`, no LiteRT), each with its fix:\n\n    ```bash\n    python3 SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py --check-project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n      --package \u003Coutput-dir of step 5a> [--app-module app] [--json]\n    ```\n\n*   **6b - Update:** the plan is `UPDATE.md` (the file table and section 2).\n\nFollow the procedure in\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md#applying-the-plan-skillmd-step-6)\n(backups, edits merged in the project's own style, re-check, one build). Never\ndelete or reformat unrelated code, and never touch signing configs.\n\n## Step 7 - Install and check on a Pixel (when the user agrees)\n\nBuilds the user's app, installs it on the attached Pixel the way Google Play\nwould (bundletool local testing, for the phone's device group), and reads\nthe loader's `LITERT_TENSOR_RESULT` line:\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Finstall_and_verify.py --project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n  [--app-module app] [--variant debug|release|\u003Cflavor>Debug] [--serial \u003Cid>] \\\n  [--uninstall-first] [--dry-run]\n```\n\nRun `--dry-run` first: it shows the phone, its device group and whether the\nNPU path is expected. Exit 7 means the app is already installed and local\ntesting cannot update it: ask the user (uninstalling deletes the app's data on\nthe phone), then rerun with `--uninstall-first`. The app must call\n`TensorModelLoader.load()`; if it loads the model on a particular screen, tell\nthe user to open it while the script waits. Report the script's block\nverbatim: `\"path\":\"npu\"` is the pass; for `\"path\":\"cpu\"` on a phone the app\nhas a build for, the `npu_error` says why. Requirements and exit codes:\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md#checking-on-a-pixel-skillmd-step-7).\n\n## Rules\n\n*   ALWAYS run `check_compiled.py` before compiling or benchmarking, on every\n    model file involved - the compiler cannot recompile a compiled model, and\n    the TPU cannot run an uncompiled one.\n*   ALWAYS verify the device SoC matches the model's stamp (the benchmark\n    script does) - a `Tensor_G5` model on a `Tensor_G6` phone fails with an\n    opaque dispatch error, wasting a debugging round.\n*   ALWAYS use the original uncompiled model for `--cpu-baseline` - compiled\n    models contain `DISPATCH_OP` nodes that only the NPU can execute.\n*   ALWAYS clean up the per-run device directory (automatic; after an\n    interrupted run list the base first, then remove only its `run-*` entries:\n    `adb shell ls -la \u003Cbase>` and `adb shell rm -rf \u003Cbase>\u002Frun-*`, where\n    `\u003Cbase>` is `\u002Fdata\u002Flocal\u002Ftmp\u002Flitert_benchmark` or the `--device-dir` that\n    was used). NEVER `rm -rf` the base directory itself - users keep their own\n    binaries and models there.\n*   NEVER combine `--use_cpu=true` with `--require_full_delegation=true` -\n    `benchmark_model` aborts on that combination.\n*   NEVER install packages into the system interpreter or without telling the\n    user; use a virtualenv so pinned LiteRT versions do not break other work.\n*   NEVER type LiteRT version numbers into install commands or download URLs\n    yourself - take them from `compile_model.py --print-install` and the\n    scripts' default URLs, which all read `versions.json`, so every job uses the\n    pair that was verified together. Use another release only when the user\n    asks for one (`--benchmark-url`, or the pip pair at that version), and say\n    so in the report. Changing the pin is a maintainer task\n    ([references\u002Fcontributing.md](references\u002Fcontributing.md)).\n*   NEVER treat macOS, Windows, or ARM hosts as a compile blocker or give manual\n    browser Colab notebook steps - run `compile_model.py --colab` directly.\n*   NEVER leave adb, benchmark, or Colab VM sessions running in the background -\n    every command here is bounded by a timeout and returns before the next step\n    (`compile_model.py --colab` stops any Colab VM it creates unless\n    `--keep-colab-session` is passed).\n*   NEVER guess compile flags or overwrite an existing output without asking\n    (`compile_model.py` exits 2; use `--output-name` or ask before\n    `--overwrite`).\n*   ALWAYS package for an app with `package_ai_pack.py` (it calls LiteRT's\n    exporter and verifies the result), and with `--update-project` (step 5b)\n    when the app already ships Google Tensor builds; NEVER create or edit AI\n    pack folders, the device-targeting XML or the runtime modules by hand, and\n    NEVER copy a new package's `ai_packs\u002F` over an existing pack - the app's\n    group names and the place of its CPU copy can differ.\n*   ALWAYS ask before changing the user's project, show the whole plan, and\n    get one approval; ask separately for each risky item (step 6) and before\n    `install_and_verify.py --uninstall-first`. NEVER change signing configs.\n*   NEVER put a compiled build where the app runs on the CPU (base assets,\n    `--fallback`): only the original uncompiled model.\n*   NEVER publish to Google Play, sign, or upload anything for the user; the\n    skill stops at the package and the local-testing steps.\n\n## Troubleshooting\n\nEvery script error names its fix; look up the error line or exit code in\n[references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md).\n\n## Public references\n\n[LiteRT NPU guide](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Fnpu),\n[Google Tensor with LiteRT](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Ftensor-sdk),\n[compilation flags](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Fcompilation-flags),\n[Tensor SDK FAQ](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Ftensor-faqs),\n[release notes \u002F compatibility](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Frelease-notes),\n[benchmark_model](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Fbenchmark),\n[codelab](https:\u002F\u002Fcodelabs.developers.google.com\u002Fcodelabs\u002Fgoogle-tensor-ml-sdk),\n[Play for On-device AI](https:\u002F\u002Fdeveloper.android.com\u002Fgoogle\u002Fplay\u002Fon-device-ai).\n\n## Contributions\n\nTo contribute or modify this skill or its references, follow the\n[contribution guidelines](references\u002Fcontributing.md) before making changes.\n","# LiteRT on Google Tensor: compile, benchmark, package for apps\n\nThree scriptable workflows for Pixel TPUs:\n\n1.  **Compile** a plain `.tflite` into a Google Tensor AOT-compiled `.tflite`\n    with the public LiteRT Python API (`ai_edge_litert.aot`), locally on Linux\n    `x86_64` or on a Google Colab VM (`--colab`, via `google-colab-cli`) when\n    the user is on macOS\u002FWindows or lacks a Linux box.\n2.  **Benchmark** a compiled model on a connected Pixel with LiteRT's\n    `benchmark_model`, NPU-only, optionally next to a CPU baseline, including\n    TPU tile time (pure TPU compute time) and TPU energy per inference.\n3.  **Package** compiled builds for an Android (Gradle) app as a Google Play AI\n    pack with the Google Tensor NPU runtime and a Kotlin loader (or, for an app\n    that already ships Google Tensor builds, only the files to replace), apply\n    the plan to the project when the user agrees, and check the app on a Pixel.\n\nEverything runs synchronously in the user's terminal; the scripts never start\nbackground processes and always clean up what they pushed to the phone or\nallocated on Colab. All paths below are relative to this skill's directory\n(`SKILL_DIR`).\n\nPath | Purpose\n---- | -------\n[assets\u002Fversions.json](assets\u002Fversions.json) | LiteRT versions the scripts use (single source)\n[scripts\u002Fcheck_compiled.py](scripts\u002Fcheck_compiled.py) | Is this `.tflite` already Tensor-compiled?\n[scripts\u002Fcompile_model.py](scripts\u002Fcompile_model.py) | AOT compile (local Linux `x86_64` or `--colab`)\n[scripts\u002Fbenchmark_on_device.py](scripts\u002Fbenchmark_on_device.py) | adb push -> benchmark -> parse -> cleanup\n[scripts\u002Fpackage_ai_pack.py](scripts\u002Fpackage_ai_pack.py) | Compiled builds -> AI pack + Gradle modules for an app, or an update of one\n[scripts\u002Finstall_and_verify.py](scripts\u002Finstall_and_verify.py) | Build the app, install it like Google Play, read the NPU\u002FCPU result\n[assets\u002Ftemplates\u002F](assets\u002Ftemplates\u002F) | Gradle, Kotlin, `INTEGRATION.md` and `UPDATE.md` templates (`package_ai_pack.py`)\n[references\u002Fcompile-flags.md](references\u002Fcompile-flags.md) | API, compiler flags, script options, `--colab`\n[references\u002Fbenchmark-flags.md](references\u002Fbenchmark-flags.md) | What the benchmark runs, binaries, writing the report, example output\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md) | Packaging for an app: contents, checks, delivery modes, applying the plan, checking on a Pixel\n[references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md) | Symptom -> fix tables\n[references\u002Fcontributing.md](references\u002Fcontributing.md) | Maintainers: adopting a new LiteRT release\n\nEvery script supports `--help` and `--dry-run` and is Python 3 standard library\nonly, so it runs with any `python3`, with two exceptions that import LiteRT: a\nlocal compile (`compile_model.py` without `--colab`, `--dry-run` or\n`--print-install`) must use the virtualenv's interpreter\n(`\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fcompile_model.py ...`, or activate the\nvenv first), and a real `package_ai_pack.py` run (not `--dry-run` or\n`--check-project`) needs a Python with `ai-edge-litert` (the compile venv\nworks; the Beta SDK is not needed).\n\n## Prerequisites (tell the user up front)\n\n| Need | Compile (local) | Compile (`--colab`) | Benchmark | Package (app) |\n|---|---|---|---|---|\n| **Google Tensor SDK Beta access** - sign up at https:\u002F\u002Fservices.google.com\u002Ffb\u002Fforms\u002Ftensor_ml_sdk_experimental_access (overview: https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Ftensor-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`) | - | - |\n| 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) |\n| 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) |\n| `adb` on PATH, Pixel 10\u002F11 with USB debugging enabled | - | - | required | step 7 (install and check the app) |\n| A JDK the app's Gradle supports (`JAVA_HOME`), the Android SDK, the project's `.\u002Fgradlew` | - | - | - | steps 6-7 (build, install); bundletool is downloaded once |\n| `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) |\n| Internet | once for `pip install` | required (Colab VM + `pip install`) | once to fetch `benchmark_model` + dispatch lib (cached in `~\u002F.cache\u002Flitert-google-tensor\u002F`) unless supplied locally | - (the app's Gradle build downloads the LiteRT Maven artifacts) |\n\nSupported targets: `Tensor_G5` (Pixel 10 family) and `Tensor_G6` (Pixel 11\nfamily), as listed by the public Tensor SDK docs; Pixel 9 and older are not.\n\n## Step 0 - Collect parameters\n\nAsk the user only for what is missing; never invent values:\n\nParameter                           | How to get it\n----------------------------------- | -------------\nModel path                          | Absolute path to the `.tflite`. Confirm it exists.\nGoal                                | 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\" \u002F \"deploy it\" = package); do not add an unrequested device run.\nTarget 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).\nOutput path                         | Default `\u003Coutput-dir>\u002F\u003Cstem>_Google_\u003Ctarget>.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 `\u003Cstem>_Google_\u003Ctarget>.\u003CYYYYMMDD-HHMM>.tflite` (e.g. `--output-name model_Google_Tensor_G5.20260107-0930.tflite`) or, for a flag variant, `\u003Cstem>_Google_\u003Ctarget>.\u003Cflag-summary>.tflite` (`...G5.half-maxsharding.tflite`); keep the `_Google_\u003Ctarget>` part so the file stays recognisable.\nDevice serial                       | Only if `adb devices` lists more than one device.\nDispatch library \u002F 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 \u003Cbenchmark_model>` plus `--dispatch-lib \u003ClibLiteRtDispatch_GoogleTensor.so \\| dir \\| .zip \\| .aar>` (also env `LITERT_GOOGLE_TENSOR_DISPATCH_LIB`) use local copies and no network is touched.\nCPU 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).\nRun counts \u002F mode                   | Defaults 5 warmup \u002F 50 measured, `burst` performance mode. `benchmark_model` treats counts as **minimums** and also runs at least 0.5 s warmup \u002F 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\" \u002F \"sustained\" requests map to `--performance-mode sustained_performance`.\nTPU 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`.\nTPU 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.\nCompile mode                        | Local Linux `x86_64` by default. Use `--colab` when the host is not Linux `x86_64` (macOS\u002FWindows\u002FARM) or when the user asks to compile on Google Colab; ask for the Beta tarball path (`--sdk-tarball` \u002F `GOOGLE_TENSOR_SDK_BETA`) or URL (`--sdk-url` \u002F `GOOGLE_TENSOR_ML_SDK_URL`) before running.\nCompiler flags                      | Default to the compiler defaults; only set flags the user asks for or that troubleshooting requires (see [references\u002Fcompile-flags.md](references\u002Fcompile-flags.md)).\nApp 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).\nNew 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\u002Fmain\u002Fassets`). 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.\nBuilds 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.\nDelivery 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\u002Fapp-integration.md](references\u002Fapp-integration.md#delivery-modes-asked-in-step-0)) and use the default when the user has no preference.\nPack \u002F model names, app module      | New integrations only. Defaults: pack name = the original's file name made valid, model name = pack name, app module `app`, Kotlin package `com.example.litert`. Ask only when the user's project differs (another app module name, their package).\nQuick test (optional)               | New integrations only. Offer it when the user wants to try the model on their own Pixel before setting up bundletool: `--quick-test` adds a copy of each build and the steps for `.\u002Fgradlew installDebug -PtensorQuickTest=\u003CSoC>`, which puts the build and the NPU runtime in the debug APK. Local testing only; release builds are unaffected.\n\n## Commands or a plan only (the user says not to run anything)\n\nRun nothing - not even the read-only scripts - and give the same steps as a\nreal run, in the same order, as commands the user can paste:\n\n1.  Start with `check_compiled.py` on every input model (step 1), **before**\n    any install or compile command; checking only the compiled output\n    afterwards is not enough.\n2.  For installs, give `python3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py\n    --print-install [--colab]` as the command that produces them (step 2a),\n    then the lines it prints with the user's paths filled in (venv,\n    `export GOOGLE_TENSOR_SDK_BETA=\u003Ctheir tarball>` before `pip install`) and\n    each version written as `\u003Cversion printed by --print-install>`. Never\n    copy a version number from `versions.json` or from memory.\n3.  Give no results, not even estimates: latency, speed-up, memory and ops\n    offloaded come only from the scripts' output. Say where they will appear\n    (for a benchmark, the table `benchmark_on_device.py` prints and saves as\n    `report.md`).\n4.  When the plan changes the user's app project (step 6), say that nothing\n    in the project changes until they approve, and end by asking whether you\n    should apply it.\n\n## Step 1 - Check whether the model is already compiled\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fcheck_compiled.py \u002Fabs\u002Fpath\u002Fmodel.tflite [--expect-target Tensor_G5]\n```\n\nRun it on every model file involved (the model to compile or benchmark, the\nCPU-baseline file, and an existing output file you are about to reuse). For a\nbenchmark job read the phone first (`adb shell getprop ro.soc.model` prints\n`Tensor G5` or `Tensor G6`) and pass the underscore form as `--expect-target`\n(`Tensor G5` -> `--expect-target Tensor_G5`), so one check answers both\n\"compiled?\" and \"for this phone?\" (a plain model exits 1 either way); the\nbenchmark script enforces the match again anyway (exit 4).\n\n| Exit | Meaning | Next action |\n|---|---|---|\n| 0 | compiled for Google Tensor (SoC printed) | skip compile; report the SoC (and the `Compile info` line if a `.compile.json` sidecar exists). Continue to step 3 only if the goal includes a benchmark. No sidecar (compiled elsewhere, flags unknown): for a plain \"how fast is it\" job, benchmark the file as-is and say \"compile flags unknown\"; when the user needs to know how it was built (or wants a reproducible comparison), compile the original with the defaults under a new `--output-name` and compare SHA-256 (`sha256sum` of both files, or `output_sha256` in the new sidecar): compilation is deterministic, so an identical hash proves the existing file is a default build ([references\u002Fcompile-flags.md](references\u002Fcompile-flags.md)). Never `--overwrite` to find out. |\n| 1 | plain (uncompiled) model | go to step 2 if compiling; this is the correct file for `--cpu-baseline` |\n| 2 | compiled for a different SoC than `--expect-target` | compiled models are SoC-specific (a `Tensor_G5` file never runs on a `Tensor_G6` TPU, and a `Tensor_G6` file never runs on a `Tensor_G5` TPU; there is no runtime fallback, and `--allow-mismatch` only produces dispatch errors). Tell the user which SoC the phone has, then offer, in this order: an existing `*_Google_\u003Cphone target>.tflite` build of the same model in the project (verify it with this check first; do not benchmark it unless the user says so), attaching the matching phone, or recompiling the **original** uncompiled export for the phone's target. |\n| 3 | not a `.tflite` \u002F missing | fix the path |\n| 4 | compiled by another toolchain: an Edge TPU custom op (`edgetpu-custom-op...`) instead of LiteRT's `DISPATCH_OP` | not usable here: LiteRT cannot recompile it or run it on the Google Tensor TPU, and the CPU cannot run it (so it is no `--cpu-baseline` or `--fallback` either; the scripts refuse it). Ask for the original model it was compiled from and compile that (step 2) |\n\nThe `LiteRtStamp` is authoritative (the `_Google_Tensor_G5` suffix is only a\nnaming convention) and records the SoC but **not** the compiler flags: those\ncome from the `\u003Cmodel>.compile.json` sidecar that `compile_model.py` writes\nnext to its output; without it, say \"flags unknown\" rather than guessing.\n\n## Step 2 - Compile (Linux x86_64 or Google Colab via `--colab`)\n\n### 2a. One-time environment\n\nThe SDK pip package contains no compiler by itself: at install time it unpacks\nthe Beta tarball that `GOOGLE_TENSOR_SDK_BETA` points to (same flow as the\npublic codelab). Ask the user for the tarball path first, then print the\ninstall commands for the LiteRT version the skill pins in `versions.json`:\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py --print-install [--colab]\n```\n\n**Local Linux `x86_64`** (`--print-install`): runs with any `python3` and prints\ncomment lines (the pinned version, when and on what it was last verified, the\nsupported Python range, and whether this host and Python qualify) followed by:\n\n```text\npython3 -m venv ~\u002F.venvs\u002Flitert-tensor && source ~\u002F.venvs\u002Flitert-tensor\u002Fbin\u002Factivate\npip install --upgrade pip\nexport GOOGLE_TENSOR_SDK_BETA=\u002Fabs\u002Fpath\u002Flitert_plugin_compiler.tar.gz   # from the Beta e-mail\npip install --no-cache-dir ai-edge-litert==\u003Cpinned> ai-edge-litert-sdk-google-tensor==\u003Cpinned>\n```\n\n**Remote Google Colab** (`--print-install --colab`) - for macOS, Windows,\nnon-x86 Linux, or when compiling on Colab without a local Linux venv: installs\n`google-colab-cli` into `~\u002F.venvs\u002Fcolab-cli`\n([how `--colab` works](references\u002Fcompile-flags.md#compiling-on-google-colab---colab)).\nNever ask the user to run a terminal command for OAuth: when `--colab` needs\none-time OAuth, show its printed URL in chat, ask the user for the code, and\nre-run with `--colab-auth-code \u003CCODE>`.\n\n*   Tell the user before installing anything. Run the printed commands with the\n    real tarball path and never type a LiteRT version yourself: the runtime and\n    SDK packages must be one version (`WARNING` when they differ; `NOTE` when\n    they match each other but not the pin). Use `-nightly` packages only when\n    the user explicitly asks for nightlies.\n*   If `--print-install` warns about the Python version, create the venv with\n    a `python3.N` in the supported range. Install errors:\n    [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md#environment-and-install).\n\n**If the user has no Beta access yet:** say so plainly - the compiler cannot be\ninstalled until Google e-mails the tarball link (sign-up form above) - and do\nnot install anything or allocate a Colab VM meanwhile (`--colab` checks for the\ntarball before `colab new`). Still useful now: run `check_compiled.py` on their\nfiles, confirm the host and phone SoC, and run `--dry-run` \u002F `--print-install`.\n\n### 2b. Compile\n\n```bash\n# Local Linux x86_64 (using the virtualenv's interpreter):\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  --target Tensor_G5 --output-dir \u002Fabs\u002Fpath\u002Fcompiled\n\n# Remote Google Colab VM (any OS, any local python3 + google-colab-cli):\npython3 SKILL_DIR\u002Fscripts\u002Fcompile_model.py \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  --target Tensor_G5 --colab --sdk-tarball \u002Fabs\u002Fpath\u002Flitert_plugin_compiler.tar.gz \\\n  --output-dir \u002Fabs\u002Fpath\u002Fcompiled\n# -> \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite\n```\n\nThe script prints the compilation report, re-verifies the Tensor stamp, writes\n`\u003Coutput>.compile.json` (flags, ops offloaded \u002F total, package versions,\nSHA-256s) and never overwrites an existing output (exit 2) unless\n`--overwrite` is given. Ops left on the CPU in the report mean the strict NPU\nbenchmark will fail (step 3, `--allow-cpu-fallback`). Every compiler, script\nand Colab option: [references\u002Fcompile-flags.md](references\u002Fcompile-flags.md).\n\n*   If the compiler crashes with an internal error - or the user reports that it\n    did with the defaults (no need to reproduce the crash) - use\n    `--truncation-type half --sharding-intensity maximum` (public FAQ guidance)\n    and tell the user which flags produced the artifact. `half` changes the\n    numerics (16-bit floats on the TPU), so tell the user to validate the\n    model's outputs against the original before relying on it.\n*   Report a compile-only job from the script's output and sidecar only:\n\n    ```markdown\n    **Compiled:** \u003Coutput path> (\u003Cbytes from \"Compiled model written to\" line>)\n    **Target \u002F flags:** \u003Ccli_flags from the sidecar, or \"--target X (compiler defaults)\">\n    **Ops offloaded:** \u003CN \u002F M from the \"Ops offloaded to the TPU\" line>\n    **LiteRT:** \u003C\"packages\" from the sidecar, plus the script's WARNING\u002FNOTE line if it printed one>\n    **Verified:** check_compiled.py -> \u003Cits Status line>\n    ```\n\nExit codes: 0 ok, 2 bad input, 3 already compiled, 4 unsupported host,\n5 LiteRT packages or Beta compiler library missing (message includes the\ninstall fix), 6 compile failed (compiler log errors are printed),\n7 output verification failed.\n\n## Step 3 - Benchmark on the device\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Fbenchmark_on_device.py \\\n  --model \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--cpu-baseline \u002Fabs\u002Fpath\u002Fmodel.tflite] [--serial SERIAL] \\\n  [--dispatch-lib \u002Fabs\u002Fpath\u002FlibLiteRtDispatch_GoogleTensor.so] \\\n  [--output-dir \u002Fabs\u002Fpath\u002Fresults]\n```\n\nThe script refuses a model compiled for another SoC than the phone's (exit 4;\n`--dry-run` never contacts the phone, so it proves nothing about the match),\nfetches `benchmark_model` and `libLiteRtDispatch_GoogleTensor.so` once from the\nbucket release in `versions.json` (cached; `downloaded from \u003Curl>` means a\nfirst download - tell the user what was fetched), runs the strict NPU\nbenchmark, a second hooked NPU pass for TPU tile time and TPU energy, and the\noptional CPU baseline on the **uncompiled** model in a fresh\n`\u002Fdata\u002Flocal\u002Ftmp\u002Flitert_benchmark\u002Frun-*` directory, which it deletes even on\nfailure. It writes `report.md`, `results.json` and the logs to `--output-dir`\n(nothing after exit 2\u002F3\u002F4 or `--dry-run`). Each step and flag:\n[references\u002Fbenchmark-flags.md](references\u002Fbenchmark-flags.md#what-the-script-does).\n\nThe script is NPU-only by design (`--extra-arg` cannot switch the accelerator,\nand an uncompiled model is rejected with exit 2); GPU or non-Tensor runs\n(`benchmark_model --use_gpu=true` etc. directly) are outside this skill. Other\noptions (`--num-runs`, `--performance-mode`, `--signature`,\n`--allow-cpu-fallback`, `--no-tile-time`, `--no-power`, ...) are in `--help`.\n\n*   **Offline host:** pass both `--benchmark-bin` and `--dispatch-lib`; a\n    `--dry-run` then shows `user-provided: \u003Cpath>` for both binaries without\n    touching the phone or the network - the proof the user wants first.\n*   **Binary versions:** keep `benchmark_model` and the dispatch library from\n    the **same** bucket release (the default does; `--benchmark-url\n    ...\u002Fbinaries\u002F\u003Crelease>\u002Fandroid_arm64\u002Fbenchmark_model` pins another one and\n    the dispatch URL follows). If a provenance md5 differs from\n    `verified.binaries` in `versions.json`, rerun with `--refresh-binary`\n    ([details](references\u002Fbenchmark-flags.md#choosing-binary-versions)).\n\n## Step 4 - Report\n\nNothing in the report is typed by hand. `benchmark_on_device.py` prints a\nMarkdown header + table (also saved as `report.md` and as the `markdown` field\nof `results.json`) in which every value is read from the device or the run.\nPaste that block verbatim and add only the context the script cannot know:\n\n```markdown\n**Summary:** \u003CNPU \"Inference avg\" from the table> ms on the TPU vs \u003CCPU \"Inference avg\"> ms on the CPU (\u003Cthe N.NNx value from the script's \"NPU speed-up vs CPU\" line>); peak memory \u003CNPU> vs \u003CCPU> MB; \u003Cstrict NPU | CPU fallback allowed>. TPU tile time \u003C\"TPU tile time \u002F inference\" row> ms per inference. TPU energy \u003C\"TPU energy \u002F inference\" row> mJ per inference.\n\n\u003Cheader and table exactly as printed by benchmark_on_device.py, including any \"Unexpected log lines\" section>\n\n**Notes:** \u003Cwhat the Log check line reports: \"none\" when both logs show 0 unexpected lines and no profiler retry; otherwise each unexpected line with its meaning from references\u002Fbenchmark-flags.md or troubleshooting.md, plus anything the user should validate>\n```\n\nWhen nothing ran (check exit 2, benchmark exit 2\u002F3\u002F4\u002F5, no device), report\nthe same way - from output, not from memory:\n\n```markdown\n**Not run:** \u003Cthe script's ERROR line verbatim>\n\n- Device: \u003Cthe \"Device: ...\" line printed by benchmark_on_device.py, or the `adb devices -l` line>\n- Model: \u003Cthe \"Status: ...\" line from check_compiled.py>\n- Nothing was pushed to or removed from the phone.\n\n**Options:** \u003Cthe next actions from step 1 \u002F troubleshooting, most specific first>\n```\n\n*   NEVER type, round, or \"tidy up\" numbers, and NEVER reuse values from an\n    earlier run or from any example in this skill - copy the script output.\n    Prose numbers (the Summary line) must be character-for-character the\n    table's values. Never edit `report.md` (script output); if the user wants\n    the answer saved, write `summary.md` next to it.\n*   Before writing the Summary and Notes, read\n    [Writing the report](references\u002Fbenchmark-flags.md#writing-the-report)\n    (no CPU baseline, combined compile + benchmark jobs, run counts, CPU\n    fallback, mixed LiteRT releases, speed-up below 1x, TPU tile time\u002Fenergy).\n\n## Step 5 - Package for an app (Gradle)\n\nTwo cases (Step 0, \"New integration or update\"); what the package contains and\nhow the script checks it: [references\u002Fapp-integration.md](references\u002Fapp-integration.md).\n\n*   **5a - New integration:** an AI pack written by LiteRT's own exporter from\n    the files as they are (byte-identical, nothing recompiled), the Google\n    Tensor NPU runtime as an install-time feature module (from Google Maven),\n    the original model for the app's CPU path, a Kotlin loader, and an\n    `INTEGRATION.md` with every remaining step for the user's project.\n*   **5b - Update** (the app already ships Google Tensor builds):\n    `--update-project` only reads the project and prepares the files to\n    replace, under the app's own paths and names, plus an `UPDATE.md`.\n\n```bash\n# 5a -> \u003Cfallback dir>\u002Fapp_package\u002F\u003Cpack name>\u002FINTEGRATION.md and the modules\n\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py \\\n  --compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G6.tflite] \\\n  --fallback \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  [--delivery install-time|fast-follow|on-demand] [--pack-name NAME] \\\n  [--model-name NAME] [--app-module app] [--kotlin-package com.example.litert] \\\n  [--quick-test] [--output-dir \u002Fabs\u002Fpath\u002Fapp_package\u002FNAME]\n\n# 5b -> \u003Cfallback dir>\u002Fapp_update\u002F\u003Cpack>\u002FUPDATE.md, update.json, files\u002F\u003Cpaths>\n\u003Cvenv>\u002Fbin\u002Fpython SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py \\\n  --update-project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n  --compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G5.tflite \\\n  [--compiled \u002Fabs\u002Fpath\u002Fcompiled\u002Fmodel_Google_Tensor_G6.tflite] \\\n  --fallback \u002Fabs\u002Fpath\u002Fmodel.tflite \\\n  [--pack-name NAME] [--model-name NAME] [--cpu-asset PATH|none]\n```\n\n1.  Run `check_compiled.py` on every file first (step 1), and package builds\n    that passed the strict benchmark (step 3).\n2.  Run with `--dry-run` first (any `python3`), then for real with a Python\n    that has `ai-edge-litert`. The script refuses mismatched inputs and never\n    replaces a directory it did not write.\n3.  For 5b, show the user the verdict and the file list: `drop-in` (only\n    model files change), `structural` (`UPDATE.md` section 2 lists the other\n    changes; list them and ask how to proceed before anything else) or\n    `up-to-date`. A `Runtime` check of `device` means the new builds must pass\n    the strict benchmark with the app's own runtime library first (`UPDATE.md`\n    section 4).\n4.  Paste the script's `**Packaged:** ...` or `**Update plan:** ...` block\n    verbatim, add one line (the delivery mode or the verdict in plain words,\n    and \"next: `\u003Coutput-dir>\u002FINTEGRATION.md`\" or `UPDATE.md`), then ask: \"The\n    integration plan is ready (`INTEGRATION.md`). Do you want me to apply it\n    to your project?\" (or \"The update plan is ready (`UPDATE.md`). ...\"). If\n    yes, go to step 6. Publishing to Google Play stays with the user.\n\nExit codes: 0 ok, 2 bad input (missing file, duplicate SoC, invalid name,\noutput exists, a build that differs from its sidecar, or a project\n`--update-project` cannot update as is), 3 wrong model kind (uncompiled\n`--compiled`, compiled `--fallback`), 5 LiteRT not importable or its exporter\nAPI changed (the message has the fix), 7 post-export verification failed\n(nothing is left at `--output-dir`).\n\n## Step 6 - Apply the plan to the user's project (when they say yes)\n\nYou apply the plan; the user approves it once. Before changing anything,\nshow the **whole plan** and get **one approval**. Then ask **separately** for\neach risky item (the check marks them): upgrading the Android Gradle plugin\nor Kotlin, adding Kotlin, raising `minSdk`, limiting the app to arm64-v8a\n(devices without it can no longer install the app), changing the app's\nLiteRT version, replacing project files that differ from the package,\nremoving a SoC. A declined item is skipped; say what will not work without\nit.\n\n*   **6a - New integration:** the plan is the `fail` items of a read-only check\n    (any `python3`, no LiteRT), each with its fix:\n\n    ```bash\n    python3 SKILL_DIR\u002Fscripts\u002Fpackage_ai_pack.py --check-project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n      --package \u003Coutput-dir of step 5a> [--app-module app] [--json]\n    ```\n\n*   **6b - Update:** the plan is `UPDATE.md` (the file table and section 2).\n\nFollow the procedure in\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md#applying-the-plan-skillmd-step-6)\n(backups, edits merged in the project's own style, re-check, one build). Never\ndelete or reformat unrelated code, and never touch signing configs.\n\n## Step 7 - Install and check on a Pixel (when the user agrees)\n\nBuilds the user's app, installs it on the attached Pixel the way Google Play\nwould (bundletool local testing, for the phone's device group), and reads\nthe loader's `LITERT_TENSOR_RESULT` line:\n\n```bash\npython3 SKILL_DIR\u002Fscripts\u002Finstall_and_verify.py --project \u002Fabs\u002Fpath\u002Fto\u002Fapp-project \\\n  [--app-module app] [--variant debug|release|\u003Cflavor>Debug] [--serial \u003Cid>] \\\n  [--uninstall-first] [--dry-run]\n```\n\nRun `--dry-run` first: it shows the phone, its device group and whether the\nNPU path is expected. Exit 7 means the app is already installed and local\ntesting cannot update it: ask the user (uninstalling deletes the app's data on\nthe phone), then rerun with `--uninstall-first`. The app must call\n`TensorModelLoader.load()`; if it loads the model on a particular screen, tell\nthe user to open it while the script waits. Report the script's block\nverbatim: `\"path\":\"npu\"` is the pass; for `\"path\":\"cpu\"` on a phone the app\nhas a build for, the `npu_error` says why. Requirements and exit codes:\n[references\u002Fapp-integration.md](references\u002Fapp-integration.md#checking-on-a-pixel-skillmd-step-7).\n\n## Rules\n\n*   ALWAYS run `check_compiled.py` before compiling or benchmarking, on every\n    model file involved - the compiler cannot recompile a compiled model, and\n    the TPU cannot run an uncompiled one.\n*   ALWAYS verify the device SoC matches the model's stamp (the benchmark\n    script does) - a `Tensor_G5` model on a `Tensor_G6` phone fails with an\n    opaque dispatch error, wasting a debugging round.\n*   ALWAYS use the original uncompiled model for `--cpu-baseline` - compiled\n    models contain `DISPATCH_OP` nodes that only the NPU can execute.\n*   ALWAYS clean up the per-run device directory (automatic; after an\n    interrupted run list the base first, then remove only its `run-*` entries:\n    `adb shell ls -la \u003Cbase>` and `adb shell rm -rf \u003Cbase>\u002Frun-*`, where\n    `\u003Cbase>` is `\u002Fdata\u002Flocal\u002Ftmp\u002Flitert_benchmark` or the `--device-dir` that\n    was used). NEVER `rm -rf` the base directory itself - users keep their own\n    binaries and models there.\n*   NEVER combine `--use_cpu=true` with `--require_full_delegation=true` -\n    `benchmark_model` aborts on that combination.\n*   NEVER install packages into the system interpreter or without telling the\n    user; use a virtualenv so pinned LiteRT versions do not break other work.\n*   NEVER type LiteRT version numbers into install commands or download URLs\n    yourself - take them from `compile_model.py --print-install` and the\n    scripts' default URLs, which all read `versions.json`, so every job uses the\n    pair that was verified together. Use another release only when the user\n    asks for one (`--benchmark-url`, or the pip pair at that version), and say\n    so in the report. Changing the pin is a maintainer task\n    ([references\u002Fcontributing.md](references\u002Fcontributing.md)).\n*   NEVER treat macOS, Windows, or ARM hosts as a compile blocker or give manual\n    browser Colab notebook steps - run `compile_model.py --colab` directly.\n*   NEVER leave adb, benchmark, or Colab VM sessions running in the background -\n    every command here is bounded by a timeout and returns before the next step\n    (`compile_model.py --colab` stops any Colab VM it creates unless\n    `--keep-colab-session` is passed).\n*   NEVER guess compile flags or overwrite an existing output without asking\n    (`compile_model.py` exits 2; use `--output-name` or ask before\n    `--overwrite`).\n*   ALWAYS package for an app with `package_ai_pack.py` (it calls LiteRT's\n    exporter and verifies the result), and with `--update-project` (step 5b)\n    when the app already ships Google Tensor builds; NEVER create or edit AI\n    pack folders, the device-targeting XML or the runtime modules by hand, and\n    NEVER copy a new package's `ai_packs\u002F` over an existing pack - the app's\n    group names and the place of its CPU copy can differ.\n*   ALWAYS ask before changing the user's project, show the whole plan, and\n    get one approval; ask separately for each risky item (step 6) and before\n    `install_and_verify.py --uninstall-first`. NEVER change signing configs.\n*   NEVER put a compiled build where the app runs on the CPU (base assets,\n    `--fallback`): only the original uncompiled model.\n*   NEVER publish to Google Play, sign, or upload anything for the user; the\n    skill stops at the package and the local-testing steps.\n\n## Troubleshooting\n\nEvery script error names its fix; look up the error line or exit code in\n[references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md).\n\n## Public references\n\n[LiteRT NPU guide](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Fnpu),\n[Google Tensor with LiteRT](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Ftensor-sdk),\n[compilation flags](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Fcompilation-flags),\n[Tensor SDK FAQ](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Ftensor-faqs),\n[release notes \u002F compatibility](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Ftensor-sdk\u002Frelease-notes),\n[benchmark_model](https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert\u002Fnext\u002Fbenchmark),\n[codelab](https:\u002F\u002Fcodelabs.developers.google.com\u002Fcodelabs\u002Fgoogle-tensor-ml-sdk),\n[Play for On-device AI](https:\u002F\u002Fdeveloper.android.com\u002Fgoogle\u002Fplay\u002Fon-device-ai).\n\n## Contributions\n\nTo contribute or modify this skill or its references, follow the\n[contribution guidelines](references\u002Fcontributing.md) before making changes.\n",{"name":5,"metadata":24,"description":7},{"version":25,"category":26},"1.0.0","AiAndMachineLearning","main","64d010629e61e4a7d59fc21e042362f370b5888b","skills\u002Fplatform-devices\u002Flitert-google-tensor",2014,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills","https:\u002F\u002Fgithub.com\u002Fgoogle","https:\u002F\u002Fopensource.google\u002F","Google ❤️ Open Source","2026-11-14 23:31:00",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add google\u002Fskills --skill litert-google-tensor",{"tool":42,"command":43},"bunx","bunx skills add google\u002Fskills --skill litert-google-tensor",{"tool":45,"command":46},"pnpm","pnpm dlx skills add google\u002Fskills --skill litert-google-tensor","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002FSKILL.md",true,[50,56,60,64,68,72,76,80,84,88,92,98,102,106,110,114,120,124,128,132],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"assets\u002Ftemplates\u002Fai_pack\u002Fbuild.gradle.kts","ASSET","资产文件",1194,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002Fai_pack\u002Fbuild.gradle.kts",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"assets\u002Ftemplates\u002Fgoogle_tensor_runtime\u002Fbuild.gradle.kts",1504,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002Fgoogle_tensor_runtime\u002Fbuild.gradle.kts",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"assets\u002Ftemplates\u002Fgoogle_tensor_runtime\u002Fsrc\u002Fmain\u002FAndroidManifest.xml",1587,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002Fgoogle_tensor_runtime\u002Fsrc\u002Fmain\u002FAndroidManifest.xml",{"path":65,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":67},"assets\u002Ftemplates\u002FINTEGRATION_quick_test.md",1959,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002FINTEGRATION_quick_test.md",{"path":69,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":70,"sourceHtmlUrl":71},"assets\u002Ftemplates\u002FINTEGRATION.md",7654,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002FINTEGRATION.md",{"path":73,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":74,"sourceHtmlUrl":75},"assets\u002Ftemplates\u002Fruntime_strings\u002Fbuild.gradle.kts",1082,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002Fruntime_strings\u002Fbuild.gradle.kts",{"path":77,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":78,"sourceHtmlUrl":79},"assets\u002Ftemplates\u002Fruntime_strings\u002Fsrc\u002Fmain\u002Fres\u002Fvalues\u002Fstrings.xml",869,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002Fruntime_strings\u002Fsrc\u002Fmain\u002Fres\u002Fvalues\u002Fstrings.xml",{"path":81,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":82,"sourceHtmlUrl":83},"assets\u002Ftemplates\u002FTensorModelLoader.kt",7290,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002FTensorModelLoader.kt",{"path":85,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":86,"sourceHtmlUrl":87},"assets\u002Ftemplates\u002FUPDATE.md",1970,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Ftemplates\u002FUPDATE.md",{"path":89,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":90,"sourceHtmlUrl":91},"assets\u002Fversions.json",5328,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fassets\u002Fversions.json",{"path":93,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":96,"sourceHtmlUrl":97},"references\u002Fapp-integration.md","REFERENCE","参考文档",33364,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Freferences\u002Fapp-integration.md",{"path":99,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":100,"sourceHtmlUrl":101},"references\u002Fbenchmark-flags.md",50444,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Freferences\u002Fbenchmark-flags.md",{"path":103,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":104,"sourceHtmlUrl":105},"references\u002Fcompile-flags.md",15449,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Freferences\u002Fcompile-flags.md",{"path":107,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":108,"sourceHtmlUrl":109},"references\u002Fcontributing.md",18801,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Freferences\u002Fcontributing.md",{"path":111,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":112,"sourceHtmlUrl":113},"references\u002Ftroubleshooting.md",48902,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Freferences\u002Ftroubleshooting.md",{"path":115,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":118,"sourceHtmlUrl":119},"scripts\u002Fbenchmark_on_device.py","SCRIPT","脚本",85429,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fscripts\u002Fbenchmark_on_device.py",{"path":121,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":122,"sourceHtmlUrl":123},"scripts\u002Fcheck_compiled.py",7961,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fscripts\u002Fcheck_compiled.py",{"path":125,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":126,"sourceHtmlUrl":127},"scripts\u002Fcompile_model.py",65364,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fscripts\u002Fcompile_model.py",{"path":129,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":130,"sourceHtmlUrl":131},"scripts\u002Finstall_and_verify.py",28675,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fscripts\u002Finstall_and_verify.py",{"path":133,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":134,"sourceHtmlUrl":135},"scripts\u002Fpackage_ai_pack.py",147104,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fplatform-devices\u002Flitert-google-tensor\u002Fscripts\u002Fpackage_ai_pack.py",[137,145,152,159,166,173],{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":143,"publishedAt":144},"01M7DQ9K7JF4T7NJZ2K1MQZ44Q","cloud-operator-share-context","Shares Google Cloud operating context the user or their team already have — environments, projects, services and regions, product preferences, best practices, architecture guidance, runbooks — found in agent instruction files, local memory, skills and workflows, and the repository's GCP docs, with the operator agent's memory after the user reviews the list. Use when the user runs this skill, accepts the cloud-operator or cloud-operator-setup skill's offer to share their existing Google Cloud context, or asks to share, import or save that context or a GCP fact for the operator agent. Don't use for ordinary GCP requests, which go to the cloud-operator skill.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fcloud-operator-share-context\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":146,"name":147,"nameZh":6,"description":148,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":149,"categories":150,"keywords":151,"publishedAt":144},"01M7DQ9ERFGGQCFAWQW0KRKYBY","cloud-operator-setup","Sets up the operator agent in a Google Cloud project via the autocloud MCP server: picks the operator project, creates or checks the user's operator agent, saves the project, and offers to share the user's existing Google Cloud operating context with the operator agent's memory. Use when the user runs this skill, asks to set up the operator or create their operator agent, or chooses setup when the cloud-operator skill asks. Don't use for ordinary GCP requests or installing gcloud.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fcloud-operator-setup\u002FSKILL.md",[],[],{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":156,"categories":157,"keywords":158,"publishedAt":144},"01M7B4RHQCM0DK2XQ7S7ZXVN8D","developer-device-platform-device-run","Runs automated, non-interactive jobs on remote Android devices with Developer Device Platform (DDP) Device Run using `gcloud beta device-run sessions`: native Android executables or shell scripts (for example CLI tools, custom runners, test harnesses or benchmarks) and Android instrumentation tests, on one or many devices, then waits for completion and collects per-device outputs and logs. Use when running a binary or test suite on remote devices without an interactive connection. Don't use it for interactive device reservations, adb tunnels or screen streaming (use developer-device-platform-basics), or for local devices.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fdeveloper-device-platform-device-run\u002FSKILL.md",[],[],{"skillNo":160,"name":161,"nameZh":6,"description":162,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":163,"categories":164,"keywords":165,"publishedAt":144},"01M7B4R9YXMRW7RZP9Q9FMZJ2P","compute-vm-creation","Guides the planning, configuration, and provisioning of standalone Google Compute Engine virtual machines (VMs) and bare metal (-metal) instances using gcloud CLI commands or direct MCP tool execution. Use ONLY when the user wants to create, configure, or provision a new standalone Compute Engine VM or bare metal instance from conversational intents (hardware sizing, region selection, OS image, networking, security defaults). DO NOT read or use for Google Kubernetes Engine (GKE) Autopilot or Standard clusters, Kubernetes node pools or Pods, container orchestration, managing existing VMs, Managed Instance Groups (MIGs), or Instance Templates.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fcompute-vm-creation\u002FSKILL.md",[],[],{"skillNo":167,"name":168,"nameZh":6,"description":169,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":170,"categories":171,"keywords":172,"publishedAt":144},"01M7B4QD02N0YBVT0838Z5K5VC","agent-platform-autorater-customization","Customizes an autorater (evaluation metric) for an AI agent so its grades match the user's own judgment, starting from the agent's real trajectories. Use when a user wants a metric tailored to their agent, wants to turn failing trajectories into rubrics, says an existing autorater grades their agent wrong, or wants an autorater to agree with human labels (autorater hillclimbing, judge calibration). Don't use for quick evals with built-in metrics or for improving the agent itself (use agent-platform-eval-flywheel).","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fagent-platform-autorater-customization\u002FSKILL.md",[],[],{"skillNo":174,"name":175,"nameZh":6,"description":176,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":177,"categories":178,"keywords":179,"publishedAt":144},"01M78JP22K73KK96JH0JNDT5C4","iap-agent-platform-troubleshooting","Diagnoses Identity-Aware Proxy (IAP) denials of outbound requests from Gemini Enterprise Agent Platform agents that run on Agent Runtime and send traffic through Agent Gateway. Use when an agent request fails with \"Egress request is not authorized\", when Cloud Audit Logs show an IAP egressViaIAP decision with granted false, when IAP audit entries are missing while debugging agent egress, or when Access policies, IAP allow policies, policy bindings, or Agent Registry entries might block agent egress. Don't use for Gemini model IAM permission errors (such as aiplatform.endpoints.predict), Agent Platform API errors, or Agent Runtime deployment or 500 errors (use agent-platform-troubleshooting instead). Don't use for setting up, creating, or connecting an Agent Gateway, or for IAP web apps, IAP TCP forwarding, or SSH.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002Fcloud\u002Fiap-agent-platform-troubleshooting\u002FSKILL.md",[],[]]