megatron.model.transformer.ParallelTransformerLayer#

class megatron.model.transformer.ParallelTransformerLayer(init_method: Callable, output_layer_init_method: Callable, layer_number: int, layer_type=LayerType.encoder, self_attn_mask_type=AttnMaskType.padding, drop_path_rate: float = 0.0, world_size: int | None = None, hidden_dropout: float = 0.0, args=None)#

Bases: MegatronModule

A single transformer layer. Transformer layer takes input with size [s, b, h] and returns an output of the same size.

forward(hidden_states: Tensor, attention_mask: Tensor, encoder_output=None, enc_dec_attn_mask=None, inference_params=None, position_ids=None)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.