Warning : 1Torch was not compiled with flash attention.
首先告诉大家一个好消息,失败了通常不影响程序运行,就是慢点
这个警告是由于torch=2.2 更新后需要启动 flash attention V2 作为最优机制,但是并没有启动成功导致的。
在这个blog https://pytorch.org/blog/pytorch2-2/ 中写道pytorch 2.2 有重大更新
scaled_dot_product_attention (SDPA) now supports FlashAttention-2, yielding around 2x speedups compared to previous versions.
通常情况下这个函数调用顺序为 FlashAttention > Memory-Efficient Attention(xformers) > PyTorch C++ implementation(math)
(不理解为何要这样设计,而且从警告上完全看不出来这个意思,希望官方下个版本改进吧)
但是想解决的坑就坑下面几个地方:
在pytroch支持了并且是首选,而且逻辑是只要flashAttentionV2失败就会出这个Warning。(有些人测试发现flashAttentionV2并没有提高多少)
flashAttentionV2并没有完善生态,当前官方版本(官网 https://github.com/Dao-AILab/flash-attention)只支持了linux,而对于windows用户只能源码编译(不论如何就是很慢,即便按照安装了ninja),下载第三方打包的可以参考(https://github.com/bdashore3/flash-attention/releases),
硬件支持至少是RTX 30 以上的 ,FlashAttention only supports Ampere GPUs or newer. 换句话说3060才能跑得起来。
还很小的可能是环境cuda版本和编译的cuda版本不兼容,torch官方版本呢是12.1(torch2.* +cu121)。