Open VictorYang097 opened 2 years ago
Maybe I have solved this problem. Just modify load() as follows:
def load(model, file, device=None, strict=True): if device is None: device = 'cpu' elif isinstance(device, int): device = torch.device('cuda', device) assert os.path.isfile(file) state = torch.load(file, map_location=device) **# if set(state.keys()) == {'model', 'opt'}:
state = state['model']**
state = state['model'] model.load_state_dict(state, strict=strict) return model
@LualuOntheSea I have also encountered the same issue with loading the language model (I faced the missing key problem when testing the language model's performance on Wikitext103 separately). Your explanation is very helpful, and you have adopted a similar approach that effectively resolved my issue.
Thanks for your great work! when I created an instance of BCNLanguage and let it load pretrain-language-model.pth, an error emerged:
relevant functions and files are as follows: main()
get_model()
load()
inf_language_model.yaml
input.txt
I would appreciate it if you could help me, thanks again. @FangShancheng