隐稀疏注意力:迈向亚二次复杂度的超长上下文注意力
Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention
AI总结:
针对超长上下文下全注意力成本过高、现有稀疏注意力精度不足或复杂度高的问题,提出隐稀疏注意力及其两种变体,在保持精度的同时大幅提升超长上下文下的注意力速度。
摘要:
智能体工作流正日益转向长周期任务,如开放性科学研究,这类任务中模型得益于长上下文窗口。然而在100万token以上的超长上下文场景下,全注意力的计算成本高得难以承受。稀疏注意力是一种有前景的方法,它通过专用索引器为注意力选择部分键,但当前的索引方法要么在上下文规模上仍具有二次复杂度,要么在超长上下文场景下精度下降。我们提出隐稀疏注意力(Latent Sparse Attention, LSA),这是一种在超长上下文下保持精度的高效注意力方法。在LSA中,键在学习到的隐空间中被分层聚类,查询对聚类层次进行打分而非对每个键打分,这使得长上下文下的预填充、解码和训练速度更快。我们提出两种变体:蒸馏隐稀疏注意力(Distilled-LSA, D-LSA),可通过蒸馏应用于预训练模型;原生隐稀疏注意力(Native-LSA, N-LSA),仅基于下一个token损失进行原生训练。在GLM-5.3-FLASH(QWEN-3.8-27B)上,当上下文长度为1000万token时,D-LSA相比原始稀疏注意力(全注意力),单个注意力层的预填充速度提升22.7倍(72.4倍),解码速度提升4.6倍(42.5倍),同时在各类任务中保持相近精度;N-LSA在12.8万token下与全注意力精度相当,每层训练速度提升1.6倍。LSA为模型利用超长上下文提供了实用且高效的注意力方案。
英文摘要:
Agentic workflows are increasingly shifting towards long-horizon tasks, such as open-ended scientific work, where models benefit from long context windows. However, at ultra-long context (above 1M tokens), full attention is prohibitively expensive. A promising approach is sparse attention, in which a dedicated indexer selects a subset of keys for the attention. Yet current methods of indexing either still have quadratic cost in context size or lose accuracy at ultra-long context scale. We address this with Latent Sparse Attention (LSA), an efficient attention method that maintains accuracy at ultra-long context. In LSA, keys are hierarchically clustered in a learned latent space, and queries score the hierarchy of clusters instead of scoring every key, making prefill, decode and training faster at long context. We propose two variants, Distilled-LSA (D-LSA), which can be applied to pre-trained models via distillation, and Native-LSA (N-LSA), which is trained natively on the next-token loss alone. On GLM-5.3-FLASH (QWEN-3.8-27B) at 10M tokens, D-LSA speeds up one attention layer by 22.7x (72.4x) in prefill and 4.6x (42.5x) in decode over its original sparse attention (full attention), while keeping similar accuracy across a variety of tasks. N-LSA matches the accuracy of full attention with a training speedup of 1.6x per layer at 128k tokens. LSA offers practical and efficient attention for models to benefit from ultra-long context.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。