TL;DR
This paper introduces a novel method to reduce the memory footprint of neural networks on microcontrollers (MCUs) by reordering the execution of operators. This technique allows for the deployment of previously too-large models on resource-constrained MCUs, opening up new possibilities for edge AI.
What Problem Does This Paper Address?
Deep learning models are becoming increasingly powerful, but deploying them on edge devices, especially low-power microcontrollers (MCUs), presents a significant challenge. MCUs are attractive for their low cost and energy efficiency, but they have severely limited computational resources and, crucially, very small amounts of on-chip memory (SRAM). Existing methods for making neural networks smaller, like pruning or quantization, often focus on reducing the model's parameter count. However, even with a small parameter count, the peak memory usage during inference can still be too high for MCUs. This peak usage is determined by the "working set" of tensors (inputs, outputs, and intermediate activations) that need to be held in memory at any given time. The paper addresses the gap of optimizing this peak runtime memory usage, which is distinct from static model size reduction.
Methods
The core contribution of this paper is a method to optimize the execution order of operators within a neural network's computation graph to minimize peak memory usage.
- Operator Reordering: Neural networks are represented as computation graphs. When a graph has branches (multiple operators can be executed next), the inference software has a choice. The authors propose an algorithm to find an execution order that minimizes the maximum memory required for intermediate tensors.
- Dynamic Programming Algorithm (MEM): They introduce a dynamic programming algorithm to compute the minimal peak memory usage for a given set of output tensors. This algorithm recursively explores different operator execution paths, considering the memory needed for input tensors, output tensors, and tensors required by subsequent operations.
- TensorFlow Lite Micro Integration: The proposed method is implemented as a tool that modifies TensorFlow Lite models. This tool generates an optimized execution schedule.
- Dynamic Memory Allocation: Since MCUs often lack sufficient memory to statically pre-allocate all tensor buffers, the authors use a lightweight TensorFlow Lite Micro interpreter and implement a dynamic memory allocator. They also employ a simple defragmentation strategy to manage memory efficiently.
Datasets
Not discussed in the paper. The paper focuses on a specific convolutional neural network (CNN) architecture (SwiftNet Cell) and a pre-trained model for person detection (MobileNet v1) from the Visual Wake Words competition.
Key Insights and Ideas
- Execution Order Matters for Memory: The most significant insight is that the order in which operators are executed can drastically affect the peak memory required during inference, even if the network architecture and total number of operations remain the same. This is because different orders lead to different "working sets" of tensors needing to be resident in memory.
- Orthogonal to Other Compression: Operator reordering is a technique that can be applied in addition to other compression methods like pruning or quantization, offering a complementary way to save memory.
- MCU Memory is the Bottleneck: The paper highlights that for MCUs, the limited SRAM is often the primary constraint, and optimizing peak memory usage is crucial for deploying models.
- Dynamic Allocation is Feasible: The work demonstrates that dynamic memory allocation, coupled with simple defragmentation, is a viable strategy for managing memory on MCUs when static allocation is not possible.
Key Results
- Significant Memory Reduction: For the SwiftNet Cell model, operator reordering reduced peak memory usage from 351KB to 301KB (a saving of 50KB). This was sufficient to fit the model within the 512KB SRAM of the target MCU.
- Minimal Overhead: The optimized ordering resulted in a negligible increase in execution time (0.68%) and energy use (0.97%) for the MobileNet v1 model, while still achieving a substantial memory reduction (186KB).
- Tool Availability: The authors have released a tool for reordering operators in TensorFlow Lite models, making their method accessible to the community.
Limitations and Future Work
- Computational Complexity: The dynamic programming algorithm for finding the optimal schedule has a complexity of O(|V|^2|V|), where |V| is the number of operators. While this is manageable for typical MCU-sized networks, it could become a bottleneck for very large graphs.
- Operator Implementation: The paper notes that further latency and power consumption reductions can be achieved by leveraging processor-specific instructions (SIMD, DSP) within operator implementations.
- Future Work: The authors suggest extending their algorithm to support more advanced memory-saving tricks, such as accumulating results into unused input buffers. They also believe their method can benefit neural architecture search (NAS) by providing a precise way to compute peak memory usage. The paper also mentions that the TensorFlow Lite Micro interpreter's dynamic memory allocator has since been improved, making their custom allocator less critical.
Summary updated