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

Flashlight: PyTorch 编译器扩展以加速注意力变种

Flashlight: PyTorch Compiler Extensions to Accelerate Attention Variants

Anonymous Institution, Anonymous City, Anonymous Region, Anonymous Country(匿名机构,匿名城市,匿名地区,匿名国家)

Bozhi You, Irene Wang, Zelal Su Mustafaoglu, Abhinav Jangda, Angélica Moreira, Roshan Dathathri, Divya Mahajan, Keshav Pingali

AI总结:

本文提出Flashlight,一种基于PyTorch的编译器框架,能够自动生成融合的FlashAttention风格内核,支持任意注意力程序,无需静态模板或预定义内核专有化,从而在保持性能的同时提供灵活性。

摘要:

注意力是大型语言模型(LLMs)的基本构建块,因此有很多努力去高效地实现它。例如,FlashAttention利用分块和内核融合来优化注意力。最近,一些注意力变种被引入以提高模型质量和效率。支持它们仍然困难,因为它们通常需要专门的内核或手动调优的实现。FlexAttention最近通过使用静态编程模板来支持FlashAttention-like内核来解决部分这一差距。在本文中,我们介绍了Flashlight,一种位于PyTorch生态系统中的编译器原生框架,能够自动生成融合的FlashAttention风格内核,适用于任意注意力程序,而无需依赖静态模板或预定义的内核专有化。Flashlight利用PyTorch的编译流程来透明地融合和分块注意力计算,使各种注意力模式能够高效执行。不仅支持FlexAttention模型中所有可表达的变种,还处理更一般、数据依赖的注意力公式,这些超出了FlexAttention的能力范围。我们的结果表明,Flashlight生成的内核在性能上与FlexAttention具有竞争力或更优,同时提供原生PyTorch代码的灵活性,使开发人员能够快速探索新的注意力模型,而不会牺牲性能。

英文摘要:

Attention is a fundamental building block of large language models (LLMs), so there have been many efforts to implement it efficiently. For example, FlashAttention leverages tiling and kernel fusion to optimize attention. Recently, a number of variants of attention have been introduced to enhance model quality or efficiency. Supporting them efficiently remains difficult since they usually require specialized kernels or hand-tuned implementations. FlexAttention recently addressed part of this gap by using static programming templates to support FlashAttention-like kernels for a subset of attention variants. In this paper, we introduce Flashlight, a compiler-native framework within the PyTorch ecosystem that automatically generates fused, FlashAttention-style kernels for arbitrary attention-based programs, without relying on static templates or predefined kernel specializations. Flashlight leverages PyTorch's compilation workflow to fuse and tile attention computations transparently, enabling efficient execution for diverse attention patterns. Not only does it support all variants expressible in the FlexAttention model but it also handles more general, data-dependent attention formulations that are beyond the capabilities of FlexAttention. Our results show that Flashlight produces kernels with competitive or superior performance to FlexAttention, while offering the flexibility of native PyTorch code, enabling developers to rapidly explore new attention models without sacrificing performance.

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

↑