Hi All,
I am relatively new to PyTorch, and I am trying to find the second derivative. However, it is always zero for some reason. Below is the code:
import torch
from torch.autograd import grad
dev = torch.device('cpu')
if torch.cuda.is_available():
    dev = torch.device('cuda')
    torch.set_default_tensor_type('torch.cuda.FloatTensor')
def Sec_Der(y,x):
        
    duxdxyz = grad(y[:, 0].unsqueeze(1), x, torch.ones(x.size()[0], 1, device=dev), create_graph=True, retain_graph=True)[0]
    duydxyz = grad(y[:, 1].unsqueeze(1), x, torch.ones(x.size()[0], 1, device=dev), create_graph=True, retain_graph=True)[0]
    duzdxyz = grad(y[:, 2].unsqueeze(1), x, torch.ones(x.size()[0], 1, device=dev), create_graph=True, retain_graph=True)[0]
        
    sec_der = grad(duzdxyz[:,0].unsqueeze(1), x, torch.ones(x.size()[0], 1), create_graph=True, retain_graph=True)[0]
    print(sec_der)
            
    return sec_der
x = 2*torch.rand((5,3))
x.requires_grad_(True)
x.retain_grad()
print(x)
y = x**3 + 2*x
print(y)
sec_der = Sec_Der(y,x)