You can separately call backward on different losses (and would need to use loss1.backward(retain_graph=True) to keep the intermediate tensors for the second backward call if necessary), which would accumulate the gradients in all used parameters.