SlideShare a Scribd company logo
1 of 12
Download to read offline
Things I learned while running neural networks
on microcontroller
Saradindu Sengupta
PyData Global 2022
Senior ML Engineer @Nunam
Where I work on building learning systems to forecast health and failure of Li-ion batteries.
When to deploy on the edge
● Low Latency
Average low inference time, generally in critical system such as safety and healthcare environment
where latency is crucial with a slight compromise on accuracy
● Privacy
When the user data doesn’t leave the source is the when privacy leakage scenarios are rare
● Network constraints
In a highly network-constraint environment, non-functional requirements (latency, throughput) takes a hit.
● Throughput
When the inference requests per second are high
2
PyData Global 2022
Patterns
● Training at the edge
○ Federated learning
1. User data never leaves the device
2. In contrast with a centralised model training and serving, the necessary
training and model refresh due to data drift happens on the edge
3. Each deployment can have customized model to suit the use-case and
data distribution
Training at the
edge
Updated weights
Base
model
Share the updated
model
3
PyData Global 2022
Patterns
● Inferencing at the edge
1. Depending on the type of application, this is the most used scenarios where inference
only happen at the edge. This introduces several problems over the lifetime starting with
data drift and model update.
2. The model is trained on a large dataset and only inference happens on the edge
3. Best suited for deployment on microcontrollers
4
PyData Global 2022
Model quantization
What
Reduce the floating-point precision to store the model parameters from 32-bit to 16-bit or 8-bit
Why
● Reduce memory footprint
● Reduce memory usage
Drawbacks
● Reduced accuracy dependending on the type of quantization
● (Full integer quantization with int16 activations and int8 weights)[3]
● But how much size is reduced
● All most 4x reduction in models with primarily convolution layers[5]
5
PyData Global 2022
Types of quantization
● Post-training quantization
1. Quantization of the model parameters from 32-bit floating-point to 16-bit floating-point or 8-bit
integer.
2. Different libraries supports different types of post-training quantization for different edge hardwares
(mobile,GPU ,microcontrollers and neural-accelerator)
3. For example tflite model optimization toolkit provides 3 different types of post-training quantization
methods
6
PyData Global 2022
Types of Quantization
● Post-training quantization
1. Post-training float16
● Suitable for CPU, GPU
● Accuracy loss: Negligible
2. Post-training dynamic range
● Suitable for CPU, GPU
● Accuracy loss: Least among the rest
3. Post-training integer
● Suitable for CPU, GPU and EdgeTPU
● Accuracy loss: Higher compared to the rest
7
PyData Global 2022
Types of Quantization
● Quantization-aware training
1. Happens during model training
2. 8-bit integers precision
● Which one to choose
1. Reduction in model size
a. Post-training float16
2. Less loss of accuracy
a. Post-training dynamic range
b. Post-training integer
8
PyData Global 2022
Other ways to reduce model size
● Weight Sharing
1. Cluster weights of each layers into N clusters
2. Share the centroids of each cluster
3. Provides 30-50% reduction in model size with negligible loss in accuracy
● Pruning
1. Remove parameters which are insignificant
9
PyData Global 2022
Benchmarks
1. Benchmark results of the recent Tiny MLPerf v0.7 [Link][Paper]
2. EdgeTPU benchmark result of different neural net architectures [Link]
10
PyData Global 2022
References
1. https://www.tensorflow.org/lite/performance/model_optimization#quantization
2. https://www.tensorflow.org/model_optimization/guide/clustering#results
3. https://www.tensorflow.org/lite/performance/model_optimization#full_integer_
quantization_with_int16_activations_and_int8_weights
4. https://www.tensorflow.org/model_optimization/guide/quantization/training#res
ults
5. https://blog.tensorflow.org/2018/09/introducing-model-optimization-toolkit.html
11
PyData Global 2022
Thank You
12
PyData Global 2022
/in/saradindusengupta
@iamsaradindu /saradindusengupta

More Related Content

Similar to PyData Global 2022 - Things I learned while running neural networks on microcontroller

Computer Application and Agri Informatics
Computer Application and Agri InformaticsComputer Application and Agri Informatics
Computer Application and Agri Informatics
SubhamMandal40
 
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratchOpen_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
Igor Stoppa
 

Similar to PyData Global 2022 - Things I learned while running neural networks on microcontroller (20)

Client side machine learning
Client side machine learningClient side machine learning
Client side machine learning
 
Computer Application and Agri Informatics
Computer Application and Agri InformaticsComputer Application and Agri Informatics
Computer Application and Agri Informatics
 
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratchOpen_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
Open_IoT_Summit-Europe-2016-Building_a_Drone_from_scratch
 
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio..."Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
 
AI hype or reality
AI  hype or realityAI  hype or reality
AI hype or reality
 
IRJET- BSIOTR IT SMART LAB using IOT
IRJET- BSIOTR IT SMART LAB using IOTIRJET- BSIOTR IT SMART LAB using IOT
IRJET- BSIOTR IT SMART LAB using IOT
 
C3 w3
C3 w3C3 w3
C3 w3
 
ECML PKDD 2021 ML meets IoT Tutorial Part III: Deep Optimizations of CNNs and...
ECML PKDD 2021 ML meets IoT Tutorial Part III: Deep Optimizations of CNNs and...ECML PKDD 2021 ML meets IoT Tutorial Part III: Deep Optimizations of CNNs and...
ECML PKDD 2021 ML meets IoT Tutorial Part III: Deep Optimizations of CNNs and...
 
Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...Improving GStreamer performance on large pipelines: from profiling to optimiz...
Improving GStreamer performance on large pipelines: from profiling to optimiz...
 
Deep learning at the edge: 100x Inference improvement on edge devices
Deep learning at the edge: 100x Inference improvement on edge devicesDeep learning at the edge: 100x Inference improvement on edge devices
Deep learning at the edge: 100x Inference improvement on edge devices
 
Class 5 an 8 bit embedded platform
Class 5 an 8 bit embedded platformClass 5 an 8 bit embedded platform
Class 5 an 8 bit embedded platform
 
Leveraging Artificial Intelligence Processing on Edge Devices
Leveraging Artificial Intelligence Processing on Edge DevicesLeveraging Artificial Intelligence Processing on Edge Devices
Leveraging Artificial Intelligence Processing on Edge Devices
 
Presentation 7.pptx
Presentation 7.pptxPresentation 7.pptx
Presentation 7.pptx
 
What is a microcontroller
What is a microcontrollerWhat is a microcontroller
What is a microcontroller
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
Scolari's ICCD17 Talk
Scolari's ICCD17 TalkScolari's ICCD17 Talk
Scolari's ICCD17 Talk
 
Project_updated
Project_updatedProject_updated
Project_updated
 
A Parallel Computing-a Paradigm to achieve High Performance
A Parallel Computing-a Paradigm to achieve High PerformanceA Parallel Computing-a Paradigm to achieve High Performance
A Parallel Computing-a Paradigm to achieve High Performance
 
Vibration Analysis for condition Monitoring & Predictive Maintenance using Em...
Vibration Analysis for condition Monitoring & Predictive Maintenance using Em...Vibration Analysis for condition Monitoring & Predictive Maintenance using Em...
Vibration Analysis for condition Monitoring & Predictive Maintenance using Em...
 
IRJET - Automated Fraud Detection Framework in Examination Halls
 IRJET - Automated Fraud Detection Framework in Examination Halls IRJET - Automated Fraud Detection Framework in Examination Halls
IRJET - Automated Fraud Detection Framework in Examination Halls
 

More from SARADINDU SENGUPTA

More from SARADINDU SENGUPTA (7)

Solar Energy Output Forecasting from SolarGIS Data for Connected Grid Station
Solar Energy Output Forecasting from SolarGIS Data for Connected Grid StationSolar Energy Output Forecasting from SolarGIS Data for Connected Grid Station
Solar Energy Output Forecasting from SolarGIS Data for Connected Grid Station
 
An Analytical Comparison of Different Regularization Parameter Selection Meth...
An Analytical Comparison of Different Regularization Parameter Selection Meth...An Analytical Comparison of Different Regularization Parameter Selection Meth...
An Analytical Comparison of Different Regularization Parameter Selection Meth...
 
Pydata Global 2023 - How can a learnt model unlearn something
Pydata Global 2023 - How can a learnt model unlearn somethingPydata Global 2023 - How can a learnt model unlearn something
Pydata Global 2023 - How can a learnt model unlearn something
 
AZConf 2023 - Considerations for LLMOps: Running LLMs in production
AZConf 2023 - Considerations for LLMOps: Running LLMs in productionAZConf 2023 - Considerations for LLMOps: Running LLMs in production
AZConf 2023 - Considerations for LLMOps: Running LLMs in production
 
GDG Community Day 2023 - Interpretable ML in production
GDG Community Day 2023 - Interpretable ML in productionGDG Community Day 2023 - Interpretable ML in production
GDG Community Day 2023 - Interpretable ML in production
 
PyData Global 2022 - Lightning Talk - Bessel's Correction
PyData Global 2022 - Lightning Talk - Bessel's CorrectionPyData Global 2022 - Lightning Talk - Bessel's Correction
PyData Global 2022 - Lightning Talk - Bessel's Correction
 
GDG Cloud Community Day 2022 - Managing data quality in Machine Learning
GDG Cloud Community Day 2022 -  Managing data quality in Machine LearningGDG Cloud Community Day 2022 -  Managing data quality in Machine Learning
GDG Cloud Community Day 2022 - Managing data quality in Machine Learning
 

Recently uploaded

Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 

Recently uploaded (20)

Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 

PyData Global 2022 - Things I learned while running neural networks on microcontroller

  • 1. Things I learned while running neural networks on microcontroller Saradindu Sengupta PyData Global 2022 Senior ML Engineer @Nunam Where I work on building learning systems to forecast health and failure of Li-ion batteries.
  • 2. When to deploy on the edge ● Low Latency Average low inference time, generally in critical system such as safety and healthcare environment where latency is crucial with a slight compromise on accuracy ● Privacy When the user data doesn’t leave the source is the when privacy leakage scenarios are rare ● Network constraints In a highly network-constraint environment, non-functional requirements (latency, throughput) takes a hit. ● Throughput When the inference requests per second are high 2 PyData Global 2022
  • 3. Patterns ● Training at the edge ○ Federated learning 1. User data never leaves the device 2. In contrast with a centralised model training and serving, the necessary training and model refresh due to data drift happens on the edge 3. Each deployment can have customized model to suit the use-case and data distribution Training at the edge Updated weights Base model Share the updated model 3 PyData Global 2022
  • 4. Patterns ● Inferencing at the edge 1. Depending on the type of application, this is the most used scenarios where inference only happen at the edge. This introduces several problems over the lifetime starting with data drift and model update. 2. The model is trained on a large dataset and only inference happens on the edge 3. Best suited for deployment on microcontrollers 4 PyData Global 2022
  • 5. Model quantization What Reduce the floating-point precision to store the model parameters from 32-bit to 16-bit or 8-bit Why ● Reduce memory footprint ● Reduce memory usage Drawbacks ● Reduced accuracy dependending on the type of quantization ● (Full integer quantization with int16 activations and int8 weights)[3] ● But how much size is reduced ● All most 4x reduction in models with primarily convolution layers[5] 5 PyData Global 2022
  • 6. Types of quantization ● Post-training quantization 1. Quantization of the model parameters from 32-bit floating-point to 16-bit floating-point or 8-bit integer. 2. Different libraries supports different types of post-training quantization for different edge hardwares (mobile,GPU ,microcontrollers and neural-accelerator) 3. For example tflite model optimization toolkit provides 3 different types of post-training quantization methods 6 PyData Global 2022
  • 7. Types of Quantization ● Post-training quantization 1. Post-training float16 ● Suitable for CPU, GPU ● Accuracy loss: Negligible 2. Post-training dynamic range ● Suitable for CPU, GPU ● Accuracy loss: Least among the rest 3. Post-training integer ● Suitable for CPU, GPU and EdgeTPU ● Accuracy loss: Higher compared to the rest 7 PyData Global 2022
  • 8. Types of Quantization ● Quantization-aware training 1. Happens during model training 2. 8-bit integers precision ● Which one to choose 1. Reduction in model size a. Post-training float16 2. Less loss of accuracy a. Post-training dynamic range b. Post-training integer 8 PyData Global 2022
  • 9. Other ways to reduce model size ● Weight Sharing 1. Cluster weights of each layers into N clusters 2. Share the centroids of each cluster 3. Provides 30-50% reduction in model size with negligible loss in accuracy ● Pruning 1. Remove parameters which are insignificant 9 PyData Global 2022
  • 10. Benchmarks 1. Benchmark results of the recent Tiny MLPerf v0.7 [Link][Paper] 2. EdgeTPU benchmark result of different neural net architectures [Link] 10 PyData Global 2022
  • 11. References 1. https://www.tensorflow.org/lite/performance/model_optimization#quantization 2. https://www.tensorflow.org/model_optimization/guide/clustering#results 3. https://www.tensorflow.org/lite/performance/model_optimization#full_integer_ quantization_with_int16_activations_and_int8_weights 4. https://www.tensorflow.org/model_optimization/guide/quantization/training#res ults 5. https://blog.tensorflow.org/2018/09/introducing-model-optimization-toolkit.html 11 PyData Global 2022
  • 12. Thank You 12 PyData Global 2022 /in/saradindusengupta @iamsaradindu /saradindusengupta