if you do x.requires_grad_() you can compute the derivative of y w.r.t. x using torch.autograd.grad. The derivative of x w.r.t. y is the inverse (1/x) by the inverse function theorem.
Of course, for 1d, approximation by finitite differences also works well.
Best regards
Thomas