@ptrblck Thanks for your comment, I edited mine accordingly  I can confirm that this bug is occurring in torch 0.4 but cannot reproduce it in 1.0.
Could you comment on the internals of ignore_index?
Is the following code the exact. or near exact, representation of what ignore_index does?
loss = torch.mean(loss[groundtruth!=-1])
loss.backward()