You could calculate the losses from using output1 and output2, accumulate them, and call loss.backward() to calculate the gradients for all 3 models. If you don’t want to train netB and netC, you could set the .requires_grad attribute if their parameters to False.
In case you want to get the gradients in state, you could call state.retrain_grad(), which would then  allow you to access its .grad after the backward call.