arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.09827cs.CLcs.CVcs.DCcs.LG
收藏

一种无需训练、亚二次成本的分层剪枝注意力Transformer模型服务框架

A Training-free Sub-quadratic Cost Transformer Model Serving Framework With Hierarchically Pruned Attention

Korea Advanced Institute of Science and Technology (KAIST)(韩国科学技术院);POSTECH(浦项科技大学)

Heejun Lee, Geon Park, Youngwan Lee, Jaduk Suh, Jina Kim, Wonyoung Jeong, Bumsik Kim, Hyemin Lee, Myeongjae Jeon, Sung Ju Hwang

AI总结:

针对LLM长上下文推理的二次复杂度问题,提出无需训练的分层剪枝注意力框架HiP,利用注意力局部性以亚二次时间与空间成本实现高效服务,显著降低延迟和内存占用。

摘要:

在现代大型语言模型(LLM)中,增加上下文长度对于提升长上下文、多模态和检索增强语言生成中的理解力与连贯性至关重要。尽管许多最近的Transformer模型试图将上下文长度扩展到超过一百万token,但由于二次时间与空间复杂度,它们仍不实用。尽管最近关于线性和稀疏注意力机制的工作可以实现这一目标,但其现实应用往往受到从头重新训练的需求以及显著更差性能的限制。为此,我们提出了一种新方法——分层剪枝注意力(HiP),它将注意力机制的时间复杂度降低到$O(T \log T)$,空间复杂度降低到$O(T)$,其中$T$是序列长度。我们注意到预训练LLM的注意力分数中存在一种模式:相邻token往往具有相似的分数,我们称之为“注意力局部性”。基于这一观察,我们利用一种新颖的类树搜索算法,在运行时为给定查询估计前$k$个关键token,该算法在数学上保证比随机注意力剪枝具有更好的性能。除了改善注意力机制的时间复杂度外,我们还通过实现KV缓存卸载进一步优化GPU内存使用,该卸载仅在GPU上存储$O(\log T)$个token,同时保持相似的解码吞吐量。基准测试实验表明,HiP凭借其无需训练的特性,显著降低了预填充和解码延迟以及内存使用,同时以最小退化保持高质量生成。HiP使预训练LLM能够在商用GPU上扩展到数百万token,可能解锁以前被认为不可行的长上下文LLM应用。

英文摘要:

In modern large language models (LLMs), increasing the context length is crucial for improving comprehension and coherence in long-context, multi-modal, and retrieval-augmented language generation. While many recent transformer models attempt to extend their context length over a million tokens, they remain impractical due to the quadratic time and space complexities. Although recent works on linear and sparse attention mechanisms can achieve this goal, their real-world applicability is often limited by the need to re-train from scratch and significantly worse performance. In response, we propose a novel approach, Hierarchically Pruned Attention (HiP), which reduces the time complexity of the attention mechanism to $O(T \log T)$ and the space complexity to $O(T)$, where $T$ is the sequence length. We notice a pattern in the attention scores of pretrained LLMs where tokens close together tend to have similar scores, which we call ``attention locality''. Based on this observation, we utilize a novel tree-search-like algorithm that estimates the top-$k$ key tokens for a given query on the fly, which is mathematically guaranteed to have better performance than random attention pruning. In addition to improving the time complexity of the attention mechanism, we further optimize GPU memory usage by implementing KV cache offloading, which stores only $O(\log T)$ tokens on the GPU while maintaining similar decoding throughput. Experiments on benchmarks show that HiP, with its training-free nature, significantly reduces both prefill and decoding latencies, as well as memory usage, while maintaining high-quality generation with minimal degradation. HiP enables pretrained LLMs to scale up to millions of tokens on commodity GPUs, potentially unlocking long-context LLM applications previously deemed infeasible.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑