I saw someone’s code that went like this while operating on the same model…
loss_one = criterion(...)
loss_one.backward()
loss_two = criterion(...)
loss_two.backward()
optimizer.step()

My feeling would be to code it like this…
loss = criterion(...) + criterion(...)
loss.backward()
optimizer.step()

I cannot explain to myself if there is any difference in these two flows…what is the truth?