They’re different because by default NLLLoss averages over the number of observations. See:
http://pytorch.org/docs/master/nn.html#torch.nn.NLLLoss 329
Set size_average to False and divide the loss by the number of non-padding tokens. That should give you approximately the same value.
It will affect back-propagation in the same way that scaling your learning rate affects it: scaling the loss by X scales the gradients by the same factor X.