[Solved] RuntimeError: Error(s) in loading state_dict for BertForTokenClassification

RuntimeError: Error(s) in loading state_dict for BertForTokenClassification

problem:
RuntimeError: Error(s) in loading state_dict for BertForTokenClassification:size mismatch for bert.embeddings.word_embeddings.weight: copying a param with shape torch.Size([21128, 768]) from checkpoint, the shape in current model is torch.Size([119547, 768]).
Solution:
The parameters of torch are not consistent with the mod
My original code was

model = AutoModelForTokenClassification.from_pretrained("bert-base-multilingual-cased", num_labels=len(label_names))

Just reinstall pytorch

conda install pytorch==1.7.1

Read More: