LiteRT 101
Welcome to the LiteRT CLI 101 hands-on codelab! This guide is designed to take you step-by-step from zero environment setup to deploying optimized edge intelligence.
Edge AI requires bringing complex neural models directly onto mobile phones, wearables, and embedded hardware.
LiteRT (formerly TensorFlow Lite / TFLite ) Google's on-device framework for high-performance ML & GenAI deployment on edge platforms, via efficient conversion, runtime, and optimization.
LiteRT CLI integrates Google AI Edge stacks into a standalone shell command ( litert ) to streamline LiteRT-related development workflows, including converting, quantizing, compiling, running, benchmarking, and visualizing LiteRT (TFLite) models on various hardware (CPU / GPU / NPU) across platforms (desktop, mobile, or cloud).
2. ๐ Basic workflows: conversion, quantize & run
In this section, let's execute a complete Edge AI modeling lifecycle with LiteRT CLI: PyTorch model wrapper โ tracing conversion โ model quantization โ desktop inference โ performance benchmarks.
๐ Stage 1: Prepare a PyTorch model wrapper script
Create resnet18.py in your current directory. It exposes dynamic tracing hooks so the graph builder can capture shapes:
๐ Stage 2: Convert a PyTorch model to LiteRT using LiteRT Torch
Invoke the LiteRT Torch converter to build a standard Float32 .tflite target model:
๐ Stage 3: Quantize weights to INT8
Apply dynamic and weight-only recipe cards to shrink sizes by ~4x:
๐ Stage 4: Run Inference locally
Execute test operations with dummy input parameters to verify performance blocks:
๐ Stage 5: Benchmark model performance
Measure high-precision metrics including average latency, initialization costs, CPU execution throughput, and dynamic active memory footprints:
3. ๐ Local environment setup & verification
Let's build an isolated, clean sandbox on your workstation (macOS or Linux)
๐ Option A: Ultra-fast setup (uv)
Using uv isolates libraries in seconds, clearing environment cache conflicts.
๐ Option B: Standard setup (pip)
If uv is not present, use standard Python virtual environment configurations:
๐ ๏ธ Option C: Editable local setup
If you are developing or testing directly inside the repository source directory clone:
Verify that your path correctly routes the litert command:
๐ก The central Model Reference catalog (model-ref)
To keep scripts and development robust, the LiteRT CLI implements a centralized Model Catalog :
Format : Assign a unique name (alias) to a downloaded or imported model, such as mobilenet .
Variants : Use target colons to refer to optimized variations, like mobilenet:int8 or mobilenet:gpu .
Simplicity : All CLI commands accept this pathless alias directly, automatically resolving physical file storage on the fly!
4. ๐ฒ Device deployment & profiling
Let us take optimization further by running high-precision local benchmarks, deploying to real USB hardware targets, implementing hardware delegates, compiling Ahead-of-Time, and cloud benchmarking.
๐ Local profiling metrics
Download EfficientNet-B1 and profile performance statistics on your desktop host:
Observe the key performance headers in the benchmark log:
Model initialization : Time to boot structural networks.
Warmup (avg) : Compilation overhead timings.
Inference (avg) : The raw mathematical processing time.
Overall footprint : Peak RAM consumed during execution.
๐ฒ Target A: Mobile CPU (USB connect)
Connect an Android device with USB Debugging enabled, and deploy:
The CLI automatically pushes the model to target device, executes the inference loop, and pipes outputs back!
๐ฎ Target B: Mobile GPU
Offload heavy workloads dynamically to the GPU using OpenCL or WebGPU:
โ๏ธ Target C: JIT Android NPU
Offload execution parameters directly to the NPU on modern chipsets:
Warning : Dynamic graph builds inside on-device runtime suffer from significant initialization JIT warmup delays.
๐ Target D: AOT compiled NPU
Pre-compile offline to bypass runtime JIT overheads and achieve maximum acceleration:
โ๏ธ Cloud profiling (Google AI Edge Portal)
Push tests to remote hardware profiles in Google Cloud's device farms.
5. ๐ง Advanced topics: LLMs & speech recognition
Let's explore advanced models by converting and running Large Language Models (LLMs) and Automatic Speech Recognition (ASR) models.
๐ฌ Generative AI (LLMs)
Edge LLMs are memory-bounded. We resolve this by applying Weight-Only INT4/INT8 quantization, compressing weights while keeping execution channels in Float32:
๐๏ธ Speech processing (ASR)
ASR models like Whisper or Parakeet have both an encoder and a decoder module. We can benchmark for specific modules using Signature Keys :
6. ๐ค Use in agentic coding
LiteRT CLI is agent-friendly , and you can integrate it directly with coding agents.
Here are some examples. Add the LiteRT CLI skill SKILL.md into your coding agent (like Google Antigravity ) and try prompts like below.
7. ๐ Congratulations & steps
๐ Outstanding! You have completed the LiteRT CLI 101 codelab!
You now possess the skills to master edge ML development:
Convert PyTorch models to LiteRT models.
Quantize model weights to INT4/INT8.
Run models on mobile CPU/GPU/NPU.
Benchmark on desktop, mobile and cloud.
Convert and run LLM models.
Use in agentic coding.
LiteRT CLI :
LiteRT :
Examples :
The full story
This article is one source in a clustered incident โ the cluster page carries the summary, timeline and every other outlet covering it.
