Unless your loss / model modifies the value in place, as the error says, it could be caused by calling optimizer1.step() before calculating loss2.backward(). Make sure it works with 1 optimizer before doing two.