Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMD] Implement Flash Attention in Triton to enable transformers to run with Flash Attention on AMD GPUs. #126

Open
ByronHsu opened this issue Aug 27, 2024 · 4 comments

Comments

@ByronHsu
Copy link
Collaborator

ByronHsu commented Aug 27, 2024

🚀 The feature, motivation and pitch

The official implementation of flash attention is in CUDA, so in AMD GPUs, users cannot easily use flash attention on transformers to training LLM. With the supports, we can unlock many exciting use cases on AMD. The code is already there at https://triton-lang.org/main/getting-started/tutorials/06-fused-attention.html.

Another option is to use flex-attn from PyTorch team, which uses torch.compile to optimize on top of existing handwritten triton kernels

Alternatives

No response

Additional context

No response

@ByronHsu ByronHsu changed the title Implement Flash Attention in Triton to enable transformers to run with Flash Attention on AMD GPUs. [AMD] Implement Flash Attention in Triton to enable transformers to run with Flash Attention on AMD GPUs. Aug 27, 2024
@helloworld1
Copy link
Collaborator

The FA provided by https://github.com/Dao-AILab/flash-attention has only MI200 or MI300 GPUs. With Trition 3.0, the kernel can work on a much broad range of AMD GPUs. Tested kernels on AMD 7000 series working great.

@thevasudevgupta
Copy link

I implemented flash attention v1 as well in triton. Feel free to copy/adapt from here: https://github.com/thevasudevgupta/gpt-triton/blob/6a12b71e4e332a2077e6b7f742f97c7160fe0242/kernels.py#L376 (my repo is MIT license!!)

I might plan to work on v2/v3 version in future. Will let you know when I finish.

@unclemusclez
Copy link

unclemusclez commented Aug 29, 2024

Working Navi 31 / 7900 / gfx1100 support: https://github.com/ROCm/flash-attention/tree/howiejay/navi_support

@remi-or
Copy link

remi-or commented Sep 26, 2024

To resolve this issue using a triton kernel, I opened this PR: #275
While FlexAttention is still in the nightly releases only, this seems the only way to add FA monkey-patching without adding a dependancy to pytorch-nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants