NOSA: Native and Offloadable Sparse Attention
该论文提出了一种名为NOSA的稀疏注意力机制,通过引入显式局部性约束和KV缓存卸载,显著提高了长上下文处理中LLM的解码吞吐量。
更新于 2025-10-16。作者:Yuxiang Huang、Chaojun Xiao、Xu Han、Zhiyuan Liu。
中文摘要
可训练稀疏注意力已成为解决长上下文处理中LLM解码效率瓶颈的有希望的方法,在显著减少内存访问的同时,对任务性能的影响微乎其微。然而,现有的稀疏注意力方法留下了一个关键的限制尚未解决:键值(KV)缓存的大小没有减少,这限制了GPU上的批量大小并限制了解码吞吐量,尤其是在大规模批量推理中。在这篇论文中,我们表明可训练稀疏注意力在相邻解码步骤中的标记选择上自然表现出很强的局部性,从而使得KV缓存卸载而无需改变底层注意力计算。然而,固有的局部性仍然不足以实现高效的卸载,因为CPU和GPU之间所选KV对的传输继续占据整体解码成本的主导地位。基于这一洞察,我们提出了NOSA,这是一个旨在原生支持KV缓存卸载的可训练稀疏注意力框架。NOSA通过将标记选择分解为查询感知和查询无关组件来引入显式的局部性约束,从而减少KV传输,同时保留与训练期间使用的相同的注意力计算。我们使用NOSA预训练了一个1B参数的模型,并进行了广泛的基准测试,结果表明它保持了几乎无损的性能,同时与标准的可训练稀疏注意力基线(InfLLM-V2)相比,解码吞吐量实现了高达2.3倍的提升。
英文摘要
Trainable sparse attention has emerged as a promising solution to address the decoding efficiency bottleneck of LLMs in long-context processing, significantly saving memory accesses while minimally impacting task performance. However, existing sparse attention methods leave a crucial limitation unresolved: the size of the key-value (KV) cache remains unreduced, which constrains on-GPU batch sizes and throttles decoding throughput, especially in large-scale batched inference. In this paper, we show that trainable sparse attention naturally exhibits strong locality in token selection across adjacent decoding steps, thereby enabling KV cache offloading without altering the underlying attention computation. However, the inherent locality remains insufficient to achieve efficient offloading, as the transfer of selected KV pairs between the CPU and GPU continues to dominate the overall decoding cost. Building on this insight, we present NOSA, a trainable sparse attention framework designed to natively support KV cache offloading. NOSA introduces explicit locality constraints by decomposing token selection into query-aware and query-agnostic components, thereby reducing KV transfers while preserving the same attention computation as used during training. We pretrain a 1B-parameter model with NOSA and conduct extensive benchmarks, showing that it preserves near-lossless performance while achieving up to a 2.3x improvement in decoding throughput compared with the vanilla trainable sparse attention baseline (InfLLM-V2).
解读
一句话总结
该论文提出了一种名为NOSA的稀疏注意力机制,通过引入显式局部性约束和KV缓存卸载,显著提高了长上下文处理中LLM的解码吞吐量。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:在长上下文处理中,LLM的解码效率受限,主要瓶颈是内存I/O,导致解码速度慢和吞吐量低。
- 现有方案不足:现有的稀疏注意力方法虽然降低了计算和内存访问,但无法减少KV缓存的大小,限制了最大批处理大小和解码吞吐量。
- 研究目标:设计一种可训练的稀疏注意力框架,支持KV缓存卸载,同时保持几乎无损的任务性能和更高的解码吞吐量。
问题2:论文的核心创新点是什么?
- 技术创新:通过将token选择分解为查询感知和查询无关组件,引入显式局部性约束,从而减少KV传输,同时保持与训练相同的注意力计算。
- 方法改进:结合了查询感知和查询无关的选择策略,以在保证性能的同时提高局部性。
- 优势:相比现有的可训练稀疏注意力方法,NOSA在解码吞吐量上实现了高达2.3倍的性能提升。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在短上下文和长上下文基准测试中进行了广泛的实验,包括MMLU、MMLU Pro、BBH、GSM8K、MATH、DROP、MBPP、HumanEval、LongBench和RULER。
- 性能提升:NOSA在保持几乎无损任务性能的同时,实现了高达2.3倍的解码吞吐量提升。
- 对比结果:与未卸载的InfLLM-V2和简单卸载的InfLLM-V2相比,NOSA在解码吞吐量上实现了显著的提升。
问题4:这个研究的实际应用价值是什么?
- 应用场景:云侧LLM服务、LLM强化学习的样本生成等。
- 实施建议:在预训练过程中引入NOSA,并在实际部署时考虑GPU和CPU之间的通信优化。
- 局限与展望:NOSA在提高解码吞吐量的同时,保持了几乎无损的性能。未来可以进一步探索其在更大规模模型和不同应用场景中的表现。