Native Model Authoring for Edge with LiteRT Tensor API Google released the LiteRT Tensor API, a C++ authoring layer in the LiteRT stack that lets developers build computation graphs op by op and run the same graph on CPU, GPU via open-source ML Drift, and NPU, or directly on CPU through XNNPACK without a model file or runtime. Google demonstrated the API with an on-device Segment Anything Model 2 (SAM 2) app running in the browser on WebGPU, where a coding agent evolved the C++ implementation from under 10 to over 30 frames per second at 512x512, with code published in the LiteRT Samples GitHub repo. Google said the conversion path, such as converting a PyTorch model with LiteRT Torch, remains the recommended default for most projects, and positions the Tensor API as a programmatic foundation for AI coding agents to generate, rewire, and tune model graphs. Shipping on-device AI means meeting tight latency and memory budgets on every device you target. The most common path for deploying models in production is converting a trained model, for example converting a PyTorch model with LiteRT Torch https://github.com/google-ai-edge/litert-torch , and running it with the LiteRT runtime https://developers.google.com/edge/litert/inference . This offers the quickest and most reliable route to production, and it's the path we recommend for most projects. Sometimes, though, developers want full control over how a network is represented and optimized to support new architectures or to try a new lowering logic without waiting for upstream framework updates. For ultimate control, developers write computations manually in native C++ or shader languages. Apple's MLX https://github.com/ml-explore/mlx made this code-first approach popular on Apple silicon, and llama.cpp https://github.com/ggml-org/llama.cpp showed how far tailored C++ implementations can take LLM inference. However, the level of control comes at a significant cost: implementations are tightly coupled to specific backends such as Metal, OpenCL, or Vulkan and must be rewritten for each new hardware target. Furthermore, managing zero-copy buffer interoperability and synchronization across CPU, GPU, and NPU, while gluing together pre-processing, inference, and post-processing, demands substantial manual engineering effort. To solve the above challenges, we are excited to announce the release of the novel LiteRT Tensor API https://github.com/google-ai-edge/LiteRT/blob/main/tensor/README.md , a lightweight authoring layer in the LiteRT stack, designed to improve handcrafting models. It combines the flexibility of native authoring with cross-platform portability. You build the computation graph op by op in C++, choosing exactly which ops run and how they connect. The same graph can run through LiteRT on CPU, GPU powered by open-source ML Drift http://github.com/google-ai-edge/ml-drift and NPU, or without model file or runtime directly on CPU through XNNPACK, so you don't rewrite it for each new hardware target. Model inference and pre/post-processing can be assembled with the same API and chained through shared accelerator buffers, so that data never round-trips through the CPU. Start with the conversion path, which remains the best default for most models. Reach for the Tensor API when you need low-level control over the graph or want the whole pipeline to run end to end on the accelerator. The LiteRT Tensor API also serves as an ideal programmatic foundation for AI coding agents, providing structured primitives to generate, rewire, and tune model graphs automatically. In the rest of this post, we’ll dive into the design and walk through practical code examples showing how to author models from scratch. To show the Tensor API in practice, we built an interactive Segment Anything App https://storage.googleapis.com/litertjs demos/sam2 web/index.html , running entirely on-device in the browser on WebGPU. The app enables real-time multi-object segmentation and tracking via Meta's Segment Anything Model 2 SAM 2 https://github.com/facebookresearch/sam2 , triggered either by simple clicks or natural language prompts powered by Gemma 4 E2B https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm . The SAM 2 model is fully authored in C++ via the LiteRT Tensor API. A coding agent wrote and evolved it from under 10 to over 30 frames per second at 512x512 on WebGPU. See that the complete implementation and the web app are open source in the LiteRT Samples https://github.com/google-ai-edge/litert-samples/tree/main/models/sam2/sam2 hiera tiny video GitHub repo. The LiteRT Tensor API provides four key features for authoring and optimizing on-device models: We ran the same C++ code for the SAM 2 model on the GPUs of three devices: a macOS laptop Metal , an iOS phone Metal , and an Android phone OpenCL . In our tests on the MacBook Pro, it ran about 1.5x faster than Apple MLX fp16, image encoder plus mask decoder . The SAM 2.1 sample https://github.com/google-ai-edge/litert-samples/blob/main/models/sam2/sam2 hiera tiny video/tensor api/sam2 image/README.md includes the benchmark commands so you can reproduce the results. With the Tensor API, each layer is a C++ function over Tensor https://github.com/google-ai-edge/LiteRT/blob/6f622b5ddd51429c564f5ac2b22a7861bedbd147/tensor/tensor.h L159 values, built from high-level operators and weights loaded directly from the checkpoint. For example, here is a multi-head self-attention layer: // Multi-head self-attention over x: batch, tokens, dim . Tensor Attention const Tensor& x, const WeightMap& w, int heads { std::vector