Hi,
As a general rule, .data is never the solution you’re looking for  Even though it can fix your issue, it is very likely to break many other things 
Here you just want the python variable “img” to point to a new leaf that is built based on the upscaled image:
img = upscale(img).detach() # Detach from history to make it a leaf
img.requires_grad_() # Make it require gradients again