[Fix] Complete the deferred FFN all-reduce before deepstack addition and aux hidden-state capture (#41080)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
This commit is contained in:
Cheng Wan
2026-09-24 12:14:39 -07:00
committed by GitHub
co-authored by Mick Qian
parent 928e683f94
commit 07a3735e94
11 changed files with 298 additions and 0 deletions
+1
View File
@@ -833,6 +833,7 @@ class BailingMoEModel(nn.Module):
for i in range(self.start_layer, self.end_layer):
with get_global_expert_distribution_recorder().with_current_layer(i):
if i in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(
hidden_states if residual is None else hidden_states + residual
)
@@ -1387,6 +1387,7 @@ class BailingMoELinearModel(nn.Module):
and i in self.layers_to_capture
and hidden_states.shape[0] != 0
):
hidden_states = complete_deferred_allreduce(hidden_states)
if residual is None:
dspark_aux_hidden_states.append(hidden_states)
else:
+1
View File
@@ -1116,6 +1116,7 @@ class Glm4MoeModel(nn.Module):
for i in range(normal_start_layer, normal_end_layer):
with get_global_expert_distribution_recorder().with_current_layer(i):
if i in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(hidden_states + residual)
layer = self.layers[i]
hidden_states, residual = layer(
@@ -813,6 +813,7 @@ class Glm4MoeLiteModel(nn.Module):
for i in range(normal_start_layer, normal_end_layer):
with get_global_expert_distribution_recorder().with_current_layer(i):
if i in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(hidden_states + residual)
layer = self.layers[i]
hidden_states, residual = layer(
+1
View File
@@ -1182,6 +1182,7 @@ class Glm5NextModel(nn.Module):
)
with ctx:
if i in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_state = self._prepare_aux_hidden_state(
hidden_states, residual
)
+1
View File
@@ -731,6 +731,7 @@ class GptOssModel(nn.Module):
positions, hidden_states, forward_batch, residual
)
if i + 1 in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(
hidden_states + residual
if residual is not None
+1
View File
@@ -597,6 +597,7 @@ class LagunaModel(nn.Module):
aux_hidden_states = []
for i in range(self.start_layer, self.end_layer):
if i in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(
hidden_states + residual if residual is not None else hidden_states
)
+1
View File
@@ -1938,6 +1938,7 @@ class Qwen3_5ForCausalLM(nn.Module):
and layer_idx < 3
):
sep = self.hidden_size * layer_idx
hidden_states = complete_deferred_allreduce(hidden_states)
hidden_states.add_(
input_deepstack_embeds[:, sep : sep + self.hidden_size]
)
+2
View File
@@ -107,6 +107,7 @@ class Qwen3MoeLLMModel(Qwen3MoeModel):
):
layer_idx += self.start_layer
if layer_idx in self.layers_to_capture:
hidden_states = complete_deferred_allreduce(hidden_states)
aux_hidden_states.append(
hidden_states + residual if residual is not None else hidden_states
)
@@ -139,6 +140,7 @@ class Qwen3MoeLLMModel(Qwen3MoeModel):
and layer_idx in self.deepstack_embed_to_decoder_layer
):
sep = self.hidden_size * layer_idx
hidden_states = complete_deferred_allreduce(hidden_states)
hidden_states.add_(
input_deepstack_embeds[:, sep : sep + self.hidden_size]
)