subedir:

Is this the same as setting modelB to eval mode?


No, setting the model to .eval() will change the behavior of some layers (e.g. dropout will be disabled and batchnorm layers will use their running stats) and will not change the behavior of the gradient calculation.



 subedir:

If I want to update the weights of both the models, can I achieve this by creating two optimizers?


Yes, that works.