Memory-Driven Mixed Low Precision Quantization For Enabling Deep Network Inference On Microcontrollers

Manuele Rusci, Alessandro Capotondi, Luca Benini

Abstract: This paper presents a novel end-to-end methodology for enabling the deployment of low-error deep networks on microcontrollers. To fit the memory and computational limitations of resource-constrained edge-devices, we exploit mixed low-bitwidth compression, featuring 8, 4 or 2-bit uniform quantization, and we model the inference graph with integer-only operations. Our approach aims at determining the minimum bit precision of every activation and weight tensor given the memory constraints of a device. This is achieved through a rule-based iterative procedure, which cuts the number of bits of the most memory-demanding layers, aiming at meeting the memory constraints. After a quantization-aware retraining step, the fake-quantized graph is converted into an inference integer-only model by inserting the Integer Channel-Normalization (ICN) layers, which introduce a negligible loss as demonstrated on INT4 MobilenetV1 models. We report the latency-accuracy evaluation of mixed-precision MobilenetV1 family networks on a STM32H7 microcontroller. Our experimental results demonstrate an end-to-end deployment of an integer-only Mobilenet network with Top1 accuracy of 68% on a device with only 2MB of FLASH memory and 512kB of RAM, improving by 8% the Top1 accuracy with respect to previously published 8 bit implementations for microcontrollers.

The Challenge of Extreme Edge AI

Bringing machine learning to the "extreme edge"—specifically, battery-powered microcontroller units (MCUs)—is incredibly difficult due to tight hardware constraints. A typical high-end MCU might only have 2MB of Flash memory for storing weights and 512kB of RAM for temporary activations.

While 8-bit quantization is the current industry standard for edge AI (e.g., TensorFlow Lite for Microcontrollers), an 8-bit MobileNetV1 still requires over 4MB of memory, making it too large for most MCUs. To fit these models, aggressive sub-byte quantization (4-bit or 2-bit) is required. However, existing sub-byte methods either rely on floating-point arithmetic, which MCUs lack, or suffer from catastrophic accuracy drops when standard optimization tricks—like folding batch-normalization parameters into weights—are applied at such low precisions.

Proposed Methodology

The authors propose an end-to-end pipeline for creating integer-only, mixed-precision inference models designed to navigate these hardware limitations.

The end-to-end DNN development flow for microcontrollers, incorporating device-aware fine-tuning and memory constraints.

1. Integer Channel-Normalization (ICN) Layers

In standard 8-bit deployment, batch-normalization parameters are "folded" into the convolutional weights to save compute. The authors found that doing this at 4-bit precision destroys the dynamic range and causes training to collapse. To fix this, they introduce ICN. ICN keeps the batch-norm parameters separate but reformulates the math so it can be executed using purely integer and fixed-point arithmetic. This allows for highly accurate per-channel sub-byte quantization without needing floating-point units.

2. Memory-Driven Bit Allocation

Instead of manually selecting which layers to quantize, the authors introduce a static, rule-based iterative algorithm. By inputting the MCU's exact Read-Only (Flash) and Read-Write (RAM) memory limits, the algorithm iteratively downgrades the precision (from 8 to 4 to 2 bits) of the most memory-heavy layers—handling activations first, then weights—until the network fits the hardware budget.

3. Quantization-Aware Retraining

Once the mixed-precision architecture is defined, the model undergoes quantization-aware training (QAT) using PACT for activations and asymmetric uniform quantization for weights to recover accuracy lost during the compression process.

Key Insights

  • Batch-norm folding is a silent killer for sub-byte quantization: While folding batch-norm into weights is standard for 8-bit networks, it drastically alters parameter ranges. At 4 bits, this causes training to collapse, yielding near-zero accuracy.
  • Per-channel quantization is essential at 4 bits: Quantizing an entire layer's weights to a single 4-bit range loses too much information. Quantizing each channel independently is required to maintain accuracy, and the proposed ICN layer makes this computationally feasible on integer-only hardware.
  • Mixed precision solves the MCU puzzle: By selectively crushing only the most memory-hogging layers to 4 or 2 bits, the network retains 8-bit precision where it matters most, maximizing accuracy within a strict byte-count limit.

Experimental Results

The methodology was evaluated on the MobileNetV1 family using the ImageNet (ILSVRC 2012) benchmark. The results demonstrate a significant breakthrough in MCU-class performance.

Top-1 Accuracy vs. Latency (CPU MCycles) for various MobileNetV1 configurations on an STM32H7 microcontroller.
  • State-of-the-Art MCU Accuracy: The methodology successfully deployed a mixed-precision MobileNetV1 model achieving 68% Top-1 accuracy on ImageNet while fitting entirely within an STM32H7 MCU (2MB Flash, 512kB RAM).
  • 8% Improvement over 8-bit: This 68% accuracy is 8% higher than the best purely 8-bit MobileNet configuration that can fit into the same memory footprint.
  • Latency vs. Accuracy Trade-off: The per-channel quantization (PC-ICN) introduces a ~20% latency overhead compared to per-layer quantization due to extra bias subtractions. However, this trade-off is justified by a 4% gain in classification accuracy.

Limitations and Future Work

The bit-reduction algorithm currently uses static heuristics, cutting the largest layers first. The authors acknowledge that dynamic, learning-based approaches (like Reinforcement Learning or Hessian-based methods) might find even more optimal mixed-precision configurations. Additionally, future work could explore optimizing low-level ARM CMSIS-NN kernels to better hide the 20% latency penalty associated with the ICN layer.

Summary updated

Abstract

This paper presents a novel end-to-end methodology for enabling the deployment of low-error deep networks on microcontrollers. To fit the memory and computational limitations of resource-constrained edge-devices, we exploit mixed low-bitwidth compression, featuring 8, 4 or 2-bit uniform quantization, and we model the inference graph with integer-only operations. Our approach aims at determining the minimum bit precision of every activation and weight tensor given the memory constraints of a device. This is achieved through a rule-based iterative procedure, which cuts the number of bits of the most memory-demanding layers, aiming at meeting the memory constraints. After a quantization-aware retraining step, the fake-quantized graph is converted into an inference integer-only model by inserting the Integer Channel-Normalization (ICN) layers, which introduce a negligible loss as demonstrated on INT4 MobilenetV1 models. We report the latency-accuracy evaluation of mixed-precision MobilenetV1 family networks on a STM32H7 microcontroller. Our experimental results demonstrate an end-to-end deployment of an integer-only Mobilenet network with Top1 accuracy of 68% on a device with only 2MB of FLASH memory and 512kB of RAM, improving by 8% the Top1 accuracy with respect to previously published 8 bit implementations for microcontrollers.
BibTeX
@inproceedings{rusci2020memory,
  author = {Manuele Rusci and Alessandro Capotondi and Luca Benini},
  title = {{Memory-Driven Mixed Low Precision Quantization For Enabling Deep Network Inference On Microcontrollers}},
  booktitle = {MLSys},
  year = {2020},
  url = {https://openreview.net/forum?id=6Ho4Lg7qQnc},
}
Figure