Thank you for your detailed explanation about .clone() method.
I face an issue during training stacked of 2 unet module. the input to the network is a batch of single image and some geometric transformation on it. Then I apply inverse of augmentation to the images (F -1) and compute a loss #1 function. Also, I have loss #2 at the end of the network.
(x + F(x)) --> Unet1 -->  loss#1(y+ F-1(y)) --> Unet2 --> loss#2(z+ F-1(z))
In general, I got this error:
“one of the variables needed for gradient computation has been modified by an inplace operation”.
I resolved this error by utilizing y.clone() and then apply inverse geometric transformation.
(x + F(x)) --> Unet1 -->  loss#1(y+ F-1(y.clone())) --> Unet2 --> loss#2(z+ F-1(z.clone()))
Now, it seems that it is working well, yet I am suspicious about it. Is it Ok or not? does the gradient flow back to the Unet1 and does the gradient from Unet2 flow back to Unet1?
Note; I use pytorch functions for some geometric transformation, but for others not. I have converted them to numpy to do that.