Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting issue while loading model #1

Closed
vijender412 opened this issue Mar 9, 2020 · 6 comments
Closed

Getting issue while loading model #1

vijender412 opened this issue Mar 9, 2020 · 6 comments

Comments

@vijender412
Copy link

Getting below issue while loading the model in local system. Model was trained on colab.

Traceback (most recent call last):
  File "app.py", line 74, in <module>
    MODEL.load_state_dict(torch.load(config.MODEL_PATH, map_location=torch.device('cpu'))) #New created
  File "C:\Users\Vijender\Downloads\bert_sentiment\lib\site-packages\torch\nn\modules\module.py", line 830, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for BERTBaseUncased:
        Missing key(s) in state_dict: "bert.embeddings.word_embeddings.weight", "bert.embeddings.position_embeddings.weight", "bert.embeddings.token_type_embeddings.weight", "bert.embeddings.LayerNorm.weight", "bert.embeddings.LayerNorm.bias", "bert.encoder.layer.0.attention.self.query.weight", "bert.encoder.layer.0.attention.self.query.bias",
@abhishekkrthakur
Copy link
Owner

did you use data parallel to train the model?

@vijender412
Copy link
Author

@abhishekkrthakur Yes used data parallel while training

@abhishekkrthakur
Copy link
Owner

does your bert_base_path has bert base uncased model files?

@vijender412
Copy link
Author

@abhishekkrthakur Fixed the issue was with data parallel. I local i was not making use of "MODEL = nn.DataParallel(MODEL)". Now working with this. Can you help me understand the use of DataParallel and if it does require after training also?
Thanks for quick replying. Good to close the issue

@abhishekkrthakur
Copy link
Owner

DataParallel is used only when you have multiple GPUs during training.
If you used it in training, you have to use in inference but there are other ways too.

Closing this issue for now. :)

@nipunsadvilkar
Copy link

@abhishekkrthakur : Can you give any leads on how to load DataParallel GPU model on CPU?
As per pytorch docs tried following but still raises above RuntimeError

device = torch.device('cpu')
model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH, map_location=device))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants