But the way you are describing in that snippet is perfectly good. You have a model with one input, one output. You can sum losses  and you are applying backward once. Then what’s the problem?
If you run a model() twice and you backpropagate you will backpropagate the average gradients. If you stack in a single batch both inputs and backpropagate you will backpropagate average error. As @zeakey said, if you run backward without zero grad you will accumulate gradients.