Solved by albanD in post #2 
              
              
                Hi, 
You want to do e.backward(create_graph=True) that will make sure the backward pass run in a differentiable manner. 
Also creating a .grad that requires grad is usually not recommended because when you do l.backward() here, you will accumulate in the same p.grad which can easily become confusing…