Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions paddleformers/transformers/glm4_moe/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,17 @@ def moe(self, hidden_states: paddle.Tensor, topk_indices: paddle.Tensor, topk_we
return final_hidden_states.cast(hidden_states.dtype)

def forward(self, hidden_states):
residuals = hidden_states
orig_shape = hidden_states.shape
if self.sequence_parallel:
hidden_states = GatherOp.apply(hidden_states)
residuals = hidden_states
orig_shape = hidden_states.shape
topk_indices, topk_weights = self.gate(hidden_states)
hidden_states = hidden_states.reshape((-1, hidden_states.shape[-1]))
hidden_states = self.moe(hidden_states, topk_indices, topk_weights)
if self.sequence_parallel:
hidden_states = ScatterOp.apply(hidden_states)
hidden_states = paddle.reshape(hidden_states, orig_shape)
hidden_states = hidden_states + self.shared_experts(residuals)
if self.sequence_parallel:
hidden_states = ScatterOp.apply(hidden_states)
return hidden_states


Expand Down