Solved by jpeg729 in post #2 
              
              
                In future, please use the code formatting tool. 
This works. 
loss_ht = 0.5*torch.norm((x-x_e),p=2)**2
loss_ht.backward()

Don’t use x.data if you want to be able to backprop, or you really know what you are doing.