There are examples showing how to load the saved parameters of a model which is defined some place else.
How can I save an entire model in a single file and then load it later without a separate definition file? Is there a simple way to do this?
There are examples showing how to load the saved parameters of a model which is defined some place else.
How can I save an entire model in a single file and then load it later without a separate definition file? Is there a simple way to do this?
You could script/trace the model and export it. This wouldn’t need separate source files, but you would also be unable to manipulate the model easily.
I would not recommend to save the complete eager model via torch.save
, as it would still need to import the source files while reloading and can break easily.
You can save model via torch.save but there are issues like pickling gpu-located models and if you decide to tinker with some functions or classes model is based on you’ll encounter that this is not possible.
Saving through model.state_dict() is a much more stable approach