Skip to content

LiteRT 101

codelabs.developers.google.com โ€ข December 1, 2026

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 :

Extracted Entities

Companies (1)

Tools (1)