当精度遇上位置:BFloat16在长上下文训练中破坏RoPE
When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Training
AI总结:
针对BFloat16格式下RoPE在长上下文训练中因精度有限出现数值问题的现象,提出即插即用的AnchorAttention方法,将首个token作为共享锚点,显著提升长上下文性能,训练时间减少超50%且保留通用任务能力。
摘要:
扩展上下文窗口大小使大型语言模型(LLMs)能够处理更长的序列和更复杂的任务。旋转位置嵌入(RoPE)因其相对位置编码特性有利于长上下文训练,已成为事实上的标准。然而,我们观察到使用BFloat16格式的RoPE会导致数值问题,使其偏离预期的相对位置编码,尤其在长上下文场景中。该问题源于BFloat16有限的精度,并随上下文长度增加而累积,其中第一个token对该问题贡献显著。为解决此问题,我们开发了AnchorAttention,一种即插即用的注意力方法,可缓解BFloat16导致的数值问题,提升长上下文能力并加速训练。AnchorAttention将第一个token视为具有一致位置ID的共享锚点,使其对训练上下文中的所有文档可见,从而减少不必要的注意力计算,保持语义连贯性并提高计算效率。在三种类型的LLM上进行的实验表明,与标准全注意力机制相比,AnchorAttention显著提升了长上下文性能,训练时间减少超过50%,同时保留了原始LLM在通用任务上的能力。我们的代码可在https://github.com/haonan3/AnchorContext获取。
英文摘要:
Extending context window sizes allows large language models (LLMs) to process longer sequences and handle more complex tasks. Rotary Positional Embedding (RoPE) has become the de facto standard due to its relative positional encoding properties that benefit long-context training. However, we observe that using RoPE with BFloat16 format results in numerical issues, causing it to deviate from its intended relative positional encoding, especially in long-context scenarios. This issue arises from BFloat16's limited precision and accumulates as context length increases, with the first token contributing significantly to this problem. To address this, we develop AnchorAttention, a plug-and-play attention method that alleviates numerical issues caused by BFloat16, improves long-context capabilities, and speeds up training. AnchorAttention reduces unnecessary attention computations, maintains semantic coherence, and boosts computational efficiency by treating the first token as a shared anchor with a consistent position ID, making it visible to all documents within the training context. Experiments on three types of LLMs demonstrate that AnchorAttention significantly improves long-context performance and reduces training time by over 50\% compared to standard full attention mechanisms, while preserving the original LLM's capabilities on general tasks. Our code is available at https://github.com/haonan3/AnchorContext.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。