Can't load state_dict

I have trained a network,
saving code is next:

model_to_save = model.module if hasattr(model, 'module') else model  # Only save the model it-self
output_model_file = args.output_dir / "pytorch_model.bin"
torch.save(model_to_save.state_dict(), str(output_model_file))

Then I try to load it and receive error:

>>> model.load_state_dict(torch.load('./finetuned_lm/pytorch_model.bin'))
IncompatibleKeys(missing_keys=[], unexpected_keys=[])

These keys are empty, but still there is an error.
What can be a reason to this?

The IncompatibleKeys message is just to show you that there were no missing or unexpected keys, thus the loading should be fine.

4 Likes

Wow! Thank you! Who knows, how much time I would spend investigating this :neutral_face:

1 Like

The message seems to be a bit confusing and will most likely be improved. We are tracking this issue here.

Please revise the message as it really confused me for some time debugging. It looks like an error message. :sweat_smile: