In that case, if I do img = upscale(img) , then the loss doesn’t change after the image is upscaled. img doesn’t remain a leaf node anymore, I check this with img.is_leaf and it returned False. I also checked  img.grad and it returned None. I used img.data = upscale(img).data to overcome this hurdle.
Can you please suggest how I may implement it?