Lightning-Universe / lightning-transformers

Flexible components pairing 🤗 Transformers with :zap: Pytorch Lightning
https://lightning-transformers.readthedocs.io
Apache License 2.0
610 stars 77 forks source link

Loading and saving model files and checkpoints #167

Closed astoeckl closed 3 years ago

astoeckl commented 3 years ago

📚 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?

SeanNaren commented 3 years ago

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!

astoeckl commented 3 years ago

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.

SeanNaren commented 3 years ago

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[bot] commented 3 years ago

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.