-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[Model] Add Afmoe architecture implementation #28332
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
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr>
|
👋 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. 🚀 |
|
Documentation preview: https://vllm--28332.org.readthedocs.build/en/28332/ |
914ad26 to
f8ecf32
Compare
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Pranav <veldurthipranav@gmail.com>
|
Also CC @ywang96 |
| def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: | ||
| num_tokens, hidden_dim = hidden_states.shape | ||
| hidden_states = hidden_states.view(-1, hidden_dim) | ||
|
|
||
| if self.n_shared_experts > 0: | ||
| shared_output = self.shared_experts(hidden_states) | ||
| else: | ||
| shared_output = torch.zeros_like(hidden_states) | ||
|
|
||
| router_logits = self.gate(hidden_states.to(dtype=torch.float32)) | ||
|
|
||
| fused_moe_out = self.experts( | ||
| hidden_states=hidden_states, router_logits=router_logits | ||
| ) | ||
|
|
||
| if self.shared_experts is not None: | ||
| shared_output, final_hidden_states = fused_moe_out | ||
| final_hidden_states = final_hidden_states + shared_output | ||
| else: | ||
| final_hidden_states = fused_moe_out | ||
| if self.tp_size > 1: | ||
| final_hidden_states = self.experts.maybe_all_reduce_tensor_model_parallel( | ||
| final_hidden_states | ||
| ) | ||
|
|
||
| return final_hidden_states.view(num_tokens, hidden_dim) |
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 you still need to update this to work with SharedFusedMoE. See qwen2_moe for instance
vllm/vllm/model_executor/models/qwen2_moe.py
Lines 170 to 188 in e64011f
| def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: | |
| # NOTE: hidden_states can have either 1D or 2D shape. | |
| orig_shape = hidden_states.shape | |
| hidden_dim = hidden_states.shape[-1] | |
| hidden_states = hidden_states.view(-1, hidden_dim) | |
| # router_logits: (num_tokens, n_experts) | |
| router_logits, _ = self.gate(hidden_states) | |
| final_hidden_states = self.experts( | |
| hidden_states=hidden_states, router_logits=router_logits | |
| ) | |
| if self.shared_expert is not None: | |
| final_hidden_states = final_hidden_states[0] + final_hidden_states[1] | |
| if self.tp_size > 1: | |
| final_hidden_states = self.experts.maybe_all_reduce_tensor_model_parallel( # noqa E501 | |
| final_hidden_states | |
| ) | |
| return final_hidden_states.view(orig_shape) |
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.
Yeah, I missed removing the previous shared experts computation.
Is that all or am i missing something else?
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.
cc @bnellnm @alexm-redhat could you check too?
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.
Looks good to me.
|
Also should make sure to add this arch to |
vllm/model_executor/models/afmoe.py
Outdated
| logical_replica_count=logical_replica_count, | ||
| ) | ||
|
|
||
| def get_input_embeddings(self, input_ids: torch.Tensor) -> torch.Tensor: |
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.
This was renamed to embed_input_ids in #27583, can you update this?
Signed-off-by: Pranav <veldurthipranav@gmail.com>
Signed-off-by: Pranav <veldurthipranav@gmail.com>
Signed-off-by: Pranav <veldurthipranav@gmail.com>
|
Made the fixes |
mgoin
left a comment
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.
LGTM and ready to go! I think we can merge ahead of time and enable the model test later
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: Pranav <veldurthipranav@gmail.com> Co-authored-by: Maziyar Panahi <maziyar.panahi@iscpif.fr>
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: Pranav <veldurthipranav@gmail.com> Co-authored-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: jiang1.li <jiang1.li@intel.com>
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: Pranav <veldurthipranav@gmail.com> Co-authored-by: Maziyar Panahi <maziyar.panahi@iscpif.fr>
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: Pranav <veldurthipranav@gmail.com> Co-authored-by: Maziyar Panahi <maziyar.panahi@iscpif.fr>
Signed-off-by: Maziyar Panahi <maziyar.panahi@iscpif.fr> Signed-off-by: Pranav <veldurthipranav@gmail.com> Co-authored-by: Maziyar Panahi <maziyar.panahi@iscpif.fr>
Purpose
This PR adds architecture implementation of upcoming Arcee AI AFMoE (trinity) models.
Test Plan
The model is not public yet, verified serving of AFMoE across configs.
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.