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

Cannot load any Pre-Trained Model #15

Closed
Mahyar-Ali opened this issue Sep 27, 2020 · 2 comments
Closed

Cannot load any Pre-Trained Model #15

Mahyar-Ali opened this issue Sep 27, 2020 · 2 comments

Comments

@Mahyar-Ali
Copy link

Mahyar-Ali commented Sep 27, 2020

I created an extractive summarizer using the "extractive" module and the parser(almost all default values).
from extractive import ExtractiveSummarizer
summarizer = ExtractiveSummarizer
args = build_parser()
model = summarizer(hparams=args)
checkpoint = torch.load( "epoch=3.ckpt", map_location=lambda storage, loc: storage )
model.load_state_dict(checkpoint["state_dict"])
When I try to load a state dict in a model, it raises an error, "RuntimeError: Error(s) in loading state_dict for ExtractiveSummarizer:
Missing key(s) in state_dict: "word_embedding_model.embeddings.position_ids"."

Sometimes with the missing keys error, it produces IncompatibleKeys and shape mismatch error.

Note: The model checkpoint file is of the same model name provided in the parser.
for build_parser, I just extracted all the arguments from the main.py file and placed it in a function.

It would be nice if you can document the necessary steps to load a pretrained model in the official documentation. As of now, I can't find any.
Thanks!

@HHousen
Copy link
Owner

HHousen commented Sep 27, 2020

I believe this is a duplicate of #12. Essentially, it is a problem with the update from 3.0.2 to 3.1.0 of huggingface/transformers. The problem is being discussed at huggingface/transformers#6882. While they work on a fix, you can install the previous version of huggingface/transformers by running pip install -U transformers==3.0.2.

The steps to load a pretrained model are in the documentation. Please see https://transformersum.readthedocs.io/en/latest/general/getting-started.html#programmatically. Simply import the ExtractiveSummarizer or AbstractiveSummarizer pytorch_lightning module and call the load_from_checkpoint() function with the path to the model checkpoint file.

@Mahyar-Ali
Copy link
Author

Thanks....!

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

2 participants