Skip to main content
QUICK REVIEW

[论文解读] Algorithm and Hardness for Dynamic Attention Maintenance in Large Language Models

Jan van den Brand, Zhao Song|arXiv (Cornell University)|Apr 5, 2023
Topic ModelingComputer Science被引用 3
一句话总结

本文提出了一种动态数据结构,用于在大语言模型(LLMs)中维护注意力矩阵,支持对键(keys)和值(values)的增量更新,实现 $O(n^{\tau})$ 的摊销更新时间与 $O(n^{1+\tau})$ 的最坏情况查询时间。通过证明,任何更快的算法都将导致提示的矩阵-向量乘法猜想被证伪,从而展示了其条件最优性。

ABSTRACT

Large language models (LLMs) have made fundamental changes in human life. The attention scheme is one of the key components over all the LLMs, such as BERT, GPT-1, Transformers, GPT-2, 3, 3.5 and 4. Inspired by previous theoretical study of static version of the attention multiplication problem [Zandieh, Han, Daliri, and Karbasi arXiv 2023, Alman and Song arXiv 2023]. In this work, we formally define a dynamic version of attention matrix multiplication problem. There are matrices $Q,K, V \in \mathbb{R}^{n imes d}$, they represent query, key and value in LLMs. In each iteration we update one entry in $K$ or $V$. In the query stage, we receive $(i,j) \in [n] imes [d]$ as input, and want to answer $(D^{-1} A V)_{i,j}$, where $A:=\exp(QK^ op) \in \mathbb{R}^{n imes n}$ is a square matrix and $D := \mathrm{diag}(A {\bf 1}_n) \in \mathbb{R}^{n imes n}$ is a diagonal matrix. Here ${\bf 1}_n$ denote a length-$n$ vector that all the entries are ones. We provide two results: an algorithm and a conditional lower bound. $\bullet$ On one hand, inspired by the lazy update idea from [Demetrescu and Italiano FOCS 2000, Sankowski FOCS 2004, Cohen, Lee and Song STOC 2019, Brand SODA 2020], we provide a data-structure that uses $O(n^{ω(1,1,τ)-τ})$ amortized update time, and $O(n^{1+τ})$ worst-case query time. $\bullet$ On the other hand, show that unless the hinted matrix vector multiplication conjecture [Brand, Nanongkai and Saranurak FOCS 2019] is false, there is no algorithm that can use both $O(n^{ω(1,1,τ) - τ- Ω(1)})$ amortized update time, and $O(n^{1+τ-Ω(1)})$ worst query time. In conclusion, our algorithmic result is conditionally optimal unless hinted matrix vector multiplication conjecture is false.

研究动机与目标

  • 正式定义并解决动态注意力矩阵乘法问题,其中大语言模型中的键矩阵和值矩阵在增量中更新。
  • 设计一种数据结构,高效支持大规模变换器中注意力计算的动态更新与快速查询。
  • 基于提示的矩阵-向量乘法猜想,建立任何动态注意力算法效率的条件下界。
  • 通过提供条件最优解,弥合理论动态算法与实际大语言模型推理之间的鸿沟。
  • 与以往静态或近似注意力研究形成对比,本研究聚焦于具有理论保证的精确动态计算。

提出的方法

  • 借鉴动态图算法中的惰性更新策略,结合凸优化与线性规划技术,高效维护注意力矩阵。
  • 构建一种数据结构,用于在 $K$ 和 $V$ 的增量更新下,维护注意力矩阵 $A = \text{exp}(QK^\top)$ 及其归一化形式 $D = \text{diag}(A\boldsymbol{1}_n)$。
  • 通过从提示的矩阵-向量乘法问题到困难性的归约,证明其困难性,将布尔矩阵乘积嵌入注意力计算框架中。
  • 采用三阶段构造:(1) 将矩阵-向量乘积编码为注意力输入,(2) 维护归一化的注意力输出,(3) 通过差值查询提取结果。
  • 利用 $\text{exp}(x) > 1$ 对于 $x > 0$ 的性质,保留注意力分数中的布尔语义,从而实现矩阵乘积的精确重构。
  • 通过 $D^{-1}$ 实现类似 $\text{softmax}$ 的归一化,以分离注意力矩阵的非恒等部分,从而实现矩阵乘积条目的精确恢复。

实验结果

研究问题

  • RQ1我们能否设计一种用于注意力矩阵乘法的动态数据结构,以支持大语言模型中键和值的高效增量更新?
  • RQ2动态注意力计算中,摊销更新时间与最坏情况查询时间之间的最佳可能权衡是什么?
  • RQ3是否存在一个条件下的下界,排除了显著更快的动态注意力维护算法?
  • RQ4精确的动态注意力问题能否被归约为细粒度复杂性中的已知难题?
  • RQ5凸优化与动态算法技术与细粒度复杂性方法在解决动态注意力问题上的表现如何比较?

主要发现

  • 所提出的算法对任意 $\tau \neq 0$,实现了 $O(n^{\tau})$ 的摊销更新时间与 $O(n^{1+\tau})$ 的最坏情况查询时间,采用了一种新颖的惰性更新机制。
  • 该算法是条件最优的:若提示的矩阵-向量乘法猜想为真,则任何算法都无法实现 $O(n^{\tau - \theta})$ 的摊销更新时间与 $O(n^{1+\tau - \theta})$ 的查询时间,其中 $\theta > 0$。
  • 困难性结果通过从提示的矩阵-向量乘法问题的归约获得,将布尔矩阵乘积嵌入注意力计算框架中。
  • 该构造确保差值 $(D^{-1}AV)_{i,j} - (D^{-1}V)_{i,j}$ 的符号能精确恢复布尔矩阵乘积 $(MPV)_{i,j}$,从而实现精确重构。
  • 该方法在凸优化与动态算法理论上具有坚实的理论基础,区别于以往仅依赖细粒度复杂性分析的工作。
  • 分析表明,归一化矩阵 $D$ 在构造下保持稳定,无需更新,从而简化了数据结构。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。