TypeError: load_state_dict() got an unexpected keyword argument 'strict'

When I try to finetune a model, I set the ‘strict’ argument to load the state_dict, however, an error appears:

“TypeError: load_state_dict() got an unexpected keyword argument ‘strict’”

My pytorch is 1.2.0, can anyone help me with it?

Anyone can help, thanks?

The strict argument was already added to 1.2.0 so could you post a code snippet to reproduce this error?

Thank you.

Here is the code:
#torch.load(os.path.join(final_output_path, config.model_prefix + str(curr_iter) + ‘.pth’)), resume=True) # this works fine
torch.load(os.path.join(final_output_path, config.model_prefix + str(curr_iter) + ‘.pth’)),strict=False) #this doesnot work and give the error I list above.

Your code is unfortunately not executable and I cannot reproduce the error in PyTorch 1.2.0:

>>> import torch
>>> torch.__version__
>>> import torch.nn as nn
>>> model = nn.Linear(1, 1)
>>> model.load_state_dict(nn.Linear(1, 1).state_dict(), strict=False)
<All keys matched successfully>
>>> model.load_state_dict(nn.Linear(1, 1).state_dict(), strict=True)
<All keys matched successfully>