TensorX
返回文献探索

Paper · arXiv 2411.13476

When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Training

Haonan Wang, Qian Liu, Chao Du, Tongyao Zhu, Cunxiao Du, Kenji Kawaguchi, Tianyu Pang

15 upvotesNovember 20, 2024arXiv 预印本
AI 摘要

AnchorAttention improves the long-context performance and training efficiency of large language models by addressing numerical issues with BFloat16 and Rotary Positional Embedding.

large language modelscontext window sizesRotary Positional EmbeddingBFloat16numerical issuesrelative positional encodinglong-context trainingAnchorAttentionattention methodsemantic coherencecomputational efficiencyshared anchorposition IDfull attention mechanisms

Abstract

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.

北京市昌平区探索星信息技术及软件开发工作室

京ICP备2026059466号
When Precision Meets Position: BFloat16 Breaks Down RoPE in Long-Context Training | TensorX