Hello I am getting serious problem when doing this in pytorch. Suppose that Ihave CNN to calculate 3 kind of classification, let we said out1, out2, out3. I am using same criterion for classification. Then in training phase I write like this.

loss1 = criterion(outpute, out1)

loss2 = criterion(outputh, out2)

loss3 = criterion(outputm, out3)

loss = loss1 + loss2 + loss3

loss.backward()

optimizer.step()

Is it true to do that or should I do like this?

loss1 = criterion(outpute, out1)

loss2 = criterion(outputh, out2)

loss3 = criterion(outputm, out3)

loss1.backward()

loss2.backward()

loss3.backward()

optimizer.step()

or like this?

loss1 = criterion(outpute, out1)

loss2 = criterion(outputh, out2)

loss3 = criterion(outputm, out3)

loss = loss1 + loss2 + loss3

loss1.backward()

loss2.backward()

loss3.backward()

loss.backward()

optimizer.step()

-Thank you-