bert 사용시 일어났던 에러입니다.
File "/home/ubuntu/hot6/bh/sentence_transformers/models/Transformer.py", line 41, in __init__
self.auto_model.load_state_dict(torch.load(model_name_or_path+'/result.pt'))
File "/home/ubuntu/anaconda3/envs/hot6/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1052, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for BertModel:
Missing key(s) in state_dict: "embeddings.position_ids".
에러 해결 방법
model.load_state_dict를 할 때 strict하게 로딩해오지 않게 만들었습니다. 현재 가능한것만 체크해서 로딩해올수있는 option을 적용 시켰습니다.
에러에 나온 Transformer.py의 41번째 라인을 다음과 같이 수정했습니다.
# self.auto_model.load_state_dict(torch.load(model_name_or_path+'/result.pt'))
self.auto_model.load_state_dict(torch.load(model_name_or_path+'/result.pt'), strict=False)
수정 이후 정상적으로 model을 로드하는 것을 확인할 수 있었습니다.
댓글남기기