I would have the same question as the guys before,
Can I get the final loss by output.sum()  and then do loss.backward()? (I saw some blog posts doing that way.)
Is that different from what you suggested here?