[Paper Review] Hardware Accelerator for Multi-Head Attention and Position-Wise Feed-Forward in the Transformer
This paper presents the first FPGA-based hardware accelerator for the two most computationally intensive components in the Transformer model: multi-head attention (MHA) and position-wise feed-forward networks (FFN). By leveraging matrix partitioning, a reconfigurable systolic array, and optimized nonlinear functions like layer normalization and softmax, the design achieves 14.6× speedup in MHA and 3.4× speedup in FFN over a GPU implementation at 200MHz with 16.7W power consumption on an XCVU13P FPGA.
Designing hardware accelerators for deep neural networks (DNNs) has been much desired. Nonetheless, most of these existing accelerators are built for either convolutional neural networks (CNNs) or recurrent neural networks (RNNs). Recently, the Transformer model is replacing the RNN in the natural language processing (NLP) area. However, because of intensive matrix computations and complicated data flow being involved, the hardware design for the Transformer model has never been reported. In this paper, we propose the first hardware accelerator for two key components, i.e., the multi-head attention (MHA) ResBlock and the position-wise feed-forward network (FFN) ResBlock, which are the two most complex layers in the Transformer. Firstly, an efficient method is introduced to partition the huge matrices in the Transformer, allowing the two ResBlocks to share most of the hardware resources. Secondly, the computation flow is well designed to ensure the high hardware utilization of the systolic array, which is the biggest module in our design. Thirdly, complicated nonlinear functions are highly optimized to further reduce the hardware complexity and also the latency of the entire system. Our design is coded using hardware description language (HDL) and evaluated on a Xilinx FPGA. Compared with the implementation on GPU with the same setting, the proposed design demonstrates a speed-up of 14.6x in the MHA ResBlock, and 3.4x in the FFN ResBlock, respectively. Therefore, this work lays a good foundation for building efficient hardware accelerators for multiple Transformer networks.
Motivation & Objective
- To address the lack of dedicated hardware accelerators for the Transformer model, which dominates modern NLP but has high computational and memory demands.
- To enable efficient inference of Transformer models on mobile and embedded systems by reducing latency and power consumption.
- To design a reconfigurable hardware architecture that efficiently accelerates the two most complex layers: MHA ResBlock and FFN ResBlock.
- To optimize resource sharing between MHA and FFN by partitioning large matrices and reusing systolic array hardware.
- To minimize latency of critical nonlinear operations like layer normalization and scaled masked-softmax through early computation and hardware-friendly approximations.
Proposed method
- Matrix partitioning is applied to large matrices in MHA and FFN to allow shared use of the systolic array across both components.
- A reconfigurable systolic array is used as the core computation unit, with a carefully designed dataflow to maximize hardware utilization.
- The scaled masked-softmax is optimized using fixed-point arithmetic and a log-sum-exp trick to reduce complexity and latency.
- Layer normalization is accelerated by precomputing the mean and using an algebraic identity to compute variance in fewer cycles: $var(G,i) = E(G,i)^2 - \frac{1}{d_{model}}\sum_{k=1}^{d_{model}} G(i,k)^2$.
- A lookup table is used for the $x \hat{~{}} (-0.5)$ operation in layer normalization to reduce critical path delay.
- The entire design is implemented in HDL and synthesized on a Xilinx xcvu13p-fhga2104-3-e FPGA with 8-bit integer quantization.
Experimental results
Research questions
- RQ1Can a single hardware accelerator efficiently handle both the multi-head attention and position-wise feed-forward blocks in the Transformer architecture?
- RQ2How can matrix partitioning and systolic array reuse be leveraged to minimize area and power consumption while maintaining high throughput?
- RQ3What optimizations are required for nonlinear functions like softmax and layer normalization to reduce their latency in hardware?
- RQ4To what extent can FPGA-based acceleration outperform GPU inference in terms of latency and energy efficiency for Transformer inference?
- RQ5Can hardware-optimized implementations of attention and feed-forward layers maintain model accuracy after quantization to INT8?
Key findings
- The proposed accelerator achieves a 14.6× speedup in the MHA ResBlock compared to a GPU implementation on an NVIDIA V100.
- The FFN ResBlock achieves a 3.4× speedup over the same GPU baseline under identical settings (batch size = 1, sequence length = 64).
- The FPGA design operates at 200MHz with a total on-chip power consumption of 16.7W, including 13.3W dynamic and 3.4W static power.
- The systolic array utilization is maximized through a carefully designed computation flow that enables reconfiguration between MHA and FFN operations.
- The layer normalization module reduces latency by precomputing the mean and using an algebraic identity to compute variance in fewer cycles, minimizing the critical path.
- The quantized Transformer base model using 8-bit integers maintains a BLEU score of 23.57 on the IWSLT 2016 German-English translation task, demonstrating minimal accuracy loss.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.