Saving and loading HF transformer model fine tuned with PL? #8893
-
I am fine-tuning hugging face transformer models, essentially exactly as shown in the following example found in the pytorch lightning docs: Where we instantiate the LightningModule doing something like this: class GLUETransformer(LightningModule):
def __init__(self, ... ):
super().__init__()
self.config = AutoConfig.from_pretrained(model_name_or_path, num_labels=num_labels)
self.model = AutoModelForSequenceClassification.from_pretrained(
model_name_or_path, config=self.config
) But I have been confused about how I should be saving and loading checkpoints. When saving checkpoints, should I be using or saving with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Dear @brijow, You should be using the second approach. An even better one would be to rely on Best, |
Beta Was this translation helpful? Give feedback.
-
@brijow Is there a way to unpack HF PL checkpoints into constituents (e.g. pytorch_model.bin, config.json, tokenizer.json etc.) usually found on the HF hub hosted models. Most importantly, how would I extract just the pytorch_model.bin from the PL checkpoint? |
Beta Was this translation helpful? Give feedback.
Dear @brijow,
You should be using the second approach. An even better one would be to rely on
ModelCheckpoint
to save the checkpoints and provideTrainer(resume_from_checkpoint=...)
for reloading all the states.Best,
T.C