In the nn.Embedding provided by PyTorch, padding_idx is an int that doesn’t change, for that reason we have added it to __constants__ in nn.Embedding (code here 1). Since LearnedPositionalEmbedding does not override __constants__, it gets the one from nn.Embedding.
If you want padding_idx to be a Tensor (which is not a supported constant type 1), you’ll have to provide your own __constants__ that removes padding_idx but keeps the other stuff around, something like:
from fairseq import utils

class LearnedPositionalEmbedding(nn.Embedding):
    __constants__ = ['num_embeddings', 'embedding_dim', 'max_norm',
                     'norm_type', 'scale_grad_by_freq', 'sparse']
    def __init__(self, num_embeddings, embedding_dim, padding_idx, left_pad):
        super().__init__(num_embeddings, embedding_dim, padding_idx)
        self.left_pad = left_pad