In version 0.2.0 they added ignore_index in CrossEntropyLoss 175. I think this addition solves the problem. I use it like this:
loss_function = nn.CrossEntropyLoss(ignore_index=0)

since i have zero padded targets.
I used to use this masked_cross_entropy 264 workaround, but i tested them both and i observe the same behaviour (compared to CrossEntropyLoss without ignore_index=0).