Solved by ptrblck in post #2 
              
              
                This line of code: 
p = p - self.alpha * (x_normal - x_tilde)

would create a non-leaf tensor, so that the following p.grad call would raise this warning. 
Based on your code I think you should new a new variable name for this assignment and keep p pointing to the parameters in the optimizer. 
Also,…