问题:
解决:
- 添加strict=False,允许加载过程中出现不匹配的键。但请注意,仍然需要确保模型中的主要参数能够正确加载,以确保模型的有效性。
model.load_state_dict(state_dict)
# 改为:
model.load_state_dict(state_dict, strict=False)
- #去除关键字”model"
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in params.items():
if not k.endswith('position_ids'):
new_state_dict[k] = v
model.load_state_dict(new_state_dict)