ptrblck:

To properly load the model, create the model instance first and load the state_dict afterwards:


Thank you for your reply, I rewritten the code according to your prompt:
model=BertForMaskedLM.from_pretrained(model_path)
model.load_state_dict(torch.load(model_path))

And now it prompts a new error:
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x80 in position 0: invalid start byte
What is the reason for this problem, I am a beginner in deep learning, thank you for your reply！