megatron.model.language_model.Embedding#

class megatron.model.language_model.Embedding(hidden_size, vocab_size, max_position_embeddings, embedding_dropout_prob, init_method, num_tokentypes=0)#

Bases: MegatronModule

Language model embeddings.

Parameters:
  • hidden_size – hidden size

  • vocab_size – vocabulary size

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

  • embedding_dropout_prob – dropout probability for embeddings

  • init_method – weight initialization method

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

add_tokentype_embeddings(num_tokentypes)#

Add token-type embedding. This function is provided so we can add token-type embeddings in case the pretrained model does not have it. This allows us to load the model normally and then add this embedding.

forward(input_ids, position_ids, tokentype_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.

load_state_dict(state_dict, strict=True)#

Customized load.

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

For easy load.

zero_parameters()#

Zero out all parameters in embedding.