Yes.
So maybe it’s simpler to consider the autograd.grad(loss, w) API first:
Given the output and input of a function, it will return the gradient dloss/dw to you.
In the context of torch.nn, to avoid the user the burden of moving these gradients around, we use loss.backward() that will populate a .grad field on the leafs (w here). So after loss.backward(), you can access w.grad() to get dloss/dw.
This .grad() field will then be used by the optimizer when it performs its step.