-
Notifications
You must be signed in to change notification settings - Fork 629
[CustomOp][MM] Register AscendMMEncoderAttention CustomOp and remove related patch #4750
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
Signed-off-by: shen-shanshan <467638484@qq.com>
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 refactors the Ascend-specific implementation of multi-modal encoder attention by creating a new custom operator, AscendMMEncoderAttention. This improves code organization by moving specialized logic out of a model-specific patch file (patch_qwen2_5_vl.py) and into a reusable operator. The changes also include registering this new operator in the system. The refactoring is well-done, but I've found a couple of potential issues in the new custom operator that could affect correctness and robustness, particularly regarding support for Grouped-Query Attention and handling of optional arguments.
| v = F.pad(v, (0, pad_len), mode="constant", value=0) | ||
|
|
||
| context_layer = torch.empty_like(q) | ||
| cu_seqlens = torch.diff(cu_seqlens).to("cpu") |
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 cu_seqlens tensor is used without checking if it is None. The function signature allows cu_seqlens to be None, which would cause a TypeError when torch.diff is called. This could lead to a runtime crash. Please add a check to ensure cu_seqlens is not None before using it.
| cu_seqlens = torch.diff(cu_seqlens).to("cpu") | |
| if cu_seqlens is None: | |
| raise ValueError("cu_seqlens cannot be None for AscendMMEncoderAttention") | |
| cu_seqlens = torch.diff(cu_seqlens).to("cpu") |
| seq_len=cu_seqlens, | ||
| scale_value=self.head_size**-0.5, | ||
| num_heads=self.num_heads, | ||
| num_kv_heads=self.num_heads, |
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 number of key-value heads (num_kv_heads) is hardcoded to self.num_heads. This is incorrect for models that use Grouped-Query Attention (GQA) or Multi-Query Attention (MQA) where the number of key-value heads is different from the number of query heads. The num_kv_heads parameter is passed during initialization and should be available as self.num_kv_heads.
| num_kv_heads=self.num_heads, | |
| num_kv_heads=self.num_kv_heads, |
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. |
What this PR does / why we need it?
Register AscendMMEncoderAttention CustomOp and remove related patch.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
✅ Run Qwen2.5-VL:
Output:
✅ Run Qwen3-VL:
Output: