Genetic Quantization-Aware Approximation for Non-Linear Operations in Transformers

Pingcheng Dong, Yonghao Tan, Dong Zhang, Tianwei Ni, Xuejiao Liu, Yu Liu, Peng Luo, Luhong Liang, Shih-Yang Liu, Xijie Huang, Huaiyu Zhu, Yun Pan, Fengwei An, Kwang-Ting Cheng · DOI

This paper, presented at DAC 2024, introduces GQA-LUT, a method to make Transformer models significantly more hardware-efficient by rethinking how we handle non-linear operations like GELU, Softmax, and LayerNorm in quantized environments.

Introduction

While quantization—converting 32-bit floats to 8-bit integers—has drastically reduced the cost of linear layers in neural networks, non-linear operations remain a stubborn bottleneck. Functions like GELU, Exponential (EXP), and Reciprocal Square Root (RSQRT) are mathematically complex and usually require high-precision (FP32 or INT32) arithmetic to maintain accuracy. Existing solutions often use Piece-Wise Linear (PWL) approximation, which approximates a curve with a series of small straight lines stored in a Look-Up Table (LUT). However, these methods typically ignore the "scaling factor" used in integer-only quantization, leading to significant approximation errors.

The Problem: Breakpoint Deviation

When a model is quantized, the "distance" between integer steps changes across layers. If the LUT breakpoints aren't aware of these shifts, a phenomenon called breakpoint deviation occurs. This is where the approximation significantly misses the target because the quantized input values no longer align with the pre-calculated breakpoints, leading to a "quantization cliff" in model performance.

The GQA-LUT Framework

The authors propose a Genetic Quantization-Aware LUT (GQA-LUT) framework to address these challenges. The core idea is to treat the selection of LUT breakpoints as an evolutionary optimization problem rather than a manual tuning task.

  1. Genetic Piece-Wise Linear Approximation: GQA-LUT uses a genetic algorithm to maintain a population of potential breakpoint sets, evolving them through crossover and mutation to minimize the Mean Squared Error (MSE) against the target function.
  2. Quantization-Awareness: The algorithm specifically optimizes for integer-only pipelines by enforcing power-of-two scaling factors. This allows hardware to replace expensive division operations with simple bit-shifts.
  3. Rounding Mutation (RM): To solve breakpoint deviation, the authors introduced a novel mutation strategy. During the genetic search, breakpoints are randomly perturbed and rounded across various scales, "training" the LUT to be robust regardless of the input scaling factor.
  4. Multi-Range Input Scaling: For functions with massive input ranges (like Division or RSQRT), the framework splits the input into sub-ranges, each with its own optimized power-of-two scale.

Hardware Architecture Efficiency

Traditional LUT-based approximations often operate in high-precision FP32 or INT32 domains to maintain accuracy. As shown in Figure 1(a), this requires high-precision multipliers and adders. In contrast, GQA-LUT (Figure 1(b)) integrates a quantizer and utilizes power-of-two scaling factors ($S=2^N$). This design choice allows the hardware to replace expensive multiplication and division with simple bit-shift operations (>>), significantly reducing the silicon footprint.

Comparison of traditional high-precision LUT architecture (a) and the proposed quantization-aware INT8/16 GQA-LUT architecture (b).

Key Results

Hardware and Accuracy Performance

On a TSMC 28nm process, the INT8 GQA-LUT achieved an 81.3%–81.7% reduction in silicon area and a 79.3%–80.2% reduction in power consumption compared to high-precision FP32/INT32 units. Despite these savings, accuracy loss remained negligible. On the Cityscapes semantic segmentation task, replacing standard non-linearities with GQA-LUT resulted in a tiny drop in mIoU: only 0.07% for Segformer and 0.02% for EfficientViT.

Comparison with State-of-the-Art

The effectiveness of GQA-LUT was validated across several common non-linear operators. As illustrated in Figure 6, GQA-LUT consistently achieves significantly lower Normalized Mean Squared Error (MSE) compared to the previous state-of-the-art, NN-LUT, across various quantization scales ($S$). The improvement is most pronounced at larger scales, where traditional methods typically fail due to breakpoint deviation.

Normalized MSE comparison between NN-LUT and the proposed GQA-LUT across different operators (GELU, HSWISH, EXP) and quantization scales.

Conclusion

GQA-LUT demonstrates that by co-designing the approximation algorithm with the underlying hardware quantization constraints, it is possible to achieve massive efficiency gains in Transformers. By replacing complex arithmetic with optimized INT8 LUTs and bit-shifts, GQA-LUT paves the way for deploying sophisticated Transformer models on resource-constrained edge devices without sacrificing accuracy.

Summary updated

BibTeX
@inproceedings{dong2024genetic,
  author = {Pingcheng Dong and Yonghao Tan and Dong Zhang and Tianwei Ni and Xuejiao Liu and Yu Liu and Peng Luo and Luhong Liang and Shih-Yang Liu and Xijie Huang and Huaiyu Zhu and Yun Pan and Fengwei An and Kwang-Ting Cheng},
  title = {{Genetic Quantization-Aware Approximation for Non-Linear Operations in Transformers}},
  booktitle = {DAC},
  year = {2024},
  doi = {10.1145/3649329.3657314},
}
Figure