reppy4620 / Dialog

A PyTorch Implementation of japanese chatbot using BERT and Transformer's decoder
MIT License
72 stars 29 forks source link

Missing key(s) in state_dict: "encoder.embeddings.position_ids" #15

Closed CZFuChason closed 3 years ago

CZFuChason commented 3 years ago

I was trying to test the pretrained model. But an error popped out.

the version of my packages: transformers: 3.3.1 torch: 1.3.1

Can I ask the exact version of the transformer and torch you used for this project?

Thank you so much in advance.


RuntimeError Traceback (most recent call last)

in 3 tokenizer = Tokenizer.from_pretrained(Config.model_name) 4 model = build_model(Config).to(device) ----> 5 model.load_state_dict(state_dict['model']) 6 model.eval() 7 model.freeze() ~/anaconda3/envs/myenv/lib/python3.7/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict) 837 if len(error_msgs) > 0: 838 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( --> 839 self.__class__.__name__, "\n\t".join(error_msgs))) 840 return _IncompatibleKeys(missing_keys, unexpected_keys) 841 RuntimeError: Error(s) in loading state_dict for EncoderDecoder: Missing key(s) in state_dict: "encoder.embeddings.position_ids".
reppy4620 commented 3 years ago

I trained the pre-trained model with transformers==2.3.0, so version of the package may cause this error. If you want more information, pls refer to #13. I reproduced evaluation procedure.

BTW, version of transformers and PyTorch is

>>> import torch
>>> torch.__version__
'1.6.0'
>>> import transformers
>>> transformers.__version__
'2.3.0'