megatron.model.transformer.ParallelTransformer#

class megatron.model.transformer.ParallelTransformer(init_method: Callable, output_layer_init_method, layer_type=LayerType.encoder, self_attn_mask_type=AttnMaskType.padding, pre_process=True, post_process=True, drop_path_rate=0.0, args=None, model_type=None)#

Bases: MegatronModule

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.

set_input_tensor(input_tensor)#

Set input tensor to be used instead of forward()’s input.

When doing pipeline parallelism the input from the previous stage comes from communication, not from the input, so the model’s forward_step_func won’t have it. This function is thus used by internal code to bypass the input provided by the forward_step_func