you can either inplace update parameter.data, this is invisible to autograd, or have something like an optimizer between your models, and pass gradients to model A by using autograd.grad (with grad_outputs parameter).