Solved by albanD in post #5 
              
              
                I’m not sure what is the purpose of theta_two in your code above, why not use theta directly (turns out after more investigation below, this was the root of the problem, see the rest of the answer)? 
Also if I read correctly, loss_one = (theta * xi - 10)**2. 
So grad = 2 * xi * (theta * xi - 10). 
S…