[Refactor] Leave decoder stacks through final_norm(skip_empty=True) (#41751)
This commit is contained in:
@@ -581,12 +581,9 @@ class GigaChat35Model(nn.Module):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
return hidden_states
|
||||
|
||||
|
||||
|
||||
@@ -791,12 +791,9 @@ class InternS2MobiusForCausalLM(Qwen3_5ForCausalLM):
|
||||
input_deepstack_embeds[:, start : start + self.hidden_size],
|
||||
)
|
||||
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
return (
|
||||
hidden_states
|
||||
if not aux_hidden_states
|
||||
|
||||
@@ -607,17 +607,15 @@ class LagunaModel(nn.Module):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
capture=aux_hidden_states.append
|
||||
if self.end_layer in self.layers_to_capture
|
||||
else None,
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
capture=aux_hidden_states.append
|
||||
if self.end_layer in self.layers_to_capture
|
||||
else None,
|
||||
skip_empty=True,
|
||||
)
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
return hidden_states, aux_hidden_states
|
||||
|
||||
@@ -1177,12 +1177,9 @@ class MiniMaxM2Model(nn.Module):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
|
||||
@@ -1517,11 +1517,9 @@ class MiniMaxM3Model(nn.Module):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
|
||||
@@ -1214,11 +1214,9 @@ class Qwen2MoeModel(nn.Module):
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
else:
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
@@ -1310,9 +1308,6 @@ class Qwen2MoeForCausalLM(nn.Module):
|
||||
)
|
||||
|
||||
if end == self.model.config.num_hidden_layers:
|
||||
forward_batch.hidden_states = residual_batch.complete_output(
|
||||
forward_batch.hidden_states, forward_batch
|
||||
)
|
||||
# norm
|
||||
hidden_states = residual_batch.final_norm(
|
||||
forward_batch.hidden_states, forward_batch, self.model.norm
|
||||
|
||||
@@ -477,11 +477,9 @@ class Qwen3Model(Qwen2Model):
|
||||
)
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
return (
|
||||
(hidden_states, aux_hidden_states) if aux_hidden_states else hidden_states
|
||||
)
|
||||
|
||||
@@ -1099,9 +1099,6 @@ class Qwen3MoeForCausalLM(nn.Module):
|
||||
)
|
||||
|
||||
if end == self.model.config.num_hidden_layers:
|
||||
forward_batch.hidden_states = residual_batch.complete_output(
|
||||
forward_batch.hidden_states, forward_batch
|
||||
)
|
||||
# norm
|
||||
hidden_states = residual_batch.final_norm(
|
||||
forward_batch.hidden_states, forward_batch, self.model.norm
|
||||
|
||||
@@ -1267,14 +1267,13 @@ class Qwen3LLMModel(Qwen3Model):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
post_residual_addition=last_deepstack,
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
post_residual_addition=last_deepstack,
|
||||
skip_empty=True,
|
||||
)
|
||||
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
|
||||
@@ -157,14 +157,13 @@ class Qwen3MoeLLMModel(Qwen3MoeModel):
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
else:
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
post_residual_addition=last_deepstack,
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states,
|
||||
forward_batch,
|
||||
self.norm,
|
||||
post_residual_addition=last_deepstack,
|
||||
skip_empty=True,
|
||||
)
|
||||
|
||||
if len(aux_hidden_states) == 0:
|
||||
return hidden_states
|
||||
|
||||
@@ -1169,12 +1169,9 @@ class SarvamMLAModel(nn.Module):
|
||||
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
|
||||
return hidden_states
|
||||
|
||||
@@ -1274,9 +1271,6 @@ class SarvamMLAForCausalLM(nn.Module):
|
||||
)
|
||||
|
||||
if end == self.model.config.num_hidden_layers:
|
||||
forward_batch.hidden_states = residual_batch.complete_output(
|
||||
forward_batch.hidden_states, forward_batch
|
||||
)
|
||||
forward_batch.hidden_states = residual_batch.final_norm(
|
||||
forward_batch.hidden_states, forward_batch, self.model.norm
|
||||
)
|
||||
@@ -1453,9 +1447,6 @@ class SarvamMoEForCausalLM(BailingMoEForCausalLM):
|
||||
)
|
||||
|
||||
if end == self.model.config.num_hidden_layers:
|
||||
forward_batch.hidden_states = residual_batch.complete_output(
|
||||
forward_batch.hidden_states, forward_batch
|
||||
)
|
||||
forward_batch.hidden_states = residual_batch.final_norm(
|
||||
forward_batch.hidden_states, forward_batch, self.model.norm
|
||||
)
|
||||
|
||||
@@ -479,12 +479,9 @@ class Step3TextModel(nn.Module):
|
||||
layer = self.layers[i]
|
||||
hidden_states = layer(positions, hidden_states, forward_batch)
|
||||
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
return hidden_states
|
||||
|
||||
|
||||
|
||||
@@ -1646,11 +1646,9 @@ class XllmModel(nn.Module):
|
||||
if not self.pp_group.is_last_rank:
|
||||
return residual_batch.to_pp(hidden_states, forward_batch)
|
||||
else:
|
||||
hidden_states = residual_batch.complete_output(hidden_states, forward_batch)
|
||||
if hidden_states.shape[0] != 0:
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm
|
||||
)
|
||||
hidden_states = residual_batch.final_norm(
|
||||
hidden_states, forward_batch, self.norm, skip_empty=True
|
||||
)
|
||||
|
||||
return hidden_states
|
||||
|
||||
|
||||
Reference in New Issue
Block a user