Yes, both models will be updated, since lossB is calculated using both models.
To make sure it’s right, you could also have a look at the gradients after the backward call:
print(modelA.weight.grad)
print(modelB.weight.grad)

You’ll see that both models got valid gradients.
Also, retain_graph=True is not needed anymore, because you are not calling backward again.
The intermediate tensors might thus be freed.