2025-02-18 · 专家 · 计算机视觉 · 自然语言处理 · 机器学习

Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention

本文提出了一种名为NSA的硬件对齐且原生可训练的稀疏注意力机制,通过算法创新和硬件优化,实现了高效的长期上下文建模。

更新于 2025-02-18。作者:Jingyang Yuan、Huazuo Gao、Damai Dai、Junyu Luo、Liang Zhao、Zhengyan Zhang、Zhenda Xie、Y. X. Wei、Lean Wang、Zhiping Xiao、Yuqing Wang、Chong Ruan、Ming Zhang、Wenfeng Liang、Wangding Zeng。

中文摘要

长上下文建模对下一代语言模型至关重要,然而标准注意力机制的高计算成本带来了显著的计算挑战。稀疏注意力为在保持模型能力的同时提高效率提供了一个有希望的方向。我们提出了NSA,这是一种原生可训练的稀疏注意力机制,它将算法创新与硬件对齐优化相结合,以实现高效的长期上下文建模。NSA采用动态分层稀疏策略,结合粗粒度标记压缩和细粒度标记选择,以保持全局上下文感知和局部精确度。我们的方法通过两个关键创新推动了稀疏注意力设计:(1) 通过算术强度平衡的算法设计和针对现代硬件的实现优化,我们实现了显著的加速。(2) 我们实现了端到端训练,减少了预训练计算,同时没有牺牲模型性能。如图1所示,实验表明,使用NSA预训练的模型在通用基准、长上下文任务和基于指令的推理方面保持了或超过了全注意力模型。同时,NSA在64k长度的序列解码、正向传播和反向传播方面实现了显著的加速,验证了其在整个模型生命周期中的效率。

英文摘要

Long-context modeling is crucial for next-generation language models, yet the high computational cost of standard attention mechanisms poses significant computational challenges. Sparse attention offers a promising direction for improving efficiency while maintaining model capabilities. We present NSA, a Natively trainable Sparse Attention mechanism that integrates algorithmic innovations with hardware-aligned optimizations to achieve efficient long-context modeling. NSA employs a dynamic hierarchical sparse strategy, combining coarse-grained token compression with fine-grained token selection to preserve both global context awareness and local precision. Our approach advances sparse attention design with two key innovations: (1) We achieve substantial speedups through arithmetic intensity-balanced algorithm design, with implementation optimizations for modern hardware. (2) We enable end-to-end training, reducing pretraining computation without sacrificing model performance. As shown in Figure 1, experiments show the model pretrained with NSA maintains or exceeds Full Attention models across general benchmarks, long-context tasks, and instruction-based reasoning. Meanwhile, NSA achieves substantial speedups over Full Attention on 64k-length sequences across decoding, forward propagation, and backward propagation, validating its efficiency throughout the model lifecycle.

解读

一句话总结

本文提出了一种名为NSA的硬件对齐且原生可训练的稀疏注意力机制,通过算法创新和硬件优化,实现了高效的长期上下文建模。

问题1:这篇论文想要解决什么具体问题?

问题2:论文的核心创新点是什么?

问题3:实验结果如何验证了方法的有效性?

问题4:这个研究的实际应用价值是什么?

来源