在本地保存固定模型
我试图了解如何在本地保存微调的模型,而不是将其推向集线器。
我已经完成了一些教程,在微调的最后一步,模型正在运行 Trainer.train()
。然后,指令通常是: trainer.push_to_hub
,
但是如果我不想推到轮毂怎么办?我想在本地保存模型,然后可以将其从自己的计算机加载到将来的任务中,以便我可以进行推断而无需重新调整。
我该怎么做?
例如:最初从拥抱面上加载模型:
model = AutoModelForSequenceClassification.from_pretrained("bert-base-cased", num_labels=5)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=small_train_dataset,
eval_dataset=small_eval_dataset,
compute_metrics=compute_metrics,
)
trainer.train()
以某种方式保存本地训练有素的新型号,以便下次我可以通过
model = 'some local directory where model and configs (?) got saved'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用:
或者,或者,或者,方法:
然后,在重新加载模型时,将保存的路径指定为:
You can use the
save_model
method:Or alternatively, the
save_pretrained
method:Then, when reloading your model, specify the path you saved to:
您可以使用
You can do it using