There may exist a problem of torch.nn.functional.embedding

print(torch.nn.functional.embedding(torch.LongTensor([[0,2,0,5]]), torch.rand(10, 3), padding_idx=0))

The output embedding vectors are not zero if the corresponding index=0.