[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:
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user