-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix glm4 moe #8883
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
fix glm4 moe #8883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -527,7 +527,10 @@ def __init__( | |
| self._enable_deepep_moe = global_server_args_dict["moe_a2a_backend"].is_deepep() | ||
|
|
||
| def forward_normal_dual_stream( | ||
| self, hidden_states: torch.Tensor, can_fuse_mlp_allreduce: bool = False | ||
| self, | ||
| hidden_states: torch.Tensor, | ||
| can_fuse_mlp_allreduce: bool = False, | ||
| use_reduce_scatter: bool = False, | ||
| ) -> torch.Tensor: | ||
|
|
||
| current_stream = torch.cuda.current_stream() | ||
|
|
@@ -548,21 +551,32 @@ def forward_normal_dual_stream( | |
| current_stream.wait_stream(self.alt_stream) | ||
|
|
||
| if self.ep_size > 1: | ||
| if self.tp_size > 1 and not can_fuse_mlp_allreduce: | ||
| if ( | ||
| self.tp_size > 1 | ||
| and not can_fuse_mlp_allreduce | ||
| and not use_reduce_scatter | ||
| ): | ||
| final_hidden_states = tensor_model_parallel_all_reduce( | ||
| final_hidden_states | ||
| ) | ||
| final_hidden_states += shared_output | ||
| else: | ||
| final_hidden_states += shared_output | ||
| if self.tp_size > 1 and not can_fuse_mlp_allreduce: | ||
| if ( | ||
| self.tp_size > 1 | ||
| and not can_fuse_mlp_allreduce | ||
| and not use_reduce_scatter | ||
| ): | ||
| final_hidden_states = tensor_model_parallel_all_reduce( | ||
| final_hidden_states | ||
| ) | ||
| return final_hidden_states | ||
|
|
||
| def forward_normal( | ||
| self, hidden_states: torch.Tensor, can_fuse_mlp_allreduce: bool = False | ||
| self, | ||
| hidden_states: torch.Tensor, | ||
| can_fuse_mlp_allreduce: bool = False, | ||
| use_reduce_scatter: bool = False, | ||
| ) -> torch.Tensor: | ||
|
Comment on lines
+578
to
580
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if hasattr(self, "shared_experts") and use_intel_amx_backend( | ||
| self.shared_experts.gate_up_proj | ||
|
|
@@ -681,6 +695,7 @@ def __init__( | |
| layer_scatter_modes=self.layer_scatter_modes, | ||
| input_layernorm=self.input_layernorm, | ||
| post_attention_layernorm=self.post_attention_layernorm, | ||
| allow_reduce_scatter=True, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While enabling To fix this,
Additionally, |
||
| ) | ||
|
|
||
| def 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.
To improve readability and maintainability, extract the condition into a local variable. This makes the logic clearer and avoids repeating the same complex condition.