Two different networks, combined loss, back propagation and optimizer step

Hi all,
So here is my network architecture as shown in below image.
I’ve two separate networks and loss_1 and loss_2 are coming from two separate nn.Modules networks and final_loss = loss_1 + loss_2 .

Untitled%20Diagram

Still only one final_loss.backward() would calculate grad in both networks?
I do have two separate optimizers to update grads in two separate networks respectively.

If not so, then what is the correct way to do back propagation in these individual networks on combined loss value.

Yes, you need two Optimizers.
The Network structure you have choosen is pretty similar to so called “GAN” Networks. There are a lot of them in the Link below

Greetings :slight_smile:

Yes, calling backward() on the the combined loss computes gradient for both of the networks.
However, in your case, there is no relationship between the networks, then you can call the backward separately without any problem.