Hello @Ozan,
These two approaches did the same thing and they will get the same results, the first way is neater. Because the backward perform accumulation of gradient w.r.t. loss of each task, you don’t need worry the gradients will be corrupted.
Thus, both way is correct in your use case.
(If I misunderstand it, correct me please.)