@Megh_Bhalerao
Thank you for answering. Please see the overview of the process
x=net1(input)
x1 = f(x) {some processing, means doing some summation operation, to calculate the input of net2}
y=net2(x1)
loss = |y-gt| {gt is ground truth}
loss.backward()
so, does this loss.backward(), can take care of calculation of gradients of both the networks. In optimizer, the parameters of both the networks will be passed.