[论文解读] Quantizable Transformers: Removing Outliers by Helping Attention Heads Do Nothing
本文提出两种架构调整——裁剪的 softmax 与门控注意力——以降低 transformer 的激活异常值,使得在无需大量再训练的情况下即可实现直接的 INT8 量化后训练(PTQ)。它展示了在 BERT、OPT 和 ViT 上的量化友好性能提升。
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.
研究动机与目标
- 识别在视觉与语言模型中,激活异常值为何会妨碍 transformer 的量化。
- 提出对注意力的体系结构修改,在不损害 FP 性能的前提下抑制异常值。
- 评估这些修改对跨多种模型家族的 PTQ 性能的影响。
提出的方法
- 分析 transformer 注意力头的异常现象及其与 softmax 和残差连接的相互作用。
- 提出裁剪 softmax 作为一个可直接替换的方案,能够得到精确的零并降低异常值。
- 提出门控注意力,使用一个轻量的头部特定门控网络来调节注意力输出。
- 对模型进行 PTQ 到 INT8 的量化,并比较量化与 FP 的性能及异常值指标。
- 在 BERT-base、OPT-125M 和 ViT-S/16 上基于标准基准进行评估。
实验结果
研究问题
- RQ1在 NLP 与 CV 架构中,导致强烈激活异常值的原因是什么?
- RQ2在不重新训练的前提下,改动注意力机制是否能抑制异常值并改善量化?
- RQ3裁剪的 softmax 与门控注意力在实现更好的 PTQ 结果的同时,是否能保持或提升 FP 性能?
主要发现
- 裁剪的 softmax 与门控注意力显著降低注意力层输出的异常值和峰态。
- 这两种方法在不同模型上提升 W8A8 量化性能,同时保持或有时提升 FP 性能。
- 在所报道的实验中,门控注意力对 OPT 与 ViT 提供了最强的 PTQ 增益。
- 使用门控注意力的 OPT 在最大无限范数和峰态方面显著降低,从而改善量化困惑度(perplexity)。
- BERT 与 ViT 在两种方法下均显示出有利的量化指标,而 OPT 的裁剪 softmax 在本研究的某些配置中表现不佳。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。