How can I save best model state_dict during training?

Hi,

The .state_dict() method does not copy the parameters but returns a view into the ones in the model.
So if you want to get an independent version (that will not be updated inplace by training), you need to deepcopy it: best_model_state_dict = copy.deepcopy(model.state_dict())

1 Like