How to find differential in Pytorch?

I have a model with u(x,t) and i am training my model with x[100,1] and t[100,1] as tensor [100,2] to predict the u(x,t). I need to find the partial derivative of u wrt to t and double differential wrt to x to solve the PDE. I am stuck how to go for this part. I tried this piece of code. **’’’ u_pred = pn(y) f_pred = differential(u_pred,x,t) def differential(u_pred,x,t): f = [] for i in range(len(x)+1):

    dt = torch.autograd.grad(u_pred[i], t[i],allow_unused=True)[0]
    dx = torch.autograd.grad(u_pred[i], x[i], create_graph=True)[0]
    ddx = torch.autograd.grad(dx, x)[0]
    f_i = ddx - dt
    f = np.append(f,f_i)
return f

‘’’** Please help me.