arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2412.14468cs.LGcs.AI
收藏

HashAttention:面向更快推理的语义稀疏性

HashAttention: Semantic Sparsity for Faster Inference

UC Berkeley(加州大学伯克利分校);ETH Zurich(苏黎世联邦理工学院)

Aditya Desai, Shuo Yang, Alejandro Cuadron, Matei Zaharia, Joseph E. Gonzalez, Ion Stoica

AI总结:

HashAttention将关键令牌识别建模为推荐问题,通过在汉明空间编码查询和键并利用按位运算实现语义稀疏注意力,在A100 GPU上以极小质量损失将令牌使用量减少最高32倍,并显著降低注意力延迟、提升吞吐量。

摘要:

利用长上下文对先进人工智能系统至关重要,但注意力计算带来了可扩展性挑战。尽管缩放点积注意力(SDPA)表现出令牌稀疏性,即只有少数关键令牌对输出有显著贡献,但利用这种稀疏性仍然困难。现有方法要么导致质量下降,要么需要大量额外资源。我们表明,识别关键令牌是一个最大内积搜索(MIPS)问题。然而,现有的MIPS解决方案并不适合SDPA,因为它们对GPU不友好,并且由于查询和键分布分离而常常表现不佳。本文提出HashAttention,将关键令牌识别构建为一个推荐问题。给定一个查询,HashAttention使用学习到的映射函数在汉明空间中编码键和查询,捕获所需的语义相似性。HashAttention利用按位运算高效地识别给定查询的关键令牌,并仅使用这些令牌计算注意力,从而提升整体注意力效率。在通用数据上训练后,HashAttention将使用的令牌数量最多减少16倍,同时质量损失极小,每个令牌仅需32位辅助内存。通过任务特定的微调,稀疏性可进一步提高到32倍。在A100 GPU上,在32倍稀疏性下,引入HashAttention使GPT-FAST中的注意力延迟最多降低4.3倍,在FlashDecode中降低2.54倍,并使GPT-FAST的吞吐量最高提升3.12倍。

英文摘要:

Leveraging long contexts is crucial for advanced AI systems, but attention computation poses a scalability challenge. While scaled dot-product attention (SDPA) exhibits token sparsity, i.e. only a few pivotal tokens significantly contribute to output, exploiting this sparsity remains challenging. Existing methods either suffer from quality degradation or require substantial additional resources. We show that identifying pivotal tokens is a Maximum Inner Product Search (MIPS) problem. However, existing MIPS solutions are not well-suited for SDPA, as they are not GPU-friendly and often underperform due to the separated query and key distributions. This paper introduces HashAttention, framing pivotal token identification as a recommendation problem. Given a query, HashAttention encodes keys and queries in Hamming space, capturing the required semantic similarity, using learned mapping functions. HashAttention efficiently identifies pivotal tokens for a given query using bitwise operations and computes attention using only these tokens, improving the overall attention efficiency. Trained on generic data, HashAttention reduces tokens used by up to $16\times$ with minimal quality loss, requiring only 32 bits of auxiliary memory per token. Sparsity can be further improved to $32\times$ through task-specific fine-tuning. On A100 GPU, at $32\times$ sparsity, incorporating HashAttention reduces attention latency by up to $4.3\times$ in GPT-FAST and $2.54\times$ in FlashDecode, and achieves up to $3.12\times$ higher throughput for GPT-FAST.

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

↑