Source-linked AI summary

TensorFlow Lite Micro: Embedded Machine Learning on TinyML Systems

Robert David, Jared Duke, Advait Jain, Vijay Janapa Reddi, Nat Jeffries, Jian Li, Nick Kreeger, Ian Nappier, Meghna Natraj, Shlomi Regev, Rocky Rhodes, Tiezhen Wang, Pete Warden

arXiv:2010.08678v3cs.LGcs.AI

TL;DR

Embedded inference must operate within severe resource limits and a fragmented hardware ecosystem. The paper introduces TFLM, an interpreter-based framework emphasizing portability, flexible integration, and efficient execution. It reports minimal run-time overhead and low memory consumption, while noting limitations in dynamic-shape support and build-system maintainability.

  • Problem

    Embedded inference must accommodate severe resource constraints, missing mainstream software features, and hardware heterogeneity that complicates portable deployment.

  • Method

    TFLM uses an interpreter-based, portable framework with explicit embedded-memory planning and integration with TensorFlow Lite tooling.

  • Results

    The framework’s overhead is less than 0.1% for long-running VWW models and about 3% to 4% for short-running Google Hotword models, while memory use is at most 13 KB for convolutional and Google Hotword models and 26.5 KB for VWW.

  • Takeaways & Limitations

    TFLM enables deep-learning inference on embedded systems with only a few kilobytes of memory while addressing hardware heterogeneity and missing software features.

  • Takeaways & Limitations

    TFLM does not support dynamic shapes, and its ad hoc makefile-and-Python project generation is difficult to debug, maintain, and extend.

Abstract

from arXiv · show

Deep learning inference on embedded devices is a burgeoning field with myriad applications because tiny embedded devices are omnipresent. But we must overcome major challenges before we can benefit from this opportunity. Embedded processors are severely resource constrained. Their nearest mobile counterparts exhibit at least a 100 -- 1,000x difference in compute capability, memory availability, and power consumption. As a result, the machine-learning (ML) models and associated ML inference framework must not only execute efficiently but also operate in a few kilobytes of memory. Also, the embedded devices' ecosystem is heavily fragmented. To maximize efficiency, system vendors often omit many features that commonly appear in mainstream systems, including dynamic memory allocation and virtual memory, that allow for cross-platform interoperability. The hardware comes in many flavors (e.g., instruction-set architecture and FPU support, or lack thereof). We introduce TensorFlow Lite Micro (TF Micro), an open-source ML inference framework for running deep-learning models on embedded systems. TF Micro tackles the efficiency requirements imposed by embedded-system resource constraints and the fragmentation challenges that make cross-platform interoperability nearly impossible. The framework adopts a unique interpreter-based approach that provides flexibility while overcoming these challenges. This paper explains the design decisions behind TF Micro and describes its implementation details. Also, we present an evaluation to demonstrate its low resource requirement and minimal run-time performance overhead.

1 INTRODUCTION

TinyML applications are expanding, but fragmented hardware and resource constraints make portable, production-ready deployment difficult. TensorFlow Lite Micro addresses this gap with a portable interpreter-based framework that supports vendor optimizations while imposing minimal runtime overhead.

  • Motivation: TinyML supports always-on neural-network applications across keyword spotting and other embedded sensor tasks.Tiny models can run continuously on microcontrollers or DSP-based subsystems with minimal battery impact.
  • Challenges: Embedded systems lack a unified TinyML framework, forcing one-off, manually optimized solutions that are narrow and difficult to port.These frameworks often lack support for multiple applications and broad hardware portability.
  • Challenges: Hardware fragmentation also makes vendor-neutral performance evaluation difficult because improvements may arise from hardware, software, or an integrated solution.Frameworks tied to specific devices obscure the source of performance gains.
  • Challenges: Existing frameworks lack portable deployment, hardware-aware optimization, training-to-deployment tooling, model-compression infrastructure, and profiling or debugging support.These gaps collectively hinder productive development across embedded architectures.
  • TensorFlow Lite Micro: TensorFlow Lite Micro uses an interpreter-based, hardware-agnostic design to improve portability while allowing vendors to integrate per-kernel optimizations.The paper argues that linear-algebra-dominated workloads make the interpreter's runtime overhead minimal, despite interpretation traditionally being viewed as lower performance than compilation.

2 TECHNICAL CHALLENGES

Embedded systems impose hardware, software, memory, and power constraints that complicate machine-learning deployment. Fragmentation and rapidly changing model operations further increase the engineering burden of maintaining portable inference support.

  • Platform constraints: Embedded platforms often lack dynamic memory management, virtual memory, operating systems, standard instruction sets, file systems, and floating-point hardware.These mainstream software capabilities are unavailable because their resource tradeoffs are too expensive for embedded platforms.
  • Hardware fragmentation: Embedded hardware is fragmented across many instruction-set architectures, vendor-specific extensions, tool chains, and commercial IDEs.This fragmentation weakens pressure toward dominant platforms and can prevent a lone development team from producing broadly portable software.
  • Resource constraints: Small embedded systems may have only a few hundred kilobytes or fewer of memory, requiring both working memory and compiled code size to be minimized.Larger embedded systems may have a few megabytes of flash ROM and at most a megabyte of SRAM.
  • Resource constraints: Runtime flexibility is difficult to justify when code size is constrained, forcing developers to break through library abstractions for target-specific modifications.General-purpose software often includes code paths that remain unused on a particular device.
  • Model evolution: Frequent advances in neural-network operations require corresponding software changes, making frameworks difficult to keep current as models evolve.TensorFlow has more than 1,400 operations, while inference frameworks typically support only subsets.

3 DESIGN PRINCIPLES

TFLM’s design principles prioritize portability across heterogeneous embedded platforms while limiting framework responsibilities to efficient model computation. The design reuses TensorFlow tools and enables modular hardware optimization without imposing platform-specific build requirements.

  • Design principles: TFLM assumes models, inputs, outputs, and possible internal state are already in memory, excluding file-system and peripheral access from the framework.This narrow scope supports portability across platforms lacking mainstream memory and library features.
  • Hardware optimization: Hardware-specific kernel optimization is delegated to vendors because ecosystem fragmentation makes it impractical for one team to support every microprocessor.The framework emphasizes tests and benchmarks to support vendor modifications and library contributions.
  • Model export: Exporting embedded models is difficult because supported operations, data types, parameter ranges, and operation combinations may not follow unified rules.Resource constraints also make eight-bit and other quantized representations valuable for deployment.
  • Tool reuse: The TensorFlow Lite toolchain converts trained models into FlatBuffer files that TFLM loads for inference, while reusing TensorFlow Lite reference kernels.This integration connects TFLM to TensorFlow’s training, conversion, and optimization environment.
  • Build system: A flexible build environment avoids precompiled binaries and supports the many device, operating-system, and tool-chain combinations found in embedded platforms.The project favors source files that can be compiled through varied IDEs and tool chains.

4 IMPLEMENTATION

TFLM implements inference through a static, portable interpreter that manages operators and memory explicitly for resource-constrained systems. Its system design supports model updates and multitenancy while omitting concurrency features that would reduce portability.

  • System overview: The application creates an operator resolver, contiguous memory arena, interpreter, and model execution sequence to run inference.The resolver controls linked operators, while the arena supplies memory because dynamic allocation is assumed unavailable.
  • Concurrency: TFLM omits threading and multitasking support to avoid less-portable code and operating-system dependencies, but supports multiple nonconcurrent models.Invocation is a simple blocking call, consistent with mostly single-threaded MCU operation.
  • TFLM Interpreter: The interpreter executes model operations using statically available code while model data determines which operators run and where parameters are obtained.This separates execution code from model-specific data.
  • TFLM Interpreter: An interpreter makes field model updates and code sharing across models easier because changing a model does not require replacing or re-exporting the executable.Native code generation can improve performance but requires recompilation for each target and embeds model settings in the binary.
  • Implementation tradeoffs: The implementation incorporates code-generation simplicity through a source-file-only buildable library while retaining an interpreter-based model interface.This combines source-based deployment with runtime model handling.

4.3 Model Loading

TFLM reuses TensorFlow Lite’s portable model representation to import models efficiently across embedded platforms, while accepting modest run-time processing overhead. Its representation supports sequential execution but requires C++11 and embedded-device adaptations such as compiling model data into arrays.

  • Model Representation: TFLM reuses TensorFlow Lite’s stored model schema and export tools to import a wide variety of models with little engineering effort.The schema was designed for storage efficiency and fast access on mobile platforms.
  • Model Serialization: TensorFlow Lite’s FlatBuffer format provides memory-efficient, header-only model serialization without unpacking into another representation.The accessor code is typically less than two kilobytes, but the format requires C++11 compiler support.
  • Model Serialization: TFLM converts memory-mapped model files into C source data arrays because many embedded devices lack file systems.These arrays can be compiled directly into the application binary.
  • Model Representation: Topologically sorted operations let the interpreter execute models by iterating through an ordered operation list rather than preprocessing graph dependencies.This simplifies calculation sequencing for embedded inference.
  • Model Representation: Portable serialization requires run-time processing to convert abstract operator parameters into implementation-specific structures.The resulting code overhead is small but reduces operator-implementation readability and compactness.

4.4 Memory Management

TFLM manages all model memory from a caller-provided fixed arena because dynamic allocation cannot be assumed. Its initialization-time planning, stack separation, buffer reuse, and optional offline planning trade preparation overhead and planning complexity for reduced memory use.

  • Arena Allocation: TFLM allocates and manages model memory from a provided arena because embedded operating systems may not support dynamic allocation.Applications must supply a fixed-size arena and preserve it throughout the interpreter’s lifetime.
  • Arena Allocation: All framework allocations occur during interpreter initialization, preventing allocation-related errors during model invocation.Operator preparation communicates evaluation-time memory needs before execution begins.
  • Allocation Strategy: A two-stack strategy separates function-lifetime allocations from interpreter-lifetime allocations and detects insufficient capacity when the stack pointers cross.The space between stacks can temporarily support model-planning allocations.
  • Allocation Strategy: Discarding initialization-only allocations makes their arena space reusable for evaluation variables and can reduce the required arena size.The function-lifetime section can also be reused between evaluation calls in advanced applications.
  • Memory Planner: Memory planners reuse intermediate buffers whose lifetimes do not overlap, reducing total memory through compact layouts.The planner models allocation size and lifetime, then uses first-fit decreasing placement; perfect allocation for arbitrary models is unsolved.
  • Memory Planner: Runtime memory planning increases model-preparation overhead compared with preplanned allocation but supports more general model descriptions.Offline planning instead provides a more compact layout, user control, lower MCU initialization overhead, and memory-bank placement options.

4.5 Multitenancy

TFLM supports multitenancy for multiple models that need not run simultaneously by allowing their interpreters to share one memory arena. The planner reuses nonpersistent space while retaining model-specific persistent allocations.

  • Motivation: Multiple specialized models may be necessary because embedded constraints can prevent deploying one large monolithic model.Supporting several models on the same embedded system therefore becomes a practical requirement.
  • Motivation: Separate isolated interpreters waste memory when nonconcurrent models cannot reuse temporary space.The inefficiency arises because each instance retains its own temporary allocation region.
  • Shared Arena: TFLM enables multitenancy by allowing multiple model interpreters to allocate from a single shared arena through transparent memory-planner changes.The reusable nonpersistent region is sized to the largest model requirement, while persistent allocations remain model specific.

4.6 Multithreading

TFLM avoids built-in threading and multitasking support to preserve portability, but its arena-isolated interpreter design supports concurrent interpreter instances and multiple MCU cores when model state remains properly contained.

  • Thread Safety: Thread safety requires that model state remain inside the interpreter and the model’s arena allocation.This is an explicit condition on safe multithreaded use.
  • Thread Safety: Unique model-interpreter-arena bindings allow multiple interpreter instances to run safely from different tasks or threads.The interpreter’s variables are kept in its arena.
  • Multicore Execution: TFLM can run on multiple MCU cores because executable code is shared while separate arenas prevent threading issues.The arena-based state separation supports this arrangement in practice.
  • Operator Abstraction: Operators expose defined inputs, outputs, and state variables, enabling platform-specific kernel implementations behind an abstraction boundary.This structure supports optimized libraries for embedded processors such as CMSIS-NN.

4.8 Platform Specialization

TFLM supports platform-specific kernel optimization while preserving portability across fragmented embedded tool chains. Its source-based build process simplifies integration but remains difficult to maintain and extend.

  • TFLM lets specialized kernel implementations override reference kernels for particular platforms, including Arm CMSIS-NN.
  • Platform tags replace reference kernels during compilation, while library modifiers enable incremental implementation changes without altering build scripts.
  • A single makefile selects source files and generates project files for platform-specific tool chains.
  • The platform-agnostic build approach supports varied tool chains with minimal engineering work but is difficult to debug, maintain, and extend.

5 SYSTEM EVALUATION

TFLM is evaluated on representative general-purpose MCU and ultra-low-power DSP platforms using embedded vision and keyword-spotting models. The evaluation finds minimal interpreter overhead, substantial optimized-kernel speedups, and a small memory footprint.

  • Experimental Setup: The evaluation covers an Arm Cortex-M4 MCU and an Xtensa HiFi Mini DSP, using Visual Wake Words and Google Hotword models.
  • Benchmark Performance: Interpreter overhead is less than 0.1% for long-running VWW models and about 3% to 4% for short-running Google Hotword models on the MCU.
  • Benchmark Performance: Optimized Google Hotword kernels are only 25% better than the Cortex-M4 reference model because kernel calculations occupy less of total runtime.
  • Memory Overhead: The interpreter footprint is less than 2KB, total memory is at most 13 KB for convolutional and Google Hotword models, and the VWW framework consumes 26.5 KB.
  • Benchmarking and Profiling: TFLM benchmarks and profiling APIs provide consistent hardware comparisons and help developers measure performance and identify optimization opportunities.

6 RELATED WORK

TFLM differs from related TinyML inference systems by using an interpreter-based design rather than compiler- or code-generator-based approaches. The design emphasizes flexibility across the embedded ecosystem.

  • Related systems include cross-compilers, open-source compilers, vendor code generators, and memory-focused MCU code generators.
  • TFLM adopts an interpreter-based approach as a distinct design point for flexibility in addressing embedded ecosystem challenges.

7 CONCLUSION

TFLM is engineered to run machine learning efficiently on embedded devices with only a few kilobytes of memory. Its design addresses hardware heterogeneity, missing software features, and severe resource constraints.

  • TFLM transfers deep learning onto embedded systems and broadens the reach of machine learning.
  • TFLM’s design addresses hardware heterogeneity in fragmented ecosystems, missing software features, and severe resource constraints.
Loading 2010.08678v3…