Thomas_Poulsen:

The optimizer only seem to have knowledge about the model parameters and not the loss function.


This is correct! The optimizer does not necessarily need to know more about the model, just which parameters should be optimized using the gradient.
The gradient on the other side will be calculated during the loss.backward() call.
Since the loss was calculated using your input, the model, and the target, the backward call can use all this information to calculate the gradients.
Once these gradients are calculated, the optimizer just needs to update all parameters using its formula.