-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[bugfix] fix MHA for models like OpenGVLab/InternVL3_5-38B #25146
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
Conversation
@Isotr0py can you help review this? |
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 addresses a ValueError
that occurs in MultiHeadAttention
when processing input query tensors with more than three dimensions, as seen with models like OpenGVLab/InternVL3_5-38B
. The fix correctly extracts the batch size and sequence length by slicing the shape tuple, making the implementation more robust and compatible with higher-dimensional inputs. The change is correct and effectively resolves the bug. I've added one high-severity comment regarding an outdated docstring, which should be updated to reflect the new capability and ensure long-term maintainability.
vllm/attention/layer.py
Outdated
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.
While this change correctly handles tensors with more than 3 dimensions, the method's docstring on line 433 was not updated. It still states Input shape: batch_size x seq_len x hidden_size
, which is now misleading. Inaccurate documentation for a core component like this can lead to incorrect usage and bugs in the future. Please update the docstring to reflect that the input can have more than three dimensions, for example, by mentioning that additional dimensions are allowed after seq_len
.
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.
Thanks for fixing!
vllm/attention/layer.py
Outdated
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.
"""Input shape: batch_size x seq_len x hidden_size""" | |
"""Input shape: | |
(batch_size x seq_len x hidden_size) or | |
(batch_size x seq_len x num_heads x head_size) | |
""" |
Let's also update the docstring.
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.
Should we also remove TODO(Isotr0py): Use existing backend implementations and support FA3
as FA3 supported by #24337?
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.
Sure!
Signed-off-by: Yan Ma <yan.ma@intel.com>
Signed-off-by: Yan Ma <yan.ma@intel.com>
…ect#25146) Signed-off-by: Yan Ma <yan.ma@intel.com> Co-authored-by: Isotr0py <mozf@mail2.sysu.edu.cn>
…ect#25146) Signed-off-by: Yan Ma <yan.ma@intel.com> Co-authored-by: Isotr0py <mozf@mail2.sysu.edu.cn>
…ect#25146) Signed-off-by: Yan Ma <yan.ma@intel.com> Co-authored-by: Isotr0py <mozf@mail2.sysu.edu.cn> Signed-off-by: charlifu <charlifu@amd.com>
Purpose
The query of models like OpenGVLab/InternVL3_5-38B is 4 dimension so will pop error:
Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.