Open-Source Wikis

/

TensorFlow

/

Apps

/

TensorFlow Lite

tensorflow/tensorflow

TensorFlow Lite

Mobile and embedded inference runtime. Lives in tensorflow/lite/. Independent enough from TF "core" to deserve its own page; you can use TFLite without touching the rest of the repo.

Purpose

  • Run pre-trained models on Android, iOS, Linux, microcontrollers.
  • Use a tiny C++ runtime that loads a flatbuffer model file (.tflite).
  • Plug in delegates (GPU, NNAPI, XNNPACK, CoreML, Hexagon) to offload subgraphs to specialised hardware.
  • Convert TF/Keras/SavedModel/JAX models to .tflite via the TFLite converter.

Directory layout

tensorflow/lite/
├── interpreter.h              # User-facing interpreter
├── model_builder.h            # FlatBufferModel / model loading
├── arena_planner.{h,cc}       # Memory planning
├── core/                      # Subgraph, model_builder, op_resolver
├── kernels/                   # ~150 op kernels (Add, Conv2D, FullyConnected, ...)
├── delegates/                 # GPU, NNAPI, XNNPACK, CoreML, Hexagon, Flex
├── async/                     # Async inference primitives
├── schema/                    # FlatBuffer schema (schema.fbs) and generated code
├── stablehlo/                 # StableHLO-based ops + lowering
├── micro/                     # (mostly moved to tflite-micro standalone repo)
├── nnapi/                     # NNAPI binding glue
├── java/                      # Android Java/AAR bindings
├── objc/                      # Objective-C bindings
├── swift/                     # Swift bindings
├── ios/                       # iOS framework
├── python/                    # Python interpreter wrapper + converter entry
├── toco/                      # Legacy converter (TOCO)
├── tools/                     # benchmark_model, evaluation, optimize, ...
├── experimental/              # Newer / unstable areas
├── profiling/                 # On-device profiler
├── examples/                  # Example apps (Android demo, label_image, ...)
├── g3doc/                     # Documentation
└── ...

Key abstractions

Type / class File Role
tflite::FlatBufferModel tensorflow/lite/model_builder.h Loads a .tflite flatbuffer.
tflite::Interpreter tensorflow/lite/interpreter.h Allocates tensors and dispatches ops.
tflite::Subgraph tensorflow/lite/core/subgraph.h One graph (a model has one or many).
TfLiteContext, TfLiteRegistration tensorflow/lite/c/common.h C-style structs that ops implement.
tflite::OpResolver tensorflow/lite/op_resolver.h Maps op codes to kernel implementations.
tflite::Delegate tensorflow/lite/delegates/ Plug-in that takes over part of the graph.
tflite::ArenaPlanner tensorflow/lite/arena_planner.h Memory planner that reuses tensor buffers.
tflite::Profiler tensorflow/lite/profiling/ Optional event tracer.

How it works

graph TD
    Source[TF SavedModel / Keras model / JAX module]
    Converter[tf.lite.TFLiteConverter Python: tensorflow/lite/python/lite.py]
    MLIR[MLIR converter tensorflow/compiler/mlir/lite/]
    Flatbuf[".tflite flatbuffer"]
    Interp[Interpreter tensorflow/lite/interpreter.h]
    Kernels[Builtin kernels tensorflow/lite/kernels/]
    Delegate[Optional delegate GPU/NNAPI/XNNPACK]

    Source --> Converter
    Converter --> MLIR
    MLIR --> Flatbuf
    Flatbuf -- FlatBufferModel --> Interp
    Interp --> Kernels
    Interp --> Delegate
  1. Convert. Python TFLiteConverter accepts a SavedModel, Keras model, or concrete function. Most paths route through the MLIR-based converter (tensorflow/compiler/mlir/lite/); the legacy TOCO path (tensorflow/lite/toco/) remains for compatibility. The converter writes a flatbuffer matching tensorflow/lite/schema/schema.fbs.
  2. Load. FlatBufferModel::BuildFromFile mmaps the file, validates the schema version, and exposes the model.
  3. Build interpreter. InterpreterBuilder ties the model to an OpResolver (which maps each op code to a TfLiteRegistration).
  4. Allocate tensors. The ArenaPlanner decides how to share buffers between tensors with disjoint lifetimes (tensorflow/lite/arena_planner.cc).
  5. Apply delegates. Each delegate inspects the graph and offers to handle subgraphs it supports; the interpreter replaces those nodes with delegate nodes.
  6. Run. Interpreter::Invoke dispatches each node's kernel. Kernels are simple Prepare(...) + Eval(...) pairs.

Op registry and OpResolver

The full list of builtin ops lives in tensorflow/lite/builtin_ops.h (~360 op codes today). Kernel implementations are in tensorflow/lite/kernels/. BuiltinOpResolver (tensorflow/lite/kernels/register.h) registers all builtins; smaller binaries can use MutableOpResolver and only register the ops they need (tensorflow/lite/mutable_op_resolver.h).

Custom ops register through MutableOpResolver::AddCustom("OpName", &registration).

Delegates

Each delegate lives under tensorflow/lite/delegates/:

Delegate Path Backend
GPU tensorflow/lite/delegates/gpu/ OpenCL / OpenGL / Metal
NNAPI tensorflow/lite/delegates/nnapi/ Android NNAPI
XNNPACK tensorflow/lite/delegates/xnnpack/ Optimised CPU SIMD
CoreML tensorflow/lite/delegates/coreml/ iOS CoreML
Hexagon tensorflow/lite/delegates/hexagon/ Qualcomm Hexagon DSP
Flex tensorflow/lite/delegates/flex/ Falls back to full TF for unsupported ops

The flex delegate is special — it makes TFLite able to run any TF op by linking in (a subset of) the full TF runtime.

TFLite Micro

The microcontroller variant historically lived under tensorflow/lite/micro/. As of recent releases most active development moved to the standalone tensorflow/tflite-micro repository. What remains here are stubs and a few headers; new work goes upstream of that repo.

Mobile-language bindings

  • Java/Androidtensorflow/lite/java/, builds an Android AAR. See apps/java-api.
  • Swifttensorflow/lite/swift/.
  • Objective-Ctensorflow/lite/objc/.
  • iOS frameworktensorflow/lite/ios/.
  • Ctensorflow/lite/c/ (a parallel TFLite C API).
  • Pythontensorflow/lite/python/ provides tf.lite.Interpreter and tf.lite.TFLiteConverter.

Tools

  • tensorflow/lite/tools/benchmark/benchmark_model binary.
  • tensorflow/lite/tools/optimize/ — quantization helpers.
  • tensorflow/lite/tools/evaluation/ — model accuracy harnesses.
  • tensorflow/lite/tools/visualize.py — model visualizer.

Integration points

  • From TF: tf.lite.TFLiteConverter is the supported entry. Internally it calls into tensorflow/compiler/mlir/lite/.
  • From Android Studio: the AAR tensorflow-lite is published to Maven; ML Model Binding uses it.
  • From iOS: TensorFlowLiteSwift / TensorFlowLiteObjC Pods.

Entry points for modification

  • New op kernel — tensorflow/lite/kernels/<op_name>.cc + register in tensorflow/lite/kernels/register.cc. Add an entry in builtin_ops.h and tensorflow/lite/schema/schema.fbs if the op is new (schema bump).
  • New delegate — model after tensorflow/lite/delegates/xnnpack/ for a thin example or gpu/ for a complex one. Implement TfLiteDelegate::Prepare, Invoke, etc.
  • New converter pass — tensorflow/compiler/mlir/lite/transforms/ houses MLIR passes.
  • Schema change — tensorflow/lite/schema/schema.fbs. Schema changes require regenerating schema_generated.h and bumping the schema version.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

TensorFlow Lite – TensorFlow wiki | Factory