[论文解读] Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
论文提出 ALiBi,一种简单的注意力偏置,使变换器语言模型在没有添加位置嵌入或降低运行时的情况下,能够外推到训练时未见过的更长输入序列。
Since the introduction of the transformer model by Vaswani et al. (2017), a fundamental question has yet to be answered: how does a model achieve extrapolation at inference time for sequences that are longer than it saw during training? We first show that extrapolation can be enabled by simply changing the position representation method, though we find that current methods do not allow for efficient extrapolation. We therefore introduce a simpler and more efficient position method, Attention with Linear Biases (ALiBi). ALiBi does not add positional embeddings to word embeddings; instead, it biases query-key attention scores with a penalty that is proportional to their distance. We show that this method trains a 1.3 billion parameter model on input sequences of length 1024 that extrapolates to input sequences of length 2048, achieving the same perplexity as a sinusoidal position embedding model trained on inputs of length 2048 but training 11% faster and using 11% less memory. ALiBi's inductive bias towards recency also leads it to outperform multiple strong position methods on the WikiText-103 benchmark.
研究动机与目标
- 研究为什么 Transformer 在外推到比训练时更长的序列时会遇到困难。
- 评估现有的位置方法(正弦、旋转、T5 偏置)在外推中的表现。
- 提出一种简单高效的替代方案(ALiBi),通过距离来偏置注意力。
- 证明 ALiBi 能在较短序列上训练、在较长序列推断时具有可靠性。
- 展示在跨领域和不同模型规模(含大规模设置)的适用性。
提出的方法
- 用基于线性距离的偏置替代底层位置嵌入,加入到注意力分数中。
- 在头部级别设定固定的几何等比斜率,以控制外推行为。
- 在较短序列上训练 Transformer 语言模型,在不改变模型参数的情况下评估较长序列的困惑度(perplexity)。
- 将 ALiBi 与正弦、旋转和 T5 偏置基线在速度、内存和困惑度方面进行对比。
- 在 WikiText-103 和 CC100+RoBERTa 领域显示外推性能可达到训练长度的几倍(如 2x–3x 及以上)。
实验结果
研究问题
- RQ1是否仅通过修改位置方法而不对更长序列进行额外训练就能实现对更长输入长度的外推?
- RQ2在不同模型规模和数据集上,ALiBi 与正弦、旋转、T5 偏置在困惑度、速度和内存方面的比较如何?
- RQ3ALiBi 在外推到非常长的序列(如 10,000 token)以及跨多域时能否保持性能?
- RQ4ALiBi 易于实现,且几乎无运行时成本和内存开销?
主要发现
- ALiBi 让模型在短序列上进行训练,在对较长序列进行评测时的困惑度可与正弦基线相当甚至更好。
- 一个 13 亿参数的模型在 L=1024 下使用 ALiBi 训练,在 2048 tokens 评估时达到与在 L=2048 上训练的正弦模型相同的困惑度,且训练速度提升 11%、内存使用减少 11%。
- ALiBi 在外推到长度高达 10,000 tokens 时仍能保持较强的性能。
- 在 WikiText-103 上,ALiBi 模型在 L=512–3072 的训练下,在外推区间中表现优于正弦基线,并具有显著的速度与内存优势。
- 在 CC100+RoBERTa 上,ALiBi 达到与正弦基线相近的困惑度,同时在大规模设置中内存减少 6%–11%、训练速度提升 7%。
- ALiBi 展现出对不同域(书籍)的 transferable 能力,且在不重新调整超参数(斜率)的情况下也能很好地扩展。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。