The error seems to be raised in:
src = self.encoder(src) * math.sqrt(self.ninp)

which points to self.encoder = nn.Embedding(ntoken, ninp).
Could you check the min and max values of src and make sure they are in the valid input range for this layer [0, ntoken-1]?