LiteRT Documentation

repository·main·Indexed 25 days ago

https://github.com/google-ai-edge/litert

Google's high-performance on-device runtime for deploying Machine Learning and Generative AI models on edge platforms including mobile, web, and IoT. The documentation covers building the runtime and Python wheels via Docker, using the Accelerator Test Suite (ATS) for hardware verification (CPU, GPU, NPU), and utilizing the LiteRT Next C and C++ APIs. It also includes guides for building the Android C++ SDK and managing vendor SDK dependencies for Intel OpenVINO, Qualcomm QAIRT, and MediaTek NeuroPilot.

Tokens
256.6K
Snippets
558
Records
1.1K
Agent score
85%

What's inside LiteRT

  1. Overview of LiteRt Accelerator Test Suite (ats)

    main

    The LiteRt Accelerator Test Suite (ats) is a tool for validating the functional correctness and measuring the performance of custom accelerator implementations in LiteRt.

    It performs:

    • Numeric Validation: Compares output tensors (activations) from the accelerator against the LiteRt standard CPU backend to ensure precision and correctness.
    • Performance Metrics: Automatically captures and records metrics like latency.
    • Automated Execution: Typically runs on target devices (e.g., Android) using a shell script wrapper that manages file transfers via adb.
  2. Overview of Post-training Quantization Methods

    main

    Post-training quantization reduces model size and improves latency for CPU and hardware accelerators with minimal accuracy loss. Choose a method based on your target hardware:

    TechniqueBenefitsHardware
    Dynamic range quantization4x smaller, 2x-3x speedupCPU
    Full integer quantization4x smaller, 3x+ speedupCPU, Edge TPU, Microcontrollers
    Float16 quantization2x smaller, GPU accelerationCPU, GPU

    Note: Requires TensorFlow 1.15 or higher.

  3. Overview of @litertjs/core

    main
    @litertjs/core is the core web runtime for LiteRT (formerly TFLite), Google's open-source high-performance runtime for on-device AI. It allows you to load and run .tflite models directly in the browser using various acceleration backends including WebGPU, WebNN (for NPUs), and high-performance CPU execution via XNNPack in WebAssembly.
  4. Overview of LiteRT Tensor

    main

    LiteRT Tensor is a lightweight, Tensor-centric C++ library designed for high-performance tensor manipulation on mobile devices. It provides an expressive API for building computation graphs, simplifying pre- and post-processing, and authoring models that can be compiled into LiteRT (TFLite) models.

    Key Capabilities:

    • Expressive C++ API: Uses fluent interfaces and operator overloading.
    • Backend Agnostic: Uses template mixins to switch between execution backends like TfLite.
    • Zero-Copy Execution: Uses shared Buffer and TensorBuffer objects to avoid data duplication between pipeline stages (e.g., between CPU and GPU).
    • LiteRT Integration: Allows compiling custom C++ graphs directly into LiteRT models.
    • Dynamic Support: Supports dynamic shapes and multiple model entry points (signatures).
  5. Overview of LiteRT

    main
    LiteRT is Google's on-device runtime designed for high-performance ML and Generative AI deployment on edge platforms. It provides advanced GPU/NPU acceleration and supports a wide range of hardware including Android, iOS, Linux, macOS, Windows, and Web. Key features of V2 include the Compiled Model API for streamlined development, Unified NPU Acceleration for broad silicon support, and faster GPU acceleration via ML Drift.
  6. Overview of TensorFlow Lite Task Library

    main

    The TensorFlow Lite Task Library provides optimized, task-specific APIs for common machine learning tasks like image classification, object detection, and natural language processing. It is designed for ease of use, allowing developers to implement inference with minimal code while handling complex data processing (e.g., converting raw data to model-ready formats) automatically.

    Supported platforms include Java, C++, and Swift.

  7. Overview of the Question Answering example app architecture

    main

    The example application utilizes the BertQuestionAnswerer API from the LiteRT Task library for natural language (NL). It uses a Mobile BERT model trained on the SQuAD dataset. By default, the application runs on the CPU, but it supports hardware acceleration via GPU or NNAPI delegates.

    Key files in the implementation:

    • BertQaHelper.kt: Initializes the question answerer and manages model and delegate selection.
    • QaFragment.kt: Handles and formats the question-answering results.
    • MainActivity.kt: Contains the primary organizing logic for the application.
  8. Overview of TensorFlow Lite Sample Stable Delegate

    main

    The Sample Stable Delegate is an example implementation used for testing stable delegate APIs. It is designed to support a limited set of operations: addition, subtraction, multiplication, equality check, and while loops.

    It utilizes the TfLiteOpaqueDelegate API, which allows for the delegation of nodes to alternative backends without exposing implementation details. This enables dynamic loading of delegates.

    Critical Requirement: Because open-source TF Lite does not yet provide a binary stable interface between delegates and the runtime, any dynamically loaded opaque delegate must be built against the exact same version and commit as the TF Lite runtime to avoid undefined behavior.

  9. Overview of TensorFlow Lite Delegate Performance Benchmark (Android APK)

    main

    The TensorFlow Lite Delegate Performance Benchmark (DPB) Android app is a wrapper around the TensorFlow Lite benchmark tool and MiniBenchmark. It is designed specifically for testing TensorFlow Lite delegates that implement a stable delegate ABI.

    Developers use this app to evaluate both accuracy and latency to catch performance regressions. Unlike running binaries via adb shell, which can be affected by Android's scheduler behavior for background processes, this app provides a more faithful view of the runtime performance (accuracy and latency) that developers can expect when running delegates within a foreground Android Activity/Application.

  10. Overview of Accelerator Allowlisting

    main
    The Accelerator Allowlisting library and tools are experimental resources designed to determine if a specific accelerator engine performs effectively on a given device for a specific model. While the codebase is located within the TfLite repository, it is intended to be platform-agnostic and support users beyond TfLite, such as those using NNAPI directly or via MediaPipe.