推理时使用非对称索引的稀疏注意力
Inference-time sparse attention with asymmetric indexing
AI总结:
本文提出Saap非对称索引技术,对键和查询采用不同划分以数据自适应稀疏模式近似自注意力,在长上下文Llama 3.1-8b上将内存查找比例降低20倍并节省60%时间。
摘要:
Transformer模型中的自注意力是一种增量联想记忆,它将键向量映射到值向量。加速自注意力的一种方法是采用基于标准划分方法(如k-means)的GPU兼容向量搜索算法。然而,这类划分方法在该场景下效果不佳,原因在于:(1)键和查询服从不同的分布;(2)RoPE位置编码妨碍了桶分配。本文提出Saap(Self-Attention with Asymmetric Partitions,非对称划分自注意力),以克服上述问题。它是一种非对称索引技术,对键和查询采用不同的划分,从而以数据自适应的稀疏模式近似自注意力。该方法适用于预训练语言模型,只需离线训练一个小型查询分类器。在长上下文Llama 3.1-8b模型上,当序列长度从100k到500k个token时,Saap通常将需要查找的内存比例降低20倍,与FlashAttention-v2相比可节省60%的时间。
英文摘要:
Self-attention in transformer models is an incremental associative memory that maps key vectors to value vectors. One way to speed up self-attention is to employ GPU-compatible vector search algorithms based on standard partitioning methods such as k-means. However, such partitioning methods yield poor results in this context because (1) the keys and queries follow different distributions, and (2) the RoPE positional encoding hinders the bucket assignment. This paper introduces Saap (Self-Attention with Asymmetric Partitions), which overcomes these problems. It is an asymmetrical indexing technique that employs distinct partitions for keys and queries, thereby approximating self-attention with a data-adaptive sparsity pattern. It works on pretrained language models and only requires to train (offline) a small query classifier. On a long context Llama 3.1-8b model, with sequences ranging from 100k to 500k tokens, Saap typically reduces by a factor of 20 the fraction of memory that needs to be looked-up, which translates to a time saving of 60\% when compared to FlashAttention-v2.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。