What you want to do is quite similar to GoogleLeNet, where additional loss will be directly back-propagated to intermediate layers. I think there is no need to call backward() for loss_A, loss_B separately. You can try this one:
optimizer_A.zero_grad()
optimizer_B.zero_grad()
loss_A = ...
loss_B = ...
loss = loss_A + loss_B
loss.backward()
optimizer_A.step()
optimizer_B.step()

Also, this problem may be helpful to you (https://stackoverflow.com/questions/53994625/how-can-i-process-multi-loss-in-pytorch 10)