arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2306.12929cs.LGcs.AIcs.CLcs.CV
收藏

可量化Transformer:通过帮助注意力头实现无操作来消除离群值

Quantizable Transformers: Removing Outliers by Helping Attention Heads Do Nothing

Qualcomm AI Research(高通人工智能研究院)

Yelysei Bondarenko, Markus Nagel, Tijmen Blankevoort

AI总结:

针对Transformer激活值存在强离群值导致难以量化的问题,提出裁剪softmax和门控注意力两种改进,减小离群值的同时保持甚至提升性能,可实现激活值全INT8量化,在语言模型和视觉Transformer上均验证有效。

摘要:

近年来,Transformer模型已在多个领域得到广泛应用,尤其是大语言模型极大推动了人工智能领域的发展。随着模型规模扩大,这类网络的能力大幅提升,但代价是所需计算量显著增加。量化是减少神经网络计算时间和内存消耗的最有效方法之一。然而,多项研究表明,现代Transformer模型的激活值中往往会学习到强离群值,导致其难以量化。为了保持可接受的性能,这些离群值的存在要求激活值采用更高位宽、使用不同数值格式、额外微调或其他变通方案。我们发现,强离群值与注意力头的一种特殊行为密切相关:这些注意力头试图学习“无操作”(no-op),即仅对残差进行部分更新。为了实现无更新所需的注意力矩阵中的精确零值,softmax的输入在训练过程中被推得越来越大,从而在网络的其他部分引发离群值。基于这些观察,我们对注意力机制提出了两种简单且相互独立的改进——裁剪softmax(clipped softmax)和门控注意力(gated attention)。实验结果表明,使用我们的方法预训练的模型,其离群值规模显著减小,同时浮点任务性能得以保持,有时甚至有所提升。这使得我们无需额外操作即可将Transformer的激活值完全量化为INT8精度。我们在语言模型(BERT、OPT)和视觉Transformer上均验证了所提方法的有效性。

英文摘要:

Transformer models have been widely adopted in various domains over the last years, and especially large language models have advanced the field of AI significantly. Due to their size, the capability of these networks has increased tremendously, but this has come at the cost of a significant increase in necessary compute. Quantization is one of the most effective ways to reduce the computational time and memory consumption of neural networks. Many studies have shown, however, that modern transformer models tend to learn strong outliers in their activations, making them difficult to quantize. To retain acceptable performance, the existence of these outliers requires activations to be in higher bitwidth or the use of different numeric formats, extra fine-tuning, or other workarounds. We show that strong outliers are related to very specific behavior of attention heads that try to learn a "no-op" or just a partial update of the residual. To achieve the exact zeros needed in the attention matrix for a no-update, the input to the softmax is pushed to be larger and larger during training, causing outliers in other parts of the network. Based on these observations, we propose two simple (independent) modifications to the attention mechanism - clipped softmax and gated attention. We empirically show that models pre-trained using our methods learn significantly smaller outliers while maintaining and sometimes even improving the floating-point task performance. This enables us to quantize transformers to full INT8 quantization of the activations without any additional effort. We demonstrate the effectiveness of our methods on both language models (BERT, OPT) and vision transformers.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑