The optimizer just stored the references to the passed parameters and uses their .grad attribute to perform the update step.
It does not depend on the forward pass.
If you are able to generate the gradients in some way, the optimizer will just use them via their .grad.