Solved by albanD in post #2 
              
              
                Hi, 
You need to give create_graph=True to the first call to grad if you plan on doing a backprop through it. 
Also I don’t think you want to give torch.zeros_like(xs) for the second grad. It should be the d_xs that is in the tensorflow version