-
Notifications
You must be signed in to change notification settings - Fork 31
add FlashAtten 4 API #218
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
add FlashAtten 4 API #218
Conversation
Summary of ChangesHello @bingchenlll, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces Flash Attention 4 (FA4) as a new, high-performance attention mechanism. The primary goal is to enhance computational efficiency, particularly on B200 GPUs, by providing an optimized alternative to existing attention implementations. The changes involve updating configuration options, dynamically importing the FA4 library, and integrating it into the core attention function with appropriate compatibility checks. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request adds support for Flash Attention 4, including detection of its availability and integration into the attention mechanism. The changes look good and follow the existing structure for adding new attention implementations. I've provided a couple of suggestions to improve code maintainability by reducing duplication and simplifying logging statements. Overall, a good contribution.
| attn_out = flash_attn4(q, k, v, softmax_scale=scale) | ||
| if isinstance(attn_out, tuple): | ||
| attn_out = attn_out[0] | ||
| return attn_out |
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.
This block of code for calling flash_attn4 and processing its output is identical to the one in lines 161-164. Duplicating code can lead to maintenance issues where a bug fix or change in one place is not applied to the other. It would be best to refactor this into a helper function to avoid repetition.
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.
I'm following the existing code pattern and don't want to introduce unnecessary refactoring.
| if FLASH_ATTN_4_AVAILABLE: | ||
| logger.info("Flash attention 4 is available") | ||
| else: | ||
| logger.info("Flash attention 4 is not available") |
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.
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.
I'm following the existing code pattern and don't want to introduce unnecessary refactoring.
| from yunchang import LongContextAttention | ||
| from yunchang.kernels import AttnType | ||
|
|
||
| assert attn_impl in [ |
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.
@bingchenlll FA4 does not work with sequence parallel right now because of dependency of yunchang. We are considering a refactor of the attention backend to remove dependency, which is overlap with this PR and please expect changes will be overwritten.
This PR adds support for Flash Attention 4.
Tested on Qwen-Image, generated images look good. Compared to FA3, there is 15% speed improvement on B200, and no speed improvement on H100.
Installation of FA4:
Use of FA4:
from flash_attn.cute.interface import flash_attn_func as flash_attn4