arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2203.00091cs.LG
收藏

动态N:M细粒度结构稀疏注意力机制

Dynamic N:M Fine-grained Structured Sparse Attention Mechanism

University of California, Santa Barbara(加州大学圣巴巴拉分校);ALIBABA DAMO Academy(阿里巴巴达摩院)

Zhaodong Chen, Yuying Quan, Zheng Qu, Liu Liu, Yufei Ding, Yuan Xie

摘要:

Transformers正在成为NLP和计算机视觉等各种任务的主流解决方案。尽管它们取得了成功,但注意力机制的高度复杂性阻碍了它们应用于延迟敏感的任务。为了缓解这个问题,已经做出了巨大的努力,其中许多人成功地将渐近复杂性降低到线性。然而,他们中的大多数未能实现实际的加速比在中等序列长度下的原始的全注意力,是不友好的微调。在本文中,我们提出了DFSS,一个注意力机制,动态修剪的完整的注意力权重矩阵的N:M细粒度结构稀疏模式。我们提供的理论和经验证据表明,DFSS是一个很好的近似的完整的注意力机制。我们提出了一个专用的CUDA内核设计,完全消除了动态修剪开销,并实现任意序列长度下的加速比。我们在不同的配置下评估了1:2和2:4的稀疏性,并在全注意力机制上实现了1.27~1.89倍的加速比。它只需要从预训练模型中进行几次微调,就可以在384到4096的不同序列长度下,对来自不同领域的任务进行完全注意力机制,达到同等精度。

英文摘要:

Transformers are becoming the mainstream solutions for various tasks like NLP and Computer vision. Despite their success, the high complexity of the attention mechanism hinders them from being applied to latency-sensitive tasks. Tremendous efforts have been made to alleviate this problem, and many of them successfully reduce the asymptotic complexity to linear. Nevertheless, most of them fail to achieve practical speedup over the original full attention under moderate sequence lengths and are unfriendly to finetuning. In this paper, we present DFSS, an attention mechanism that dynamically prunes the full attention weight matrix to N:M fine-grained structured sparse pattern. We provide both theoretical and empirical evidence that demonstrates DFSS is a good approximation of the full attention mechanism. We propose a dedicated CUDA kernel design that completely eliminates the dynamic pruning overhead and achieves speedups under arbitrary sequence length. We evaluate the 1:2 and 2:4 sparsity under different configurations and achieve 1.27~ 1.89x speedups over the full-attention mechanism. It only takes a couple of finetuning epochs from the pretrained model to achieve on par accuracy with full attention mechanism on tasks from various domains under different sequence lengths from 384 to 4096.

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

↑