I get this error when training on a CPU machine but not on GPU machine i.e google colab though I am computing two losses.
if phase == 'train':         loss1.backward()          loss2.backward()           optimizer.step()