Improving Transformer Inference Through Optimized Nonlinear Operations With Quantization-Approximation-Based Strategy
- 30 October 2024
- journal article
- Published by Institute of Electrical and Electronics Engineers (IEEE) in IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems
- Vol. 44 (4) , 1475-1488
Abstract
Transformers have recently shown significant performance across various tasks, such as natural language processing (NLP) and computer vision (CV). However, the performance comes at the cost of large memory and computation overhead. Existing researches primarily focus on accelerating matrix multiplication (MatMul) through techniques like quantization and pruning, notably increasing the proportion of nonlinear operations in inference runtime. Meanwhile, previous approaches designed for nonlinear operations struggle with inefficient implementation as they are incapable of achieving both computation and memory efficiency. Additionally, these methods often require retraining or fine-tuning leading to substantial costs and inconveniences. To overcome these problems, we propose efficient implementation of nonlinear operations with quantization-approximation-based strategy. Through an in-depth analysis of the dataflow and data distribution of nonlinear operations, we design distinct quantization and approximation strategies tailored for different operations. Specifically, log2 quantization and power-of-two factor quantization have been employed in Softmax and LayerNorm, complemented by logarithmic function and low-precision statistic calculation as approximation strategies. Furthermore, the proposed efficient GeLU implementation integrates a nonuniform lookup procedure alongside low-bit-width quantization. Experimental results demonstrate negligible accuracy drops without the need for retraining or fine-tuning. By implementing the hardware design, it achieves $3.14\times - 6.34\times $ energy-efficiency and $3.01\times - 10.1\times $ area-efficiency improvements compared to state-of-the-art application-specific-integrated-circuit (ASIC) designs. In system-level evaluation, substantial speedup and reductions in energy consumption of 15% to 35% are achieved for end-to-end inference across both GPU and ASIC accelerator platforms.
Keywords
Funding Information
- National Science and Technology Major Project (2021ZD0114402)
- National Natural Science Foundation of China (92267203)
This publication has 18 references indexed in Scilit:
- Flex-SFU: Accelerating DNN Activation Functions by Non-Uniform Piecewise Approximation2023
- Softermax: Hardware/Software Co-Design of an Efficient Softmax for Transformers2021
- Swin Transformer: Hierarchical Vision Transformer using Shifted Windows2021
- Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers2021
- SpAtten: Efficient Sparse Attention Architecture with Cascade Token and Head Pruning2021
- Hardware Accelerator for Multi-Head Attention and Position-Wise Feed-Forward in the Transformer2020
- A^3: Accelerating Attention Mechanisms in Neural Networks with Approximation2020
- Low-bit Quantization of Neural Networks for Efficient Inference2019
- ImageNet: A large-scale hierarchical image database2009
- Computer Multiplication and Division Using Binary LogarithmsIEEE Transactions on Electronic Computers, 1962