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
.tflitevia 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- Convert. Python
TFLiteConverteraccepts 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 matchingtensorflow/lite/schema/schema.fbs. - Load.
FlatBufferModel::BuildFromFilemmaps the file, validates the schema version, and exposes the model. - Build interpreter.
InterpreterBuilderties the model to anOpResolver(which maps each op code to aTfLiteRegistration). - Allocate tensors. The
ArenaPlannerdecides how to share buffers between tensors with disjoint lifetimes (tensorflow/lite/arena_planner.cc). - Apply delegates. Each delegate inspects the graph and offers to handle subgraphs it supports; the interpreter replaces those nodes with delegate nodes.
- Run.
Interpreter::Invokedispatches each node's kernel. Kernels are simplePrepare(...)+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", ®istration).
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/Android —
tensorflow/lite/java/, builds an Android AAR. See apps/java-api. - Swift —
tensorflow/lite/swift/. - Objective-C —
tensorflow/lite/objc/. - iOS framework —
tensorflow/lite/ios/. - C —
tensorflow/lite/c/(a parallel TFLite C API). - Python —
tensorflow/lite/python/providestf.lite.Interpreterandtf.lite.TFLiteConverter.
Tools
tensorflow/lite/tools/benchmark/—benchmark_modelbinary.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.TFLiteConverteris the supported entry. Internally it calls intotensorflow/compiler/mlir/lite/. - From Android Studio: the AAR
tensorflow-liteis published to Maven; ML Model Binding uses it. - From iOS:
TensorFlowLiteSwift/TensorFlowLiteObjCPods.
Entry points for modification
- New op kernel —
tensorflow/lite/kernels/<op_name>.cc+ register intensorflow/lite/kernels/register.cc. Add an entry inbuiltin_ops.handtensorflow/lite/schema/schema.fbsif the op is new (schema bump). - New delegate — model after
tensorflow/lite/delegates/xnnpack/for a thin example orgpu/for a complex one. ImplementTfLiteDelegate::Prepare,Invoke, etc. - New converter pass —
tensorflow/compiler/mlir/lite/transforms/houses MLIR passes. - Schema change —
tensorflow/lite/schema/schema.fbs. Schema changes require regeneratingschema_generated.hand bumping the schema version.
Related
- compilers/mlir — the converter is MLIR-based.
- systems/kernels-and-ops — TFLite kernels are separate from
tensorflow/core/kernels/. - java-api — TFLite Android bindings.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.