-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add qwen3 attn #1602
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?
add qwen3 attn #1602
Conversation
Summary of ChangesHello @poryfly, 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 integrates dedicated attention mechanisms and a comprehensive set of optimization rules for Qwen3Moe models within the Highlights
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 Qwen3 attention by introducing a new KQwen3MoeAttention operator and an optimization rule file Qwen3Moe-sft-amx.yaml. The changes are generally in the right direction, but I've identified a few critical issues that need to be addressed.
In attention.py, the attention implementation is hardcoded, which limits flexibility.
In Qwen3Moe-sft-amx.yaml, there are two significant problems:
- An incorrect class is targeted for RoPE optimization, which will cause it to fail.
- A model replacement rule is duplicated and points to an incorrect model class for Qwen2 instead of Qwen3.
These issues could lead to incorrect model behavior or failed optimizations. Please see the detailed comments for suggestions on how to fix them.
| @@ -0,0 +1,103 @@ | |||
| - match: | |||
| class: ktransformers.models.modeling_qwen2_moe.Qwen2MoeRotaryEmbedding | |||
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 match rule for RotaryEmbedding replacement is targeting ktransformers.models.modeling_qwen2_moe.Qwen2MoeRotaryEmbedding. However, the Qwen3 model uses ktransformers.models.modeling_qwen3_moe.Qwen3MoeRotaryEmbedding. This will cause the RoPE optimization to be skipped for Qwen3 models. Please correct the class path.
class: ktransformers.models.modeling_qwen3_moe.Qwen3MoeRotaryEmbedding| key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs) | ||
|
|
||
| attention_interface: Callable = eager_attention_forward | ||
| self.config._attn_implementation = "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.
| - match: | ||
| name: "^model$" | ||
| replace: | ||
| class: "ktransformers.operators.models.KQwen2MoeModel" | ||
| kwargs: | ||
| per_layer_prefill_intput_threshold: 0 # 0 is close layer wise prefill |
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 are two match rules for name: "^model$". The first one incorrectly specifies class: "ktransformers.operators.models.KQwen2MoeModel", which is for Qwen2 models, not Qwen3. This is likely a copy-paste error and is redundant with the correct rule at the end of the file. Please remove this incorrect and duplicated rule block.
|
Please add some description to this PR. |
Wait for a moment. We are working together to improve it. |
No description provided.