fastnlp / fastNLP

fastNLP: A Modularized and Extensible NLP Framework. Currently still in incubation.
https://gitee.com/fastnlp/fastNLP
Apache License 2.0
3.07k stars 448 forks source link

checkpoint 无法加载 #370

Open sataliulan opened 3 years ago

sataliulan commented 3 years ago

我使用BiLSTMCRF做ner任务,embedding为cn-Bert-base-wwm, 模型开始训练时,Trainer设置save_path 为"./save_model" ,训练完成后生成文件:best_BiLSTMCRF_f_2021-07-06-12-14-12-018221; 随后我想加载现有训练结果继续训练,遂编写callback 为CheckPointCallback(save_path='./save_model/best_BiLSTMCRF_f_2021-07-06-12-14-12-018221') 并在trainer中设置callbacks=[callback]; 在训练报错:/fastNLP/core/callback.py line 949 in on_train_begin, model.load_statea-dict(states['model']) TypeError: 'BiLSTMCRF' object is not subscriptable.

不知道是哪里配置出了问题,请排查一下

yhcc commented 3 years ago

CheckPointCallback不是实现将自己存储的model进行继续训练的,CheckPointCallback是需要在第一次运行的时候就加入到callback中,假设训练过程意外退出,可以直接重新run整个代码,CheckPointCallback会去加载保存的Checkpointer。在你的场景下,你可以直接load这个best_BiLSTMCRF_f_2021-07-06-12-14-12-018221模型,然后放入到trainer中继续train就好了。