Please refer to these below links which are similar

  
    
    
    [solved] KeyError: 'unexpected key "module.encoder.embedding.weight" in state_dict' 
  
  
    I am getting the following error while trying to load a saved model. 
KeyError: 'unexpected key "module.encoder.embedding.weight" in state_dict' 
This is the function I am using to load a saved model. (as suggested in http://pytorch.org/docs/notes/serialization.html#recommend-saving-models) 
def load_model_states(model, tag):
    """Load a previously saved model states."""
    filename = os.path.join(args.save_path, tag)
    with open(filename, 'rb') as f:
        model.load_state_dict(torch.loa…
  



  
    
    
    Missing keys & unexpected keys in state_dict when loading self trained model vision
  
  
    I use  torch.save(model.state_dict(), 'file_name.pt')  to save the model. If I don’t use  nn.DataParallel  to save model, I also don’t need it when I load it, right? 
If so, when I  torch.save(model.state_dict(), 'mymodel.pt')  in one py file during training, I try to load it in a new file with  model.load_state_dict(torch.load('mymodel.pt)) , it gives me the error 
RuntimeError: Error(s) in loading state_dict for model: Missing key(s) in state_dict: "l1.W", "l1.b", "l2.W", "l2.b". 
My model is …