arXiv:2507.17245cs.LGcs.AI2025-07被引 1

提出DistrAttention,让自注意力更快更准,适合大模型高效推理。

DistrAttention: An Efficient and Flexible Self-Attention Mechanism on Modern GPUs

  • 按嵌入维度分组数据,用局部敏感哈希实现轻量聚类与融合
  • 比FlashAttention-2快37%,在ViT和Llama3上精度损失仅1%
  • 可灵活适配现代GPU,适合追求性能与精度平衡的部署场景

Transformer架构在自然语言处理、计算机视觉和时间序列预测等领域取得了突破性进展,但其核心组件自注意力机制存在与输入序列长度成平方关系的时间复杂度,制约了模型扩展。现有优化方法要么丢失完整上下文信息,要么缺乏灵活性。本文提出DistrAttention,一种高效且灵活的自注意力机制,保留完整上下文。该方法通过在嵌入维度(通常记为 $d$)上对数据分组实现,采用轻量级采样与融合策略,利用局部敏感哈希(LSH)对相似数据进行聚类,并设计块级分组框架以控制LSH引入的误差。通过优化块大小选择,DistrAttention可无缝集成FlashAttention-2,实现在现代GPU上的高性能计算。大量实验表明,该方法在计算自注意力时比FlashAttention-2快37%;在ViT推理中,DistrAttention兼具最快速度与最高精度;在Llama3-1B上,仍实现最低推理延迟,仅损失1%精度。

原文摘要 · Abstract (English)

The Transformer architecture has revolutionized deep learning, delivering the state-of-the-art performance in areas such as natural language processing, computer vision, and time series prediction. However, its core component, self-attention, has the quadratic time complexity relative to input sequence length, which hinders the scalability of Transformers. The exsiting approaches on optimizing self-attention either discard full-contextual information or lack of flexibility. In this work, we design DistrAttention, an effcient and flexible self-attention mechanism with the full context. DistrAttention achieves this by grouping data on the embedding dimensionality, usually referred to as $d$. We realize DistrAttention with a lightweight sampling and fusion method that exploits locality-sensitive hashing to group similar data. A block-wise grouping framework is further designed to limit the errors introduced by locality sensitive hashing. By optimizing the selection of block sizes, DistrAttention could be easily integrated with FlashAttention-2, gaining high-performance on modern GPUs. We evaluate DistrAttention with extensive experiments. The results show that our method is 37% faster than FlashAttention-2 on calculating self-attention. In ViT inference, DistrAttention is the fastest and the most accurate among approximate self-attention mechanisms. In Llama3-1B, DistrAttention still achieves the lowest inference time with only 1% accuray loss.

自注意力模型加速GPU优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。