Skip to main content
QUICK REVIEW

[论文解读] An Efficient FPGA-Based Accelerator for Swin Transformer

Zhiyang Liu, Pengyu Yin|arXiv (Cornell University)|Aug 26, 2023
Advanced Memory and Neural ComputingEngineering被引用 3
一句话总结

本论文提出了一种高效的FPGA加速器,用于Swin Transformer,通过将层归一化(Layer Normalization)替换为批归一化(Batch Normalization)以实现硬件融合,设计了近似但硬件友好的Softmax和GELU单元,并采用统一的矩阵乘法单元(Matrix Multiplication Unit)处理所有线性运算。该加速器在CPU上实现了最高1.76倍的加速比和20.45倍更高的能效,其速度和能效均优于现有的FPGA加速器。

ABSTRACT

Since introduced, Swin Transformer has achieved remarkable results in the field of computer vision, it has sparked the need for dedicated hardware accelerators, specifically catering to edge computing demands. For the advantages of flexibility, low power consumption, FPGAs have been widely employed to accelerate the inference of convolutional neural networks (CNNs) and show potential in Transformer-based models. Unlike CNNs, which mainly involve multiply and accumulate (MAC) operations, Transformer involve non-linear computations such as Layer Normalization (LN), Softmax, and GELU. These nonlinear computations do pose challenges for accelerator design. In this paper, to propose an efficient FPGA-based hardware accelerator for Swin Transformer, we focused on using different strategies to deal with these nonlinear calculations and efficiently handling MAC computations to achieve the best acceleration results. We replaced LN with BN, Given that Batch Normalization (BN) can be fused with linear layers during inference to optimize inference efficiency. The modified Swin-T, Swin-S, and Swin-B respectively achieved Top-1 accuracy rates of 80.7%, 82.7%, and 82.8% in ImageNet. Furthermore, We employed strategies for approximate computation to design hardware-friendly architectures for Softmax and GELU computations. We also designed an efficient Matrix Multiplication Unit to handle all linear computations in Swin Transformer. As a conclude, compared with CPU (AMD Ryzen 5700X), our accelerator achieved 1.76x, 1.66x, and 1.25x speedup and achieved 20.45x, 18.60x, and 14.63x energy efficiency (FPS/power consumption) improvement on Swin-T, Swin-S, and Swin-B models, respectively. Compared to GPU (Nvidia RTX 2080 Ti), we achieved 5.05x, 4.42x, and 3.00x energy efficiency improvement respectively. As far as we know, the accelerator we proposed is the fastest FPGA-based accelerator for Swin Transformer.

研究动机与目标

  • 为解决在FPGA上加速Swin Transformer的挑战,该挑战涉及Softmax和GELU等复杂非线性运算,这些运算资源消耗大且延迟高。
  • 通过将FPGA硬件中效率低下的层归一化(LN)替换为批归一化(BN),以实现与线性层的融合,从而提升推理效率。
  • 设计仅使用移位、加法和乘法操作的非线性函数(Softmax和GELU)的硬件友好近似,以减少FPGA资源使用和延迟。
  • 开发一个统一的矩阵乘法单元(MMU),高效处理Swin Transformer中所有线性计算,利用其矩阵运算的结构特性。
  • 通过优化整个加速器栈以适配FPGA部署,实现在边缘设备上的高速、低功耗推理。

提出的方法

  • 在Swin-T、Swin-S和Swin-B模型中将层归一化(LN)替换为批归一化(BN),以实现与线性层的融合,降低计算开销并提升硬件映射效率。
  • 将PatchEmbed的卷积操作转换为矩阵乘法,统一处理线性计算,提升硬件利用率。
  • 设计基于以2为底的指数运算和移位-加法操作的Softmax与GELU的近似硬件架构,最大限度减少对复杂除法和超越函数的依赖。
  • 实现一个单一且高效的矩阵乘法单元(MMU),支持Swin Transformer中所有矩阵乘法操作,针对其使用的特定矩阵形状和数据类型进行优化。
  • 采用定点数运算(Fix16)以减少资源消耗,同时保持高精度,在ImageNet上的模型精度损失小于0.5%。
  • 使用HWiNFO64(CPU)、MSI Afterburner(GPU)和Vivado Power Report(FPGA)进行功耗与性能测量,以评估能效。

实验结果

研究问题

  • RQ1在Swin Transformer中用批归一化(BN)替代层归一化(LN)是否能实现高效的硬件融合,并在不造成显著精度损失的前提下减少FPGA资源使用?
  • RQ2如何仅使用移位、加法和乘法操作对Softmax和GELU等非线性运算进行近似,以减少FPGA资源消耗和延迟?
  • RQ3如何设计一个最优的统一矩阵乘法单元(MMU),以最小面积和最高吞吐量支持Swin Transformer中所有线性运算?
  • RQ4与CPU和GPU基线相比,所提出的FPGA加速器在Swin Transformer推理中的速度和能效表现如何?
  • RQ5所提出的加速器在吞吐量、能效和资源利用率方面是否优于现有基于FPGA的Swin Transformer加速器?

主要发现

  • 修改后的Swin-T、Swin-S和Swin-B模型在ImageNet上的Top-1精度分别为80.7%、82.7%和82.8%,与原始模型相比仅出现轻微下降。
  • 与AMD Ryzen 5700X CPU相比,该FPGA加速器在Swin-T、Swin-S和Swin-B上分别实现了1.76倍、1.66倍和1.25倍的加速比。
  • 该加速器在三种模型上分别比CPU实现了20.45倍、18.60倍和14.63倍更高的能效(FPS/watt)。
  • 与Nvidia RTX 2080 Ti GPU相比,该加速器在三种模型上分别实现了5.05倍、4.42倍和3.00倍更高的能效。
  • Swin-T、Swin-S和Swin-B的功耗分别为10.69W、10.69W和11.11W,显著低于GPU的240W。
  • 所提出的加速器在吞吐量和能效方面优于现有FPGA加速器,Swin-T实现431.2 GOPS,仅使用1727个DSP,是迄今报告的最快FPGA-based Swin Transformer加速器。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。