GooglePing Yu, Quentin Khan, Chintan Parikh, Lu WangAnnouncement
Native Model Authoring for Edge with LiteRT Tensor API
Summary
The LiteRT Tensor API is a new lightweight authoring layer that allows developers to handcraft models in C++ with full control over graph structure and operations. The same graph runs through LiteRT on CPU, GPU, or NPU, or directly on CPU via XNNPACK, without rewriting for each hardware target. The API enables direct weight ingestion from model checkpoints like Hugging Face .safetensors files and provides tensor-centric buffer interop to keep intermediate data on accelerators with zero copies. A reference implementation of Meta’s Segment Anything Model 2 (SAM 2) authored entirely with the API achieved over 30 frames per second at 512x512 on WebGPU in the browser. The API also provides structured primitives for AI coding agents to generate, rewire, and tune model graphs automatically.
Context
Deploying on-device AI requires meeting tight latency and memory budgets. The standard conversion path (e.g., PyTorch to LiteRT) is recommended for most projects, but developers sometimes need full control over graph representation and optimization for new architectures or custom lowering logic. Handcrafting models in native C++ or shader languages offers control but is tightly coupled to specific backends and requires significant engineering for cross-platform portability and buffer management.
Approach / What changed
The LiteRT Tensor API is a lightweight authoring layer that allows building computation graphs op by op in C++, with cross-platform portability via LiteRT (CPU, GPU, NPU) or direct CPU execution via XNNPACK. It provides direct weight ingestion, tensor-centric buffer interop, and building blocks for AI coding agents.
Takeaways
The LiteRT Tensor API enables handcrafting models in C++ with full control over graph structure and operations, while maintaining cross-platform portability across CPU, GPU, and NPU.
The API supports direct weight ingestion from model checkpoints (e.g., .safetensors) without conversion scripts, and allows tensor-centric buffer interop to keep data on accelerators with zero copies.
A coding agent (Antigravity) used the Tensor API to optimize the SAM 2 model, more than tripling its frame rate by rewriting per-frame decisions as GPU-friendly operations, each change checked against a reference.
FAQ
How does the LiteRT Tensor API differ from the standard conversion path?
The standard conversion path (e.g., PyTorch to LiteRT) is the recommended default for most projects. The Tensor API is for developers who need low-level control over graph structure and optimization, allowing handcrafting in C++ with cross-platform portability.
What backends does the Tensor API support?
The same C++ graph can run through LiteRT on CPU, GPU (via open-source ML Drift), and NPU, or directly on CPU through XNNPACK without a model file. Tensors can be tagged for both backends.
How can AI coding agents use the Tensor API?
The API provides structured primitives for AI coding agents to generate, rewire, and tune model graphs automatically. The Antigravity agent used it to optimize the SAM 2 model by rewriting per-frame decisions as GPU-friendly operations, checking each change against a reference.
Source and freshness
- Source
- developers.googleblog.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.