You could create a detached output of modelA and perform two forward passes in modelB.
I’m not sure, if you’ll gain any performance and I’m not sure if there is a better approach.
ya = modelA(x)
yb = ya.detach()
za = modelB(ya)
zb = modelB(yb)

lossA = criterionA(za, target)
lossB = criterionB(zb, target)