Lightning-Universe/lightning-transformers

Loading and saving model files and checkpoints

astoeckl opened this issue ยท 4 comments

๐Ÿ“š Documentation

Some questions on saving and loading model files:

How can I save a .ckpt file after each epoch of training?
How can I save a model file after training as PyTorch model file (.bin)?

How can I restart training from a saved .ckpt file?

Thanks for your issue and apologies on the late response! We'll add all this into the documentation to make it clear.

By default we save every epoch as per Lightning: https://pytorch-lightning.readthedocs.io/en/latest/common/weights_loading.html#weights-loading

I'm unsure what you mean by a PyTorch model file, could you give more details?

Restarting from a saved ckpt seems to not be supported currently, will look into integration for this!

I want to upload a fine-tuned model file to the Hugging face model hub. Therefore I need the PyTorch model file and not only the ckpt.

ah I see! so you want the output from model.save_pretrained. This hasn't been added yet but I can make this an option! to do so right now you might be able to load the model and save the internal model i.e for text classification:

task = TextClassificationTransformer.load_from_checkpoint('model.pt')
task.model.save_pretrained('huggingfacemodel.pt')
task.tokenizer.save_pretrained('huggingfacetokenizer.pt')
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.