google-ai-edge/litert-samples/litert-compiled-model-migration
Claude Code and agent skill by google-ai-edge/litert-samples
- community
Checking that the SKILL.md file is still in the repository.
Rapidly migrate an Android application from legacy TensorFlow Lite (TFLite) to the modern LiteRT CompiledModel API (2.x) in Open Source GitHub repositories, keeping the TensorFlow Lite Support Library as LiteRT Support (litert-support 2.3.0). Covers buffer reuse, NPU JIT compilation, a reference implementation, and a two-stage verification gate (compile check, then an on-device parity test against a golden output).
Install
npx vskill@latest install google-ai-edge/litert-samples/litert-compiled-model-migrationSKILL.md
Skill: LiteRT Compiled Model Migration SKILL
Description
This skill guides an AI agent to rapidly migrate an Android application from legacy TensorFlow Lite (TFLite) to the modern LiteRT CompiledModel API (2.x) in Open Source GitHub repositories. It prioritizes a high-speed, 1st-pass "Like for Like" baseline migration with automated self-testing, and encourages advanced performance upgrades including off-main-thread execution with buffer reuse and NPU JIT compilation.
Read first: what the Kotlin CompiledModel API (com.google.ai.edge.litert, 2.3.0; 2.2.0 has the same API) has
CompiledModel.create(context.assets, assetName, CompiledModel.Options(Accelerator.CPU), env)andcreate(filePath, options, env);Optionstakes one or more ofAccelerator.CPU/GPU/NPU(e.g.Options(Accelerator.GPU, Accelerator.CPU));envisEnvironment.create(context)(optional; enables the compiler cache) orEnvironment.create(context, BuiltinNpuAcceleratorProvider(context))for the NPU. Nothing takes a ByteBuffer or a mapped file.- Buffers come from the model (
createInputBuffers()/createOutputBuffers(),List<TensorBuffer>;writeFloat(FloatArray)/writeInt8(ByteArray)/writeInt/writeLong,readFloat()and friends; create them once).run(inputs, outputs)is synchronous on the CPU; on the GPU it can return before the GPU finishes andread*()waits; there is no callback API.CompiledModel,TensorBufferandEnvironmentareAutoCloseable: close buffers, then the model, then anEnvironmentthe app created. CompiledModel.Options()with no accelerator compiles, butcreatethen throwsLiteRtException.Interpreter,GpuDelegate,NnApiDelegateand the Support library'sModel(com.google.ai.edge.litert.support.model.Model, which runs onInterpreterApi) do not appear in migrated code; the rest of LiteRT Support does, undercom.google.ai.edge.litert.support(Step 1), withorg.tensorflow.lite.DataTypeas the type its classes take. ThelitertAAR also containsorg.tensorflow.lite.Interpreter, so leftover Interpreter code compiles (all butsetUseNNAPI, which 2.x does not have) and the Stage 1 import check is what catches it.templates/LiteRtModel.ktcompiles against the 2.3.0 and the 2.2.0 artifacts; start from it.
0. Automatic Discovery & Upfront Planning
Before writing code, the agent MUST inspect the project workspace and present the upfront planning interview to align migration parameters:
A. Automatic Workspace & Toolchain Discovery
The agent must automatically inspect the repository structure:
- Ecosystem & Build Engine:
- Gradle Build System: Detected by
build.gradle,build.gradle.kts, orsettings.gradle. -> Enable Gradle & GitHub PR Workflow.
- Language & JNI Toolchain:
- Native C++ / NDK: Detected if
CMakeLists.txt,Android.mk, or*.cppfiles exist. -> Enable C++ / JNI Migration Rules. - Pure Kotlin / Java: Default to JVM / Android SDK Migration Rules.
B. Upfront User Interview (Questions Asked Prior to Migration)
The agent must present the following review options to the user:
With no user to answer (CI, batch runs): take Q1 from the code, Q2 [A] only when the vendor libraries of Upgrade 2.C are already in the repo (otherwise [B]), Float32 unless calibration inputs exist, and the defaults of Q3 and Q4 with the PR opened as a draft; record the choices in the PR description. Today the runtime is the standalone com.google.ai.edge.litert:litert AAR: no LiteRT artifact for Google Play services is on Google Maven as of October 2026 (only the play-services-tflite-* Interpreter artifacts exist).
[!IMPORTANT]LiteRT Support (`litert-support` 2.3.0): an app on the TensorFlow Lite Support Library keeps it. The library now ships as LiteRT Support, with the same classes, methods and behavior; the migration is two steps of Step 1, swap the Gradle coordinates and rename the packageorg.tensorflow.lite.supporttocom.google.ai.edge.litert.support(its guide: https://github.com/google-ai-edge/LiteRT/blob/main/litert/support_lib/MIGRATION_GUIDE.md).ImageProcessor,ResizeOp,NormalizeOp,TensorImage,TensorLabel,FileUtilandMetadataExtractorstay as they are. The one class replaced is itsModel, which runs on the Interpreter API: it becomesCompiledModellikeInterpreter(Step 4), withtemplates/SupportBridge.ktbetween the Support tensors and the model's buffers. An app that never used the Support library does not add it;Bitmap.toModelInputintemplates/LiteRtModel.ktis its preprocessing.
1. Phase 1: "Like for Like" Baseline Migration (1st Pass Success)
Phase 1 prioritizes functional equivalence, fast compilation, and immediate 1st pass self-test success.
Step 0: Capture the Golden Output
Before Step 1 changes any dependency, with the legacy runtime and preprocessing still in the project (no device attached: skip Step 0, stop after Stage 1, and open the PR as a draft that says so):
- Define one fixed input: for a vision app a deterministic bitmap (
fixedBitmapintemplates/GoldenCaptureTest.kt, or a small image file inapp/src/androidTest/assets/), otherwise a generated array; never a camera frame. A bitmap of the model's input size with rotation 0 leaves the resize and the rotation out of the gate: use another size (and aspect ratio), and the rotation the camera path passes, in the capture and in Stage 2 alike. - Declare the
androidx.testdependencies andtestInstrumentationRunner(Stage 2 needs them too), copytemplates/GoldenCaptureTest.ktintoapp/src/androidTest/java/<package>/, make it call the app's existing inference entry point (the class the UI calls, with its own preprocessing) on the fixed input on the CPU (no GPU or NNAPI delegate, XNNPACK at its default); when that entry point returns only a thresholded or sorted list, first give the class a function returning the raw output and one returning the preprocessed input (preprocess(bitmap): Stage 2 calls it too), still on the legacy runtime. Then run the four commands in its header: they install both APKs, run the test on the device, and pullgolden.txtintoapp/src/androidTest/assets/golden/output.txt. A raw tensor fed straight to the model is not a golden output: it leaves the preprocessing out of the gate. - Delete the capture test. Stage 2 compares against the file, so the test APK never needs
org.tensorflow:tensorflow-lite.
Step 1: Clean & Modernize Dependencies
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/litert-compiled-model-migration/SKILL.md
Popularity
- Repository stars
- 405
- Repository forks
- 114
- 7-day trend score
- 30
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/google-ai-edge/litert-samples/litert-compiled-model-migration)