can you also provide X and y?
anyways,
import torch
X=torch.tensor([1.,2.,3.],requires_grad=True)
y=X**3
z = torch.ones_like(y)
dy = torch.autograd.grad(y, X, grad_outputs=z, create_graph=True)[0]
print(dy)
d2y = torch.autograd.grad(dy, X, grad_outputs=z, create_graph=True)[0]
print(d2y)
The output of d2y is tensor([ 6., 12., 18.], grad_fn=< MulBackward0 >), which is just the second order derivative of y=x**3 isn’t it? y’’=6x