-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Flash Attention v3 #36190
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
Flash Attention v3 #36190
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a preheader to warn/inform you on some stuff regarding the current status of fa3:
- sm80 is supported (A100 etc) (and up)
- (arm64 is supported now I think, not sure if it was before)
- it doesn't seem like dropout will be supported ( Dao-AILab/flash-attention#1377 )
- (barebones) padding is included in hopper ( https://github.com/Dao-AILab/flash-attention/blob/main/hopper/padding.py )
seqused_(q/k) is now forced in the varlen interface ( https://github.com/Dao-AILab/flash-attention/blob/fa445ff6c215026438cca496a97242b8269aa428/hopper/flash_attn_interface.py#L566-L567 ) but tbh not sure if this was unintended ( opened an issue at Dao-AILab/flash-attention#1495 )newest main shouldnt require it anymore- qkv packed exisits for base fa3 forward (but not the others)
- softcapping should be supported now ( e.g. https://github.com/Dao-AILab/flash-attention/blob/fa445ff6c215026438cca496a97242b8269aa428/hopper/flash_attn_interface.py#L576 )
- fp8 backward doesnt look like it will be added soon ( Dao-AILab/flash-attention#1420 (comment) )
if torch.version.cuda: | ||
compute_capability = torch.cuda.get_device_capability() | ||
major, _ = compute_capability | ||
if major < 9: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A100 support has been recently added Dao-AILab/flash-attention#1481 (comment)
cc @bn999 if you're interested about the progress |
@vasqu Yup, I'm following. Good stuff. |
Thanks for the info @vasqu |
Gentle ping @ArthurZucker |
Hi @ArthurZucker @hlky @vasqu @muellerzr , thanks for the great efforts to integrate Flash Attention 3 😁. Do we have any plans to merge this PR? |
Hey quick thing here @hlky, if you have FA3 installed but not FA2 (which I believe is a valid way it is used in other repos like TE) you end up failing the |
Hi @sam-h-bean. At the time this PR was started (more specifically, the original PR #33522) pad functions were not available in FAv3, therefore FAv2 was required. As per #36190 (review) this is likely no longer required and will be updated when this PR is finished. At the moment we are waiting for comments from a core-maintainer, @ArthurZucker, regarding #36190 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answering!
Integrate FAv3 into _flash_attention_forward/flash_attention_forward as before or create new functions?
I think if API changes are not too big we can use the same
Some models still have FlashAttention2 classes, is refactoring all models to use the new style planned? Integrate FAv3 as before or do the refactor in this PR?
would be nice to have in a separate PR!
Happy to merge as is!
_supports_flash_attn_2 = True | ||
_supports_flash_attn_3 = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supporting 2 or 3 is equivalent to the model here so we can just keep 2 <=> 3?
@hlky sorry I probably forgot to merge 😓 don't worry we'll push trough and add support! |
@ArthurZucker lol it's cool, the PR wasn't finished because I had been waiting for your response, didn't have time in Paris then I was fired so I closed it 🤷♂️ |
Implements fwd and tests for Flash Attention 3 https://github.com/Dao-AILab/flash-attention/commits/main/hopper - Includes checks for dropout>0 and ALiBi in `modeling_utils.PreTrainedModel._check_and_enable_flash_attn_3` (Dropout will likely be supported soon, so this will need to be updated and `modeling_flash_attention_utils._flash_attention_forward` at the `if _IS_FLASH_ATTN_3_AVAILABLE: ...` An example Llama implementation is included in `modeling_llama.py` but other models would still need to be updated Based on huggingface#36190 which has model implementations and examples which could be merged
Implements fwd and tests for Flash Attention 3 https://github.com/Dao-AILab/flash-attention/commits/main/hopper - Includes checks for dropout>0 and ALiBi in `modeling_utils.PreTrainedModel._check_and_enable_flash_attn_3` (Dropout will likely be supported soon, so this will need to be updated and `modeling_flash_attention_utils._flash_attention_forward` at the `if _IS_FLASH_ATTN_3_AVAILABLE: ...` An example Llama implementation is included in `modeling_llama.py` but other models would still need to be updated Based on huggingface#36190 which has model implementations and examples which could be merged
Implements fwd and tests for Flash Attention 3 https://github.com/Dao-AILab/flash-attention/commits/main/hopper - Includes checks for dropout>0 and ALiBi in `modeling_utils.PreTrainedModel._check_and_enable_flash_attn_3` (Dropout will likely be supported soon, so this will need to be updated and `modeling_flash_attention_utils._flash_attention_forward` at the `if _IS_FLASH_ATTN_3_AVAILABLE: ...` An example Llama implementation is included in `modeling_llama.py` but other models would still need to be updated Based on huggingface#36190 which has model implementations and examples which could be merged
* Support `flash_attn_3` Implements fwd and tests for Flash Attention 3 https://github.com/Dao-AILab/flash-attention/commits/main/hopper - Includes checks for dropout>0 and ALiBi in `modeling_utils.PreTrainedModel._check_and_enable_flash_attn_3` (Dropout will likely be supported soon, so this will need to be updated and `modeling_flash_attention_utils._flash_attention_forward` at the `if _IS_FLASH_ATTN_3_AVAILABLE: ...` An example Llama implementation is included in `modeling_llama.py` but other models would still need to be updated Based on #36190 which has model implementations and examples which could be merged * Add tests for Flash Attention 2 and 3 parity * ci fix * FA2 compatibiity - `_prepare_flash_attention_from_position_ids` ->`prepare_fa2_from_position_ids` - Remove bettertransformer check in Flash Attention 3 - Merge tests - Add licensing * ci fix * Test naming consistency * ci fix * Deprecation warning for `prepare_fa2_from_position_ids` * ci fix
What does this PR do?
Replaces #33522 to avoid conflicts and allow those using it to continue while we get it updated for #35235
Initial commit of this PR adds auxiliary code so we can discuss the core FAv3 integration.
cc @ArthurZucker
_flash_attention_forward
/flash_attention_forward
as before or create new functions?FlashAttention2
classes, is refactoring all models to use the new style planned? Integrate FAv3 as before or do the refactor in this PR?Also to check:
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.