Hi all,
I am trying to convert this tensorflow code into pytorch. For example, I converted the below tensorflow code
tf.get_variable("char_embeddings", [len(data.char_dict), data.char_embedding_size]),  char_index)  # [num_sentences, max_sentence_length, max_word_length, emb]


into
class CharEmbeddings(nn.Module):
    def __init__(self, config, data):
          ....
          self.embeddings = nn.init.xavier_uniform_(torch.empty(len(data.char_dict), data.char_embedding_size))
   

    def forward(self, char_index):
        # [num_sentences, max_sentence_length, max_word_length, emb]
        char_emb = self.embeddings[char_index]       

From what I read, if no initializer is passed to the get_variable here, the glorot_uniform_initializer  will be used which is I think it equivalent to xavier_uniform_
Two questions here:

Is that conversion valid?
Should I expect the original embeddings self.embeddings to backpropagate and update its values? Is that the expected behavior from the tensorflow version as well? Should I add requires_grad to the embeddings tensor?