-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Separate MLAAttention class from Attention (needs Review) #25103
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: Naveenraj Kamalakannan <[email protected]>
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run You ask your reviewers to trigger select CI tests on top of Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
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 Multi-Head Latent Attention (MLA) logic out of the generic Attention
class and into a new, dedicated MLAAttention
class. This is a good step towards better code organization and separation of concerns. The changes in vllm/attention/layer.py
and vllm/model_executor/layers/mla.py
correctly remove the old MLA logic and adopt the new class. However, the new MLAAttention
class in vllm/model_executor/layers/mla_attention.py
has critical implementation issues. It fails to properly instantiate and call the attention backend, and it lacks the necessary integration with the KV cache and attention metadata management. These issues will prevent the MLA feature from functioning. I've left detailed comments on how to address these critical problems.
Signed-off-by: Naveenraj Kamalakannan <[email protected]>
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.
A few minor notes
k_pe, | ||
output_shape=(hidden_states.shape[0], | ||
self.num_heads * self.v_head_dim)) | ||
return self.o_proj(attn_out)[0] |
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 think we want to keep the abstraction where the MLAAttentionLayer
does not handle its own rope, qkv_proj, o_proj, etc.
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.
@ProExpertProg I've made changes to this. MLAAttention.forward()
takes care of this. Correct me if I'm wrong
kv_c_normed = key # normalized KV cache | ||
k_pe = value.unsqueeze(1) if value.dim() == 2 else value | ||
|
||
attn_out = self.impl.forward( |
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.
We need to wrap into a custom op, could you make a unified_mla_attention
/unified_mla_attention_with_output
custom op(s), and add them to splitting ops by default etc.
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.
(still respect the use_direct_call from the backend/platform)
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.
@LucasWilkinson Should we make a vllm/model_executor/layers/mla
folder containing this file and mla.py
?
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 think we should just put this code in mla.py
; I dont think we need 2 files
Signed-off-by: Naveenraj Kamalakannan <[email protected]>
@ProExpertProg i'm working on |
Yeah to start they can just mimic the |
Signed-off-by: Naveenraj Kamalakannan <[email protected]>
Hi @ProExpertProg, thanks for the feedback. I've added the
The Let me know what you think. Thanks |
attn_metadata = forward_context.attn_metadata | ||
if isinstance(attn_metadata, dict): | ||
attn_metadata = attn_metadata[layer_name] | ||
self = forward_context.no_compile_layers[layer_name] |
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.
We should type-annotate self here
class MultiHeadLatentAttentionWrapper(CustomOp): | ||
"""MLA layer registered as CustomOp. |
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.
Something like this:
class MultiHeadLatentAttentionWrapper(CustomOp): | |
"""MLA layer registered as CustomOp. | |
class MultiHeadLatentAttentionWrapper(CustomOp): | |
"""MLA layer registered as CustomOp to allow OOT backends to add custom implementations of the outer MLA layer (including rope & o_proj). |
q_proj: Optional[torch.nn.Module] | ||
|
||
|
||
class MLAAttention(nn.Module, AttentionLayerBase): |
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 think I'd rather see this in vllm/attention/layer.py
or vllm/attention/mla.py
- @LucasWilkinson what do you think?
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.
vllm/attention/layer.py
makes sense to me
Purpose
This PR implements the first step of #24620 by separating Multi-Head Latent Attention into its own dedicated
AttentionLayerBase
subclass.Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.