jinxin_wang:

d2y = torch.autograd.grad(dy, X, grad_outputs=z, create_graph=False)[0]
print(d2y)


Oh, dude, your job just now was great.
Maybe I did not express it clearly enough that you did not understand the point of my question. After my manual verification, the solution of the first-order derivative is no problem.
But an unknown error occurred when d2y = torch.autograd.grad(dy, X, grad_outputs=z, create_graph=False)[0]  print(d2y) calculated the second derivative. You can manually calculate the second derivative of this implementation process. The correct result should be  tensor([[-0.0409, -0.0909],         [-0.0909,  0.0000]])  the output of the above program is indeed  tensor([[-0.0818, -0.1726],         [-0.1817, -0.1817]])