Reusing Softmax Hardware Unit for GELU Computation in Transformers
Christodoulos Peltekis, Kosmas Alexandridis, Giorgos Dimitrakopoulos
TL;DR
This work addresses the hardware inefficiency of separately computing GELU and softmax in transformers. It derives a mathematical transformation that expresses GELU as GELU$(z) = z\,\text{softmax}^2_1([k,-k])$ with $k = \sqrt{2/\pi}\,(z + 0.044715 z^3)$, enabling GELU to be computed using a softmax unit. A dual-mode softmax core is proposed to operate on either $N$ inputs (normal softmax) or $N/2$ two-element subvectors (GELU mode), along with overhead circuitry to compute $k$ and finalize GELU results; the unit can compute multiple GELUs in parallel. Experimental results show unchanged accuracy on GLUE benchmarks with the proposed approach and demonstrate hardware savings: around $6.1\%$ area and $11.9\%$ power on average for the combined GELU-softmax unit, with additional details on dual-mode overhead and throughput gains. Overall, the method enables efficient transformer acceleration by reusing softmax hardware, reducing area and power while maintaining NLP performance.
Abstract
Transformers have improved drastically the performance of natural language processing (NLP) and computer vision applications. The computation of transformers involves matrix multiplications and non-linear activation functions such as softmax and GELU (Gaussion Error Linear Unit) that are accelerated directly in hardware. Currently, function evaluation is done separately for each function and rarely allows for hardware reuse. To mitigate this problem, in this work, we map the computation of GELU to a softmax operator. In this way, the efficient hardware units designed already for softmax can be reused for computing GELU as well. Computation of GELU can enjoy the inherent vectorized nature of softmax and produce in parallel multiple GELU outcomes. Experimental results show that computing GELU via a pre-existing and incrementally modified softmax hardware unit (a) does not reduce the accuracy of representative NLP applications and (b) allows the reduction of the overall hardware area and power by 6.1% and 11.9%, respectively, on average.
