“No inf checks were recorded for this optimizer.“ AssertionError:错误解决

问题1

主要是深拷贝会破坏一些模型的特性,模型被

self.best_model = copy.deepcopy(model).cpu()

保存之后,保存就只能保存模型的参数了,而不能保存全部的模型

torch.save(self.best_model.state_dict(),'...')

再调用的时候定义完模型直接调用参数

model.load_state_dict(torch.load('model.pth'))

问题2

change the

optimizer = torch.optim.AdamW(model.parameters(),lr=1e-5)
deberta = DebertaV2Model.from_pretrained("/home/xiaoguzai/模型/deberta-v3-large")
model = ClassificationModel(deberta)

to

deberta = DebertaV2Model.from_pretrained("/home/xiaoguzai/模型/deberta-v3-large")
model = ClassificationModel(deberta)
optimizer = torch.optim.AdamW(model.parameters(),lr=1e-5)

Because at the first one,

original AdamW(model.parameters(),lr=1e-5) 

refer to the model below,
but at the second one,

AdamW(model.parameters(),lr=1e-5)

refer to the real model


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部