I tried computing gradients for implementation of Physics informed deep learning but I kept getting runtime error:

RuntimeError: One of the differentiated Tensors does not require grad.

I Have tried all possible solutions that I cam across online but not successfully resolved it. Below is the code for computing my first and second derivative.

def fwd_gradients(Y, x):

dummy = torch.ones_like(Y)

G = torch.autograd.grad(Y, x, grad_outputs=dummy, create_graph=True)[0]

Y_x = torch.autograd.grad(G, x, grad_outputs=torch.ones_like(G), create_graph=True)[0]

`return Y_x`