I have multiple losses: Say lossA, lossB
I have an option to configure which losses to pick for training.
My code for getting total loss is:

lossA = 0
lossB = 0
if config[‘use_lossA’]:
lossA = getLossA(input, output)
if config[‘use_lossB’]:
lossB = getLossB(input, output)
totalLoss = lossA  + lossB
if training:
//optimiser clear
totalLoss.backward()
//optimiser related step



totalLoss might not always be a variable, if both losses are disabled (which won’t generally happen).  But for safe keeping, what should be the best method to combine these losses?
Is total = Variable(lossA +lossB, requires_grad=True) okay?


Is it okay to do backward on total loss?