Hi everyone 
I have two nn.Module that are applied sequentially to the first input, with the second, net2, having also an additional input. I would like to compute gradient of the parameters of net1 with a loss that involves net2 and I don’t want to touch parameters in net2.
I wrote something like the following pseudocode, is it intended to work the way I think? Which values should I check?:
intermediate_output = net1(first_input)
with torch.no_grad():
    final_output = net2(intermediate_output, second_input)
final_output.requires_grad = True
loss = criterion(final_output, target)
loss.backward()

Thanks in advance!