一、问题
model.load_state_dict(state_dict)报错出现权重与模型不匹配
TypeError: valid_step() got an unexpected keyword argument 'update_num'
二、原因分析
保存模型时可能将该模型的BLEU等非模型权重的参数一同保存了(该参数用于比较得出checkpoint_best,应该是有被存储下来的)
三、解决方案
1)根据报错内容定位到代码的位置。
2)将 model.load_state_dict 的strict参数指定为false,即
model.load_state_dict(state_dict, strict=False)
四、参考博客