How does loss.backward() relate to the appropriate parameters of the model?
I'm new in PyTorch and I'm having trouble understanding how loss knows to compute the gradients through loss.backward()? 

Sure, I understand that the parameters need to have requires_grad=True and I understand that it sets x.grad to the appropriate gradient only for the optimizer later to perform the gradient update.  

The optimizer is linked to the model parameters when it's instantiated, but the loss is never linked to the model.  

I've been going through this thread, but I don't think anyone answered it clearly and the person that started the thread seems to have the same issue as I do.  

What happens when I have two different networks with two different loss functions and two different optimizers. I will easily link the optimizers to each of the networks, but how will the loss functions know how to compute the gradients for each of their appropriate network if I never link them together?

Loss is itself a tensor which is derived from the parameters of the network. A graph is implicitly constructed where each new tensor, including loss, points back to the tensors which were involved with it's construction. When you apply loss.backward() pytorch follows the graph backwards and populates the .grad member of each tensor with the partial dervative of loss with respect to that tensor using the chain rule (i.e. backpropagation)
