-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Deepseek moe #2467
Deepseek moe #2467
Conversation
else: | ||
final_hidden_states.add_(current_hidden_states) | ||
|
||
y = tensor_model_parallel_all_reduce(final_hidden_states) |
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.
reducing after forwarding sharedexpert could avoiding one extra reduce operation, as sharedexpert also requires a reduce operation; these two operations can be merged.
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 didn't split shared_expert weights, and there is no need to reduce for that. Am i right?
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.
oh, it's right
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.
splitting shared_expert may have higher performance, reducing memory required by each gpu
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.
Emm..., It seems make sense. But maybe we can wait for #2293. And then consider improving performance.
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.
self.expert_indicies = np.array_split(range( | ||
self.n_routed_experts), self.tp_size)[self.rank].tolist() |
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.
nit: we can replace with pure-pytorch version
torch.arange(self.n_routed_experts
).split(self.n_routed_experts // self.tp_size)[self.rank].tolist()
@@ -0,0 +1,468 @@ | |||
# coding=utf-8 | |||
# Adapted from | |||
# https://github.com/huggingface/transformers/blob/v4.28.0/src/transformers/models/llama/modeling_llama.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.
can we update this comment? seems adapted mostly from mixtral.py
max_position_embeddings=max_position_embeddings, | ||
linear_method=linear_method, | ||
) | ||
self.mlp = DeepseekMoE(config=config, |
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'm pretty sure this would be easier to read if you did
if <...>:
self.mlp = DeepseekMoE(...)
else:
self.mlp = DeepseekMLP(...)
:)
@cadedaniel @pcmoritz Thanks for your reviews! I suggest to merge the fused moe version in #2453 which is faster. And i will close this PR and let's pushing that PR being merged. |
This is a refactor version based #2453, since i have no permission to change onto that PR.
load_weight
logic cleaner, and remove unnecessarymerged_replicated_linear_loader
function.reduce_results
args of DeepseekMLPshared_expert
andexpert
use sameDeepseekExpertMLP
which is semantically appropriate.Mixtral
MLP withDeepseekExpertMLP
by usingReplicatedLinear
acrossgate_proj
,up_proj
,down_proj
.@zwd003 Thanks for your contribution again! And happy to be co-auther with you.
@zhuohan123 @WoosukKwon This PR is ready for review! Also we can wait for #2293