SWAA:滑动窗口注意力适应用于高效且保质的长上下文处理
SWAA: Sliding Window Attention Adaptation for Efficient and Quality Preserving Long Context Processing
AI总结:
本文提出SWAA,通过结合四种核心策略,解决Transformer模型中长上下文处理的效率与质量问题,实现30%-100%的加速提升同时保持高质量。
摘要:
Transformer基于的LLM中的自注意力二次复杂度使得长上下文推理成本过高。虽然滑动窗口注意力(SWA)提供了线性复杂度的替代方案,但其在长上下文处理中表现出崩溃,源于两个根本因素:在简单应用SWA到预训练全注意力(FA)模型时的训练推理不匹配,以及在所有模块中始终应用SWA时固有的无法访问远距离信息的结构限制。为解决这两个挑战,我们提出滑动窗口注意力适应(SWAA),一种即插即用的工具包,通过系统结合四个核心策略来应对这些不同问题:(1)全注意力(FA)解码;(2)交替FA和SWA层,通过选择性允许访问远距离信息来缓解结构缺陷;(3)保留“sink”标记;(4)轻量级微调,以缓解训练推理不匹配。我们的实验表明,虽然孤立策略不足,但特定协同组合有效恢复长上下文性能。尽管计算开销各异,我们的性能效率权衡分析确定了适用于不同场景的最优SWAA配置,实现了长上下文推理的30%至100%加速,同时保持可接受的质量保留。我们的代码、数据和模型权重可在https://github.com/yuyijiong/sliding-window-attention-adaptation获取。
英文摘要:
The quadratic complexity of self attention in Transformer based LLMs renders long context inference prohibitively expensive. While Sliding Window Attention (SWA), the simplest sparse attention pattern, offers a linear complexity alternative, it suffers from catastrophic long context performance collapse, which stems from two fundamental factors: the training inference mismatch when naively applying SWA to models pretrained with Full Attention (FA), and the inherent structural inability to access distant information when applying SWA to every module at all times. To address these dual challenges, we propose Sliding Window Attention Adaptation (SWAA), a plug and play toolkit of recipes that adapts FA models to SWA without costly pretraining. SWAA systematically combines four core strategies to tackle these distinct issues: (1) Full Attention (FA) Decode and (2) Interleaving FA and SWA layers, which mitigate structural defects by selectively allowing access to distant information; alongside (3) preserving ``sink'' tokens and (4) lightweight fine tuning, which mitigate the training inference mismatch. Our experiments reveal that while isolated strategies are insufficient, specific synergistic combinations effectively recover long context performance. Despite varying computational overheads, our performance efficiency trade off analysis identifies optimal SWAA configurations for diverse scenarios, achieving 30% to 100% speedups for long context inference with acceptable quality retention. Our code, data and model weights are available at https://github.com/yuyijiong/sliding-window-attention-adaptation
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。