Optimizing the Deployment of Tiny Transformers on Low-Power MCUs

IF 3.8 2区 计算机科学 Q2 COMPUTER SCIENCE, HARDWARE & ARCHITECTURE IEEE Transactions on Computers Pub Date : 2024-11-18 DOI:10.1109/TC.2024.3500360
Victor Jean-Baptiste Jung;Alessio Burrello;Moritz Scherer;Francesco Conti;Luca Benini
{"title":"Optimizing the Deployment of Tiny Transformers on Low-Power MCUs","authors":"Victor Jean-Baptiste Jung;Alessio Burrello;Moritz Scherer;Francesco Conti;Luca Benini","doi":"10.1109/TC.2024.3500360","DOIUrl":null,"url":null,"abstract":"Transformer networks are rapidly becoming State of the Art (SotA) in many fields, such as Natural Language Processing (NLP) and Computer Vision (CV). Similarly to Convolutional Neural Networks (CNNs), there is a strong push for deploying Transformer models at the extreme edge, ultimately fitting the tiny power budget and memory footprint of Micro-Controller Units (MCUs). However, the early approaches in this direction are mostly ad-hoc, platform, and model-specific. This work aims to enable and optimize the flexible, multi-platform deployment of encoder Tiny Transformers on commercial MCUs. We propose a complete framework to perform end-to-end deployment of Transformer models onto single and multi-core MCUs. Our framework provides an optimized library of kernels to maximize data reuse and avoid unnecessary data marshaling operations into the crucial attention block. A novel Multi-Head Self-Attention (MHSA) inference schedule, named Fused-Weight Self-Attention (FWSA), is introduced, fusing the linear projection weights offline to further reduce the number of operations and parameters. Furthermore, to mitigate the memory peak reached by the computation of the attention map, we present a Depth-First Tiling (DFT) scheme for MHSA tailored for cache-less MCU devices that allows splitting the computation of the attention map into successive steps, never materializing the whole matrix in memory. We evaluate our framework on three different MCU classes exploiting ARM and RISC-V Instruction Set Architecture (ISA), namely the STM32H7 (ARM Cortex M7), the STM32L4 (ARM Cortex M4), and GAP9 (RV32IMC-XpulpV2). We reach an average of 4.79 <inline-formula><tex-math>$\\times$</tex-math></inline-formula> and 2.0 <inline-formula><tex-math>$\\times$</tex-math></inline-formula> lower latency compared to SotA libraries CMSIS-NN (ARM) and PULP-NN (RISC-V), respectively. Moreover, we show that our MHSA depth-first tiling scheme reduces the memory peak by up to 6.19 <inline-formula><tex-math>$\\times$</tex-math></inline-formula>, while the fused-weight attention can reduce the runtime by 1.53 <inline-formula><tex-math>$\\times$</tex-math></inline-formula>, and number of parameters by 25%. Leveraging the optimizations proposed in this work, we run end-to-end inference of three SotA Tiny Transformers for three applications characterized by different input dimensions and network hyperparameters. We report significant improvements across the networks: for instance, when executing a transformer block for the task of radar-based hand-gesture recognition on GAP9, we achieve a latency of <inline-formula><tex-math>$0.14 \\textrm{ms}$</tex-math></inline-formula> and energy consumption of <inline-formula><tex-math>$4.92 \\boldsymbol{\\mu}\\textrm{J}$</tex-math></inline-formula>, 2.32 <inline-formula><tex-math>$\\times$</tex-math></inline-formula> lower than the SotA PULP-NN library on the same platform.","PeriodicalId":13087,"journal":{"name":"IEEE Transactions on Computers","volume":"74 2","pages":"526-541"},"PeriodicalIF":3.8000,"publicationDate":"2024-11-18","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"IEEE Transactions on Computers","FirstCategoryId":"94","ListUrlMain":"https://ieeexplore.ieee.org/document/10755971/","RegionNum":2,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q2","JCRName":"COMPUTER SCIENCE, HARDWARE & ARCHITECTURE","Score":null,"Total":0}
引用次数: 0

Abstract

Transformer networks are rapidly becoming State of the Art (SotA) in many fields, such as Natural Language Processing (NLP) and Computer Vision (CV). Similarly to Convolutional Neural Networks (CNNs), there is a strong push for deploying Transformer models at the extreme edge, ultimately fitting the tiny power budget and memory footprint of Micro-Controller Units (MCUs). However, the early approaches in this direction are mostly ad-hoc, platform, and model-specific. This work aims to enable and optimize the flexible, multi-platform deployment of encoder Tiny Transformers on commercial MCUs. We propose a complete framework to perform end-to-end deployment of Transformer models onto single and multi-core MCUs. Our framework provides an optimized library of kernels to maximize data reuse and avoid unnecessary data marshaling operations into the crucial attention block. A novel Multi-Head Self-Attention (MHSA) inference schedule, named Fused-Weight Self-Attention (FWSA), is introduced, fusing the linear projection weights offline to further reduce the number of operations and parameters. Furthermore, to mitigate the memory peak reached by the computation of the attention map, we present a Depth-First Tiling (DFT) scheme for MHSA tailored for cache-less MCU devices that allows splitting the computation of the attention map into successive steps, never materializing the whole matrix in memory. We evaluate our framework on three different MCU classes exploiting ARM and RISC-V Instruction Set Architecture (ISA), namely the STM32H7 (ARM Cortex M7), the STM32L4 (ARM Cortex M4), and GAP9 (RV32IMC-XpulpV2). We reach an average of 4.79 $\times$ and 2.0 $\times$ lower latency compared to SotA libraries CMSIS-NN (ARM) and PULP-NN (RISC-V), respectively. Moreover, we show that our MHSA depth-first tiling scheme reduces the memory peak by up to 6.19 $\times$, while the fused-weight attention can reduce the runtime by 1.53 $\times$, and number of parameters by 25%. Leveraging the optimizations proposed in this work, we run end-to-end inference of three SotA Tiny Transformers for three applications characterized by different input dimensions and network hyperparameters. We report significant improvements across the networks: for instance, when executing a transformer block for the task of radar-based hand-gesture recognition on GAP9, we achieve a latency of $0.14 \textrm{ms}$ and energy consumption of $4.92 \boldsymbol{\mu}\textrm{J}$, 2.32 $\times$ lower than the SotA PULP-NN library on the same platform.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
小型变压器在低功耗mcu上的优化部署
在自然语言处理(NLP)和计算机视觉(CV)等许多领域,变压器网络正迅速成为最先进的技术(SotA)。与卷积神经网络(cnn)类似,人们强烈要求在极端边缘部署Transformer模型,最终满足微控制器单元(mcu)的微小功率预算和内存占用。然而,这个方向的早期方法大多是特别的、平台的和特定于模型的。这项工作旨在实现并优化编码器微型变压器在商用mcu上的灵活、多平台部署。我们提出了一个完整的框架来执行变压器模型到单核和多核mcu的端到端部署。我们的框架提供了一个优化的内核库,以最大限度地提高数据重用,避免不必要的数据封送操作进入关键的注意力块。提出了一种新的多头自注意(MHSA)推理方案——融合权值自注意(FWSA),将线性投影权值离线融合,进一步减少了运算次数和参数。此外,为了缓解注意图计算所达到的内存峰值,我们提出了一种针对无缓存MCU设备的MHSA深度优先平铺(DFT)方案,该方案允许将注意图的计算拆分为连续的步骤,而不会在内存中实现整个矩阵。我们在利用ARM和RISC-V指令集架构(ISA)的三种不同的MCU类上评估我们的框架,即STM32H7 (ARM Cortex M7), STM32L4 (ARM Cortex M4)和GAP9 (RV32IMC-XpulpV2)。与SotA库CMSIS-NN (ARM)和纸浆- nn (RISC-V)相比,我们的平均延迟分别降低了4.79美元和2.0美元。此外,我们表明,我们的MHSA深度优先平铺方案可以减少内存峰值高达6.19 $\times$,而融合权重关注可以减少运行时间1.53 $\times$,参数数量减少25%。利用在这项工作中提出的优化,我们运行三个SotA微型变压器的端到端推理,以不同的输入维度和网络超参数为特征的三个应用。我们报告显著改善整个网络:例如,当执行一个变压器块对GAP9雷达手势识别的任务,我们达到0.14美元的延迟\ textrm{}女士和能源消耗的4.92美元\ boldsymbol{\μ}\ textrm {J},美元2.32 \倍低于美元SotA PULP-NN图书馆在同一平台。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
IEEE Transactions on Computers
IEEE Transactions on Computers 工程技术-工程:电子与电气
CiteScore
6.60
自引率
5.40%
发文量
199
审稿时长
6.0 months
期刊介绍: The IEEE Transactions on Computers is a monthly publication with a wide distribution to researchers, developers, technical managers, and educators in the computer field. It publishes papers on research in areas of current interest to the readers. These areas include, but are not limited to, the following: a) computer organizations and architectures; b) operating systems, software systems, and communication protocols; c) real-time systems and embedded systems; d) digital devices, computer components, and interconnection networks; e) specification, design, prototyping, and testing methods and tools; f) performance, fault tolerance, reliability, security, and testability; g) case studies and experimental and theoretical evaluations; and h) new and important applications and trends.
期刊最新文献
GRASP: Accelerating Hash-Based PQC Performance on GPU Parallel Architecture FlexClave: An Extensible and Secure Trusted Execution Environment Framework Collaborative Prediction of Cloud DRAM Failures With Rules and Machine Learning Hardware-Efficient Taylor Series-Based Optimal Unsigned Square Rooter for Fast and Low Power Computation MalPDT: Backdoor Attack Against Static Malware Detection With Plug-and-Play Dynamic Triggers
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1