跳到主内容
@wquguru
精选88Avi Chawla论文研究

Latent Sparse Attention:注意力机制提速23倍的新方法

A new technique just made attention 23x faster!

原文
发到 X
推荐理由

长上下文推理的核心痛点是注意力计算的线性/二次复杂度,这篇论文提出的 LSA 方案通过语义聚类显著降低了键选择开销,实测加速比极具参考价值,值得工程团队深入研究。

A new technique just made attention 23x faster!

一项新技术让注意力机制速度提升了23倍!

At 10M tokens, sparse attention slows down not because of attention itself but rather because of deciding which keys to attend to.

在10M token的场景下,稀疏注意力变慢并非因为注意力计算本身,而是因为决定关注哪些键(keys)的过程。

Let's understand why and how a new technique solves it without scanning every key.

让我们理解为什么以及一种新技术如何在不扫描每个键的情况下解决这个问题。

1) Full attention at long context:

1) 长上下文下的全注意力:

In full attention, every query is compared against every earlier key. This leads to O(T^2) complexity for prefill, and at 10M tokens it dominates the forward pass.

在全注意力中,每个查询都会与之前所有的键进行比较。这导致预填充(prefill)阶段的复杂度为O(T^2),在10M token时,它主导了前向传播过程。

2) Sparse attention:

2) 稀疏注意力:

Sparse attention lets each query read only a small set of <k> keys instead of all of them, so the attention becomes cheap.

稀疏注意力允许每个查询只读取一小部分<k>个键,而不是全部,从而使注意力计算变得廉价。

But something still has to pick those <k> keys, and at long context, this step becomes the bottleneck.

但总得有人来选择这些<k>个键,而在长上下文场景下,这一步骤成为了瓶颈。

3) Why picking keys is still quadratic:

3) 为什么选择键仍然是二次方复杂度:

DeepSeek's DSA uses a lightning indexer that scores every earlier key. GLM-5.3-Flash pools 4 keys into 1 before scoring. NSA, MoBA, and Quest score blocks of nearby keys.

DeepSeek的DSA使用闪电索引器对每个之前的键进行评分。GLM-5.3-Flash在评分前将4个键聚合成1个。NSA、MoBA和Quest则对邻近键的块进行评分。

Each of them scans the whole context for every query, so the indexer stays O(T^2), and at 10M tokens, it takes 98% of the layer's time.

它们中的每一个都为每个查询扫描整个上下文,因此索引器仍保持O(T^2)复杂度,在10M token时,它占据了该层98%的时间。

Block methods have another issue. Blocks group keys by position, so one relevant key within filler can get averaged away in the block summary.

块方法还有另一个问题。块按位置对键进行分组,因此填充器内的一个相关键可能会在块的摘要中被平均掉。

4) How LSA picks keys:

4) LSA如何选择键:

Latent Sparse Attention (LSA) is a new approach that groups keys by meaning instead of position.

潜在稀疏注意力(Latent Sparse Attention, LSA)是一种新方法,它按语义而非位置对键进行分组。

  • Each key is projected into a 64-dim index space, and every 4 consecutive keys are pooled into one.
  • When a 512-key block fills up, it's clustered into buckets of ~8 similar keys, with one centroid per bucket. Finished blocks are never rebuilt.
  • A query scores only the centroids, keeps the top 1,024 buckets, and expands them into 4,096 keys, plus 4 sink tokens and the 512 most recent keys.
  • Exact FlashAttention then runs over that list with an unchanged kernel.
  • 每个键被投影到64维的索引空间中,每4个连续的键被聚合为一个。
  • 当一个包含512个键的块填满时,它会被聚类成约8个相似键为一组的桶(buckets),每个桶有一个质心。已完成的块永远不会重建。
  • 查询仅对质心进行评分,保留得分最高的1,024个桶,并将它们扩展为4,096个键,再加上4个sink token和最近的512个键。
  • 精确的FlashAttention随后在该列表上运行,内核保持不变。

If you've built RAG, this is like cluster-based vector search running inside attention. The kernel design even cites FAISS.

如果你构建过RAG,这就像是在注意力机制内部运行的基于聚类的向量搜索。其内核设计甚至引用了FAISS。

At 10M tokens, LSA's prefill is 72.4x faster than full attention on Qwen-3.8-27B and 22.7x faster than GLM-5.3-Flash's own sparse attention.

在10M token时,LSA在Qwen-3.8-27B上的预填充速度比全注意力快72.4倍,比GLM-5.3-Flash自身的稀疏注意力快22.7倍。

The time to first token improves:

首Token延迟得到改善:

  • 9.2x on Qwen - 2.2x on GLM
  • Qwen提升9.2倍 GLM提升2.2倍

Below ~512k tokens, it's roughly break-even.

在低于约512k token时,性能大致持平。

Here's the paper: https://arxiv.org/abs/2610.42147

论文链接:https://arxiv.org/abs/2610.42147

That said, LSA attempts to find the keys more cheaply, not storing them. The KV cache still grows linearly with context, and at 10M tokens, managing that memory becomes the next engineering problem.

话虽如此,LSA 试图以更低的成本寻找密钥,而不存储它们。KV 缓存仍随上下文线性增长,在 10M token 时,管理该内存将成为下一个工程问题。

I wrote an article on how 12 ways serving systems handle it, covering paging, offloading, quantizing, and more.

我写了一篇文章,介绍 12 种服务系统如何处理这一问题,涵盖分页、卸载、量化等更多内容。

Read it below.

请在下方阅读。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

关联讨论

同一事件的更多信源

相似阅读

关联信息,但可能不是同一事件