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

SPLAT:一个用于稀疏正则注意力(SParse reguLar ATtention)的优化GPU代码生成框架

SPLAT: A framework for optimised GPU code-generation for SParse reguLar ATtention

Microsoft(微软公司);Google DeepMind(谷歌DeepMind)

Ahan Gupta, Yueming Yuan, Devansh Jain, Yuhao Ge, David Aponte, Yanqi Zhou, Charith Mendis

AI总结:

本文提出一种新颖的稀疏格式ACSR及GPU代码生成框架SPLAT,利用稀疏MHSA模式的规则几何属性进行优化,在A100上相比triton和TVM手工内核分别实现2.05倍和4.05倍加速,兼顾了通用性与高性能。

摘要:

多头自注意力(MHSA)机制在自然语言处理和视觉任务中实现了最先进的(SOTA)性能。然而,它们对序列长度的二次依赖性成为了推理速度的瓶颈。为了规避这一瓶颈,研究人员提出了各种稀疏MHSA模型,在这些模型中只计算完整注意力的一个子集。尽管前景广阔,但由于所操作的底层稀疏格式,当前的稀疏库和编译器并不支持针对各种稀疏MHSA模式的高性能实现。这些通常为高性能和科学计算应用设计的格式,要么针对极端的随机稀疏性(非零值少于1%)进行优化,要么针对特定的稀疏模式。然而,稀疏MHSA中的稀疏模式是中等稀疏的(非零值占10-50%)且多种多样,导致现有的稀疏格式以牺牲通用性来换取性能。我们通过提出一种新颖的稀疏格式:仿射压缩稀疏行(ACSR)以及支持的代码生成方案SPLAT,弥合了这一差距,实现了通用性和性能的双重目标,该方案在GPU上为各种稀疏MHSA模式生成高性能实现。我们提出的格式和代码生成算法的核心在于观察到常见的稀疏MHSA模式具有独特的规则几何属性。这些可以即时分析的属性揭示了新颖的优化和分块策略,SPLAT利用这些策略为各种模式生成高性能实现。为了证明SPLAT的有效性,我们使用它为各种稀疏MHSA模型生成代码,在A100 GPU上,相较于分别用triton和TVM编写的手工内核,实现了2.05倍和4.05倍的几何平均加速。此外,它的接口直观,易于与JAX中现有的MHSA实现配合使用。

英文摘要:

Multi-head-self-attention (MHSA) mechanisms achieve state-of-the-art (SOTA) performance across natural language processing and vision tasks. However, their quadratic dependence on sequence lengths has bottlenecked inference speeds. To circumvent this bottleneck, researchers have proposed various sparse-MHSA models, where a subset of full attention is computed. Despite their promise, current sparse libraries and compilers do not support high-performance implementations for diverse sparse-MHSA patterns due to the underlying sparse formats they operate on. These formats, which are typically designed for high-performance & scientific computing applications, are either curated for extreme amounts of random sparsity (<1% non-zero values), or specific sparsity patterns. However, the sparsity patterns in sparse-MHSA are moderately sparse (10-50% non-zero values) and varied, resulting in existing sparse-formats trading off generality for performance. We bridge this gap, achieving both generality and performance, by proposing a novel sparse format: affine-compressed-sparse-row (ACSR) and supporting code-generation scheme, SPLAT, that generates high-performance implementations for diverse sparse-MHSA patterns on GPUs. Core to our proposed format and code generation algorithm is the observation that common sparse-MHSA patterns have uniquely regular geometric properties. These properties, which can be analyzed just-in-time, expose novel optimizations and tiling strategies that SPLAT exploits to generate high-performance implementations for diverse patterns. To demonstrate SPLAT's efficacy, we use it to generate code for various sparse-MHSA models, achieving geomean speedups of 2.05x and 4.05x over hand-written kernels written in triton and TVM respectively on A100 GPUs. Moreover, its interfaces are intuitive and easy to use with existing implementations of MHSA in JAX.

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

↑