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

Swapped naive dot product attention for flash attention #24

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

usryokousha
Copy link

This pull request adds support for the Flash Attention mechanism to the MultiheadAttention module. Flash Attention is a recently proposed alternative to the conventional multi-head attention mechanism which reduces memory usage and improves training efficiency. The implementation in this pull request follows the paper "FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness" (https://arxiv.org/abs/2205.14135)

Changes Made:

  • Replaced the conventional multi-head attention mechanism with the Flash
    Attention mechanism in the forward() method.
  • Added support for the key_padding_mask argument to the F.scaled_dot_product_attention() function.
  • Updated the incremental_state logic to work with the new tensor shapes introduced by Flash Attention.
  • Applied the xpos method to both the q and k tensors in the forward() method.
    Replaced masked_fill with the additive mask to combine the attention mask and key padding mask.
    Please review and merge.

@usryokousha
Copy link
Author

@microsoft-github-policy-service agree

@mranzinger
Copy link

I ran into some issues using this branch as-is, and created a pull request for it here: usryokousha#1

Please review and pull in, if applicable.

mranzinger and others added 2 commits May 9, 2023 19:21
@usryokousha
Copy link
Author

Please merge with master

@usryokousha usryokousha reopened this Jun 20, 2023
@usryokousha
Copy link
Author

Please merge with master

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

Successfully merging this pull request may close these issues.

None yet

2 participants