Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion megatron/core/extensions/transformer_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ def forward_post_hook(module, *_) -> None:
"TEFusedMLP module does not support submodules with post-backward hooks"
)

def forward(self, hidden_states: torch.Tensor, **kwargs) -> Tuple[Tensor, Optional[Tensor]]:
def forward(self, hidden_states: torch.Tensor) -> Tuple[Tensor, Optional[Tensor]]:
"""Forward."""

# Construct fused impl if needed
Expand Down
10 changes: 5 additions & 5 deletions megatron/core/transformer/transformer_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ def _forward_mlp(self, hidden_states, inference_context=None, padding_mask=None)

# Residual connection.
residual = hidden_states
# Only MoE layers need padding_mask
mlp_kwargs = {"padding_mask": padding_mask} if self.is_moe_layer else {}

if self.offload_mlp_norm:
hidden_states = fine_grained_offloading_group_start(hidden_states, name="mlp_norm")
Expand Down Expand Up @@ -687,13 +689,11 @@ def _forward_mlp(self, hidden_states, inference_context=None, padding_mask=None)
tensor_parallel.random.get_cuda_rng_tracker,
self.pg_collection.tp,
pre_mlp_layernorm_output,
padding_mask=padding_mask,
**mlp_kwargs,
)
else:
mlp_output_with_bias = tensor_parallel.checkpoint(
functools.partial(self.mlp, padding_mask=padding_mask),
False,
pre_mlp_layernorm_output,
functools.partial(self.mlp, **mlp_kwargs), False, pre_mlp_layernorm_output
)
elif should_chunk_mlp_for_prefill:
# Chunk input along sequence dimension
Expand All @@ -709,7 +709,7 @@ def _forward_mlp(self, hidden_states, inference_context=None, padding_mask=None)
bias_output = torch.stack(bias_chunks, dim=0).sum(dim=0) if bias_chunks else None
mlp_output_with_bias = (mlp_output, bias_output)
else:
mlp_output_with_bias = self.mlp(pre_mlp_layernorm_output, padding_mask=padding_mask)
mlp_output_with_bias = self.mlp(pre_mlp_layernorm_output, **mlp_kwargs)

if self.recompute_pre_mlp_layernorm:
# discard the output of the pre-mlp layernorm and register the recompute
Expand Down
Loading