Each operation is tracked by Autograd, if parameters are involved with require gradients.
The output of such operations get a .grad_fn attribute, which points to the backward function for the last operation:
x = torch.randn(1, 1)
w = nn.Parameter(torch.randn(1, 1))

output = x * w
print(output)
> tensor([[2.5096]], grad_fn=<MulBackward0>)

The backward call uses these grad_fns to calculate the gradient and store it in the .grad attribute of the parameters:
output.backward()
print(w.grad)
> tensor([[1.1757]])