Are there any functional differences between the two pieces of code?

dydx = torch.autograd.grad(outputs=y,
                           inputs=x,
                           grad_outputs=weight,
                           retain_graph=True,
                           create_graph=True,
                           only_inputs=True)

**and**
y.backward()

the both code is to compute the grad. When use optimizer.step() after executing y.backward(), value of x will be updated, but if i use  torch.autograd.grad instead of y.backward(), value of x will not be updated. Is it right?