Can’t edit but following what they did I in fact solved the problem (sorry to those who tried).
def fwd_gradients_0(self, U, x):
        z = torch.ones(U.shape).to(device).requires_grad_(True)
        g = autograd.grad(U, x, grad_outputs=z, create_graph=True)[0]
        return autograd.grad(g, z, grad_outputs=torch.ones(g.shape).to(device), create_graph=True)[0]

Can’t say I understand this though. What does taking the derivative w.r.t. the previous grad_output function z mean?