On-Device Training Under 256KB Memory

Ji Lin* 1 , Ligeng Zhu* 1 , Wei-Ming Chen 1 , Wei-Chen Wang 1 , Chuang Gan 2 , Song Han 1
MIT, MIT-IBM Watson AI Lab
(* indicates equal contributions)

## News

• [06/30/2022] Our video demo of on-device training on micro-controllers is now avaliable online!
• [06/30/2022] Our paper is released on arXiv.

## Abstract

On-device training enables the model to adapt to new data collected from the sensors by fine-tuning a pre-trained model. However, the training memory consumption is prohibitive for IoT devices that have tiny memory resources. We propose an algorithm-system co-design framework to make on-device training possible with only 256KB of memory. On-device training faces two unique challenges: (1) the quantized graphs of neural networks are hard to optimize due to mixed bit-precision and the lack of normalization; (2) the limited hardware resource (memory and computation) does not allow full backward computation. To cope with the optimization difficulty, we propose Quantization-Aware Scaling to calibrate the gradient scales and stabilize quantized training. To reduce the memory footprint, we propose Sparse Update to skip the gradient computation of less important layers and sub-tensors. The algorithm innovation is implemented by a lightweight training system, Tiny Training Engine, which prunes the backward computation graph to support sparse updates and offload the runtime auto-differentiation to compile time. Our framework is the first practical solution for on-device transfer learning of visual recognition on tiny IoT devices (e.g., a microcontroller with only 256KB SRAM), using less than 1/100 of the memory of existing frameworks while matching the accuracy of cloud training+edge deployment for the tinyML application VWW. Our study enables IoT devices to not only perform inference but also continuously adapt to new data for on-device lifelong learning.

Figure.1 : Algorithm and system co-design reduces the training memory from 303MB (PyTorch) to 149KB with the same transfer learning accuracy, leading to 2077x reduction. The numbers are measured with MobilenetV2-w0.35, batch size 1 and resolution 128x128. It can be deployed to a microcontroller with 256KB SRAM.

Figure.2 : Measured peak memory and latency: (a) Sparse update with our graph optimization reduces the measured peak memory by 22-28$\times$. (b) Graph optimization consistently improves the peak memory (c) Sparse update with our operators achieves 21-23$\times$ faster training speed. For all numbers, we choose the config that achieves the same accuracy as full update.

## Citation

 @inproceedings{lin2022ondevice,
title     = {On-Device Training Under 256KB Memory},
author    = {Lin, Ji and Zhu, Ligeng and Chen, Wei-Ming and Wang, Wei-Chen and Gan, Chuang and Han, Song},
booktitle = {ArXiv},
year      = {2022}
} 

## Related work

• Checkout our other work about tiny machine learning:
• MCUNetV1: Tiny Deep Learning on IoT Devices
• MCUNetV2: Memory-efficient inference, System-algorithm co-design
• TinyTL: On-device learning, Memory-efficient transfer learning
• NetAug: Training technique for tiny neural networks

Acknowledgments: We thank National Science Foundation (NSF), MIT-IBM Watson AI Lab, MIT AI Hardware Program, Amazon, Intel, Qualcomm, Ford, Google for supporting this research.