Hello,
I have a network that acts on a tensor h and I need at some point to access a quantity u that happens to be the gradient of an unrelated operation, MSE(F.interpolate(h) - y), with regard to h. The way I’m doing it at the moment is creating a cloned, detached version of h that requires gradient, feeding that into the operation, calling backward() and then h_clone.grad. However, at test time, this fails with “RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn”, presumably because in eval mode, torch does not keep the gradients. What is the proper way to resolve this ? Since really all I want is the derivative of the bicubic interpolation, is there some kind of backward call I can apply on the function directly to access the gradient? This would also allow me to have a gradient signal from u to h as I’m afraid creating another clone object does not do that.
Thanks in advance,
Teven
(as an aside, what algorithm does torch bicubic interpolation use ? I’ve written a small downsampling script to use the easily-computable derivative as it’s just a convolution operation, following this 7, but it doesn’t seem to correspond to any of the filters)