What if I want to do apply a cost function of the first model and update it is parameters, and at the same time use its output for the second model without calculating the gradient on the first. this way:
G = model() 
out1 = G(inp)
criterion(out1,y)
out2 = G(out1)
criterion(out2,y)