# Is my model loaded correctly? unexpected\_keys

**URL:** <https://discuss.pytorch.org/t/is-my-model-loaded-correctly-unexpected-keys/80600>\
**Category:** Uncategorized\
**Created:** [May 10, 2020, 6:47pm UTC](https://discuss.pytorch.org/t/is-my-model-loaded-correctly-unexpected-keys/80600 "2020-05-10T18:47:26Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jmandivarapu1](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jmandivarapu1/32/3544_2.png) [@jmandivarapu1](https://discuss.pytorch.org/u/jmandivarapu1)\
**Post date:** [May 10, 2020, 11:45pm UTC](https://discuss.pytorch.org/t/is-my-model-loaded-correctly-unexpected-keys/80600/7 "2020-05-10T23:45:52Z")

</div>

Please refer to these below links which are similar

> [@\[solved\] KeyError: 'unexpected key "module.encoder.embedding.weight" in state\_dict'](https://discuss.pytorch.org/t/solved-keyerror-unexpected-key-module-encoder-embedding-weight-in-state-dict/1686):
>
> 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](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](https://discuss.pytorch.org/t/missing-keys-unexpected-keys-in-state-dict-when-loading-self-trained-model/22379/12):
>
> 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 …

---

_[View the full topic](https://discuss.pytorch.org/t/is-my-model-loaded-correctly-unexpected-keys/80600)._
