Thank you for your answer!
Just one quick question, why do you set the lossB backward to be (retain_graph=True)? Does this option save the gradient and the other gradient will accumulate on top of it?