is there a reason why the standard way doesn’t work for you:

  
      stackoverflow.com
  
  
      
    
  

  Best way to save a trained model in PyTorch? 20



  python, serialization, deep-learning, pytorch



  asked by
  
  
    Wasi Ahmad
  
  on 07:06PM - 09 Mar 17 UTC


  
  
    
    
  
  



see answer above:
ref: https://github.com/pytorch/pytorch/blob/761d6799beb3afa03657a71776412a2171ee7533/docs/source/notes/serialization.rst 9

Recommended approach for saving a model
There are two main approaches for serializing and restoring a model.
The first (recommended) saves and loads only the model parameters:
torch.save(the_model.state_dict(), PATH)

Then later:
the_model = TheModelClass(*args, **kwargs)
the_model.load_state_dict(torch.load(PATH))

The second saves and loads the entire model:
torch.save(the_model, PATH)

Then later:
the_model = torch.load(PATH)

However in this case, the serialized data is bound to the specific classes
and the exact directory structure used, so it can break in various ways when
used in other projects, or after some serious refactors.