Thank you.
The code is
x = Variable(torch.randn(2, 2), requires_grad=True)
y = Variable(torch.randn(2, 2), requires_grad=True)
z = x ** 2 + y * x + y ** 2
...
grad_sum = 2 * x.grad + y.grad

I think grad_sum is ∂z/∂x, but is there no way to get Hessian directly? Thank you.