arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.17174cs.CL
收藏

从注意力到激活:揭开大语言模型的谜团

From Attention to Activation: Unravelling the Enigmas of Large Language Models

Institute of Automation, Chinese Academy of Sciences (CASIA)(中国科学院自动化研究所)

Prannay Kaul, Chengcheng Ma, Ismail Elezi, Jiankang Deng

AI总结:

本文针对自回归Transformer中第一个token注意力过强和隐藏状态异常激活值两大问题,提出softmax-1和OrthoAdam优化器,显著改善注意力分布、激活峰度及量化性能。

摘要:

我们研究自回归Transformer中的两个奇怪现象:(1)注意力头中第一个token的主导地位;(2)隐藏状态中出现较大的异常激活值。我们发现,Llama等流行的大语言模型在98%的注意力头中最大程度地关注第一个token,我们将这种行为归因于softmax函数。为了缓解这一问题,我们提出将softmax重新表述为softmax-1。此外,我们确定自适应优化器(如Adam)是导致较大异常激活值的主要因素,并引入OrthoAdam,这是一种利用正交矩阵变换梯度的新型优化器,以解决该问题。最后,我们的方法不仅能防止这些现象发生,还能使Transformer在使用基本算法进行量化时保持其性能,而标准方法无法做到这一点。总之,我们的方法将第一个token上的注意力比例从65%降低到3.3%,将隐藏状态中的激活峰度从1657降低到3.1,并将4位权重量化下的困惑度惩罚从3565降低到0.3。

英文摘要:

We study two strange phenomena in auto-regressive Transformers: (1) the dominance of the first token in attention heads; (2) the occurrence of large outlier activations in the hidden states. We find that popular large language models, such as Llama attend maximally to the first token in 98% of attention heads, a behaviour we attribute to the softmax function. To mitigate this issue, we propose a reformulation of softmax to softmax-1. Furthermore, we identify adaptive optimisers, e.g. Adam, as the primary contributor to the large outlier activations and introduce OrthoAdam, a novel optimiser that utilises orthogonal matrices to transform gradients, to address this issue. Finally, not only do our methods prevent these phenomena from occurring, but additionally, they enable Transformers to sustain their performance when quantised using basic algorithms, something that standard methods are unable to do. In summary, our methods reduce the attention proportion on the first token from 65% to 3.3%, the activation kurtosis in the hidden states from 1657 to 3.1, and perplexity penalty under 4-bit weight quantisation from 3565 to 0.3.

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

↑