Masked loss function (solved)

I somehow accidentally deleted optimizer.zero_grad() which caused the problems.