← 全部文章← All posts

OmniKV:动态上下文选择与层间注意力复用

文章目录
  1. 研究背景与动机
  2. 关键观察
  3. 方法介绍
  4. 实验结果
  5. 后续进展:IndexCache 与 GLM-5.2

这种方法可能会更适合R1,O1这种推理模型,也可能更适合multi round的这种对话形式?

OMNIKV: DYNAMIC CONTEXT SELECTION FOR EFFICIENT LONG-CONTEXT LLMS

代码:https://github.com/antgroup/OmniKV.git

研究背景与动机

现有推理加速方法尝试通过丢弃"不重要"的token来减少内存占用,但这些方法存在致命缺陷——它们依赖当前状态下的注意力权重来判断token重要性,忽略了token在后续生成阶段可能发挥的关键作用。这种静态的重要性评估机制无法适应动态变化的上下文需求,限制了模型的性能。

关键观察

研究团队通过深入分析发现了一个重要现象:在单个decode step内,模型连续层之间识别出的重要token具有高度相似性。这一发现为设计更高效的推理方法提供了全新思路。

OmniKV 原文配图 1

方法介绍

基于上述观察,研究团队提出了OmniKV——一种无token丢弃、无需额外训练的创新推理方法。OmniKV的核心思想包括:

动态上下文选择:在解码阶段,先利用注意力图的稀疏性,从"filter"层中选择少量重要token,然后根据“层间相似性”,让其他层直接使用这些被选中的token子集作为上下文。

全token保留:与现有方法不同,OmniKV保留所有token的KV缓存,确保模型可以在需要时访问完整信息,有效避免了信息丢失带来的性能下降。

OmniKV 原文配图 2

实验结果

在LongBench和InfiniteBench等评测中几乎不影响原有模型性能;在多步推理场景(如CoT)中表现尤为出色;成功将单个A100 GPU上Llama-3-8B模型的最大上下文长度从128K扩展到450K,提升幅度超过3.5倍;在Huggingface transformers和轻量级大模型推理框架Lightllm上都实现了1.7x的加速比,且借助Lightllm支持了Tensor Parallelism,允许多卡并行。

OmniKV 原文配图 3
OmniKV 原文配图 4

后续进展:IndexCache 与 GLM-5.2

我们ICLR25的工作OmniKV[1]发现层间的注意力分布是非常相似的,也就是我们可以让某几层作为 选择层 选择出关键token,其他层做稀疏注意力只用 最近一个选择层选择出的关键token计算稀疏注意力即可,在我们后续的工作DeltaKV[2]中我们又一次验证OmniKV性能确实很强。同期还有类似工作比如TidalDecode[3]。

GLM最近的工作IndexCache将该思想简单扩展到了DSA上(也引用了我们),也就是某几个Lightning indexer可以作为 选择层 存在,最近性能比肩claude-4.8的glm-5.2应用了该技术,也算是我们的工作应用在了最新强基模上,非常开心

[1] OmniKV: Dynamic context selection for efficient long-context llms

[2] DeltaKV: Residual-based KV cache compression via long-range similarity

[3] Tidaldecode: Fast and accurate llm decoding with position persistent sparse attention

OmniKV: Dynamic Context Selection and Cross-Layer Attention Reuse

Contents
  1. Background and motivation
  2. Key observation
  3. Method
  4. Experimental results
  5. Later developments: IndexCache and GLM-5.2

Could this approach be particularly useful for reasoning models such as R1 and o1, or for multi-turn conversations?

OMNIKV: DYNAMIC CONTEXT SELECTION FOR EFFICIENT LONG-CONTEXT LLMS

Code: https://github.com/antgroup/OmniKV.git

Background and motivation

Existing inference acceleration methods often reduce memory usage by discarding “unimportant” tokens. A critical limitation is that they judge importance using current attention weights, overlooking tokens that may become important later in generation. This static assessment cannot adapt to changing context requirements and can limit model performance.

Key observation

Our analysis revealed an important pattern: within a single decoding step, consecutive layers identify highly similar sets of important tokens. This observation suggests a different route to more efficient inference.

OmniKV: original figure 1

Method

Based on this observation, we proposed OmniKV, an inference method that requires no additional training and does not discard tokens. Its core ideas are:

Dynamic context selection: during decoding, a “filter” layer uses attention sparsity to select a small set of important tokens. Other layers then reuse this token subset as their attention context, exploiting the similarity across layers.

Retaining all tokens: OmniKV preserves the KV cache for every token so that the model can access the full history when needed. This avoids the performance degradation caused by permanently losing information.

OmniKV: original figure 2

Experimental results

OmniKV has little impact on model quality in benchmarks such as LongBench and InfiniteBench, and performs particularly well in multi-step reasoning scenarios such as chain-of-thought. It extends the maximum context length of Llama-3-8B on a single A100 GPU from 128K to 450K, an increase of more than 3.5×. It achieves a 1.7× speedup in both Hugging Face Transformers and the lightweight inference engine LightLLM. Through LightLLM, it also supports tensor parallelism for multi-GPU execution.

OmniKV: original figure 3
OmniKV: original figure 4

Later developments: IndexCache and GLM-5.2

In our ICLR 2025 work, OmniKV [1], we found that attention distributions are highly similar across layers. A subset of layers can therefore act as selection layers, identifying important tokens, while other layers compute sparse attention using the tokens chosen by the nearest preceding selection layer. Our subsequent work, DeltaKV [2], again confirmed OmniKV’s strong performance. Contemporaneous work such as TidalDecode [3] explored related ideas.

The GLM team’s more recent work, IndexCache, extends this idea to DSA and cites OmniKV. Some Lightning indexers serve as selection layers. GLM-5.2, whose performance was recently reported to be comparable to Claude 4.8, uses this technique. It is exciting to see an idea from our work finding its way into a new foundation model.

[1] OmniKV: Dynamic Context Selection for Efficient Long-Context LLMs

[2] DeltaKV: Residual-Based KV Cache Compression via Long-Range Similarity

[3] TidalDecode: Fast and Accurate LLM Decoding with Position Persistent Sparse Attention