Is there a reason why you need to backprop loss1 first and again when loss have been calculated?
The common structure when using multiple objective functions is to simply just backprop both of them at once:
for epochs
   for minibatch
       inputs.requires_grad_()
       logits = model(inputs)
       loss1 = loss_fn(logits, y)
       # oss1.backward(retain_graph=True)    <-- Removed this line
       loss2 = loss_fn(x, y)
       loss = loss1 + loss2 
       loss.backward() 
       opt.step()

And balance the different losses with constants i.e.:
loss = 2*loss1 + 1*loss2

If loss1 is more important than loss2.