calculate a mean/sum of both separate losses and call backward() on it. Autograd should handle the rest for you since only the parameters which are involved in the forward pass will be updated for each part of the loss.