About copy a model~

I want to copy a model and using the following code:

model_b = copy.deepcopy(model_a)

However, this operation only copy the weights/bias of the model_a, when model_a includes dropout, there is no guarantee that the outputs of model_a and model_b are exactly the same, and I want to know if pytorch has an operation that can be copied to the dropout of model a at the same time.

The dropout operation uses the global pseudo-random number generator to sample the mask, which won’t be stored in the deepcopy command.
If you need to “restore” the same behavior, you might need to seed the code and make sure the same order of operations is used in the PRNG.