megatron.model.language_model.TransformerLanguageModel#

class megatron.model.language_model.TransformerLanguageModel(init_method: Callable, output_layer_init_method, encoder_attn_mask_type, num_tokentypes=0, add_encoder=True, add_decoder=False, decoder_attn_mask_type=AttnMaskType.causal, add_pooler=False, pre_process=True, post_process=True, args=None, model_type=None)#

Bases: MegatronModule

Transformer language model.

Parameters:
  • transformer_hparams – transformer hyperparameters

  • vocab_size – vocabulary size

  • max_sequence_length – maximum size of sequence. This is used for positional embedding

  • embedding_dropout_prob – dropout probability for embeddings

  • num_tokentypes – size of the token-type embeddings. 0 value will ignore this embedding

forward(enc_input_ids, enc_position_ids, enc_attn_mask, dec_input_ids=None, dec_position_ids=None, dec_attn_mask=None, enc_dec_attn_mask=None, tokentype_ids=None, inference_params=None, pooling_sequence_index=0, enc_hidden_states=None, output_enc_hidden=False)#

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.

load_state_dict(state_dict, strict=True)#

Customized load.

set_input_tensor(input_tensor)#

See megatron.model.transformer.set_input_tensor()

state_dict_for_save_checkpoint(prefix='', keep_vars=False)#

For easy load.