[solved]Error with copy.deepcopy()

I want to return model after train, so I copy it first:

best_model = copy.deepcopy(model)

but I got error:

RuntimeError: Only Variables created explicitly by the user (graph leaves) support the deepcopy protocol at the moment

I want to know why I got this error, and how can I solve it.

2 Likes

I got the same error,you can try it : best_model = copy.deepcopy(model.state_dict())
maybe help.:slight_smile:

Can you be more specific how the answer given solves your problem? Because it certainly does not solve any of my problems. Don’t you still need to load those parameters to an actual model later on? How did you do that without deepcopy?

Also, can you provide a self contained part of your code that is giving you this issue? it’s impossible to know what you’re doing with so little code provided.

Also, you don’t need to manually harcode [solved] in the title, there is a button for selecting the answer that solves your question man.