-
Notifications
You must be signed in to change notification settings - Fork 153
Add flash attention 3 support for LightLLMKernelTextEncoder #850
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @sitatec, 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 enhances the LightLLMKernelTextEncoder by integrating support for Flash Attention 3, offering users a newer, potentially more optimized attention mechanism. Concurrently, it refines the fallback attention strategy by adopting SDPA, which promises better performance and seamless integration with 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 FlashAttention 3 in the LightLLMKernelTextEncoder. The changes include updating the attention implementation selection logic in qwen25_text_encoder_kernel.py and documenting the new option in the beginner guides. Additionally, the fallback attention implementation has been switched from eager to the more performant sdpa.
My review focuses on improving the clarity of the new documentation and suggesting a minor readability improvement to the implementation logic. Overall, the changes are good and the performance improvement from using sdpa is a welcome addition.
| **Parameters Explanation:** | ||
| * `text_encoder_type`: Set to **"lightllm_kernel"**. | ||
| * `use_flash_attention_kernel`: Enable FlashAttention acceleration for Attention layers. | ||
| * `use_flash_attention_kernel`: Enable FlashAttention acceleration for Attention layers. By default flash_attention_2 will be used, but you can also use "use_flash_attention_kernel": "flash_attention_3". |
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.
The description for use_flash_attention_kernel could be more explicit about the accepted values for clarity. It's good that you've documented the new option, but we can make it even clearer for users.
| * `use_flash_attention_kernel`: Enable FlashAttention acceleration for Attention layers. By default flash_attention_2 will be used, but you can also use "use_flash_attention_kernel": "flash_attention_3". | |
| * `use_flash_attention_kernel`: Enable FlashAttention acceleration for Attention layers. Set to `true` to use `flash_attention_2` (the default when enabled), or set to the string `"flash_attention_3"` to use FlashAttention 3. |
| **参数说明:** | ||
| * `text_encoder_type`: 设置为 **"lightllm_kernel"**。 | ||
| * `use_flash_attention_kernel`: 启用 FlashAttention 加速 Attention 层。 | ||
| * `use_flash_attention_kernel`: 启用 FlashAttention 加速 Attention 层。 默认情况下将使用 flash_attention_2,但你也可以使用 “use_flash_attention_kernel”: “flash_attention_3”。 |
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.
For clarity, the description for use_flash_attention_kernel could be more explicit about the accepted values. It's good that you've documented the new option, but we can make it even clearer for users. This comment is a translation of the one for the English documentation.
| * `use_flash_attention_kernel`: 启用 FlashAttention 加速 Attention 层。 默认情况下将使用 flash_attention_2,但你也可以使用 “use_flash_attention_kernel”: “flash_attention_3”。 | |
| * `use_flash_attention_kernel`: 启用 FlashAttention 加速 Attention 层。设置为 `true` 可使用 `flash_attention_2` (启用时的默认选项),或设置为字符串 `"flash_attention_3"` 以使用 FlashAttention 3。 |
| if self.use_flash_attention_kernel == "flash_attention_3": | ||
| attn_impl = "flash_attention_3" | ||
| else: | ||
| attn_impl = "flash_attention_2" |
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.
The logic is correct, but it could be made slightly more explicit and readable by setting a default and then overriding it. This can make the intention clearer to future readers of the code.
| if self.use_flash_attention_kernel == "flash_attention_3": | |
| attn_impl = "flash_attention_3" | |
| else: | |
| attn_impl = "flash_attention_2" | |
| attn_impl = "flash_attention_2" # Default to flash_attention_2 when enabled | |
| if self.use_flash_attention_kernel == "flash_attention_3": | |
| attn_impl = "flash_attention_3" |
No description provided.