The problem is that my code can be simplified like this:
     optimizer.zero_grad()
     out1, out2 = model(input)
     loss1 = my_magic_loss_with_weight_tensor_inside(out1, label)  
     loss2 = my_magic_loss_with_weight_tensor_inside(out2, label)  
     loss = loss1 + loss2
     loss.backward()
     optimizer.step()

The problem is that the output of the model comes from the same input and model, while the loss has some weight tensor in it which is expected to be shared with the two outputs out1 and out2.
What is the good way to do this, please ?