Problem with push_to_hub

Hello everyone. I’m trying to upload my fine-tuned GPT-2 Model to Model Hub.
When I try to use the uploading function push_to_hub I get the following error:
AttributeError: 'GPT2Model' object has no attribute 'push_to_hub'
In the documentation it says that I can push the model with this function.
Can anybody help please?

You need to update your Transformers library to the latest version.

1 Like

Thank you so much. I have another question. Is there a way to push a model to the model hub after training without saving the new model to the disk with trainer.save_model() ? Would Trainer.push_to_hub do that or is it for pushing just the trainer instance? If yes how can I give my authentication token as a parameter to trainer.push_to_hub method?

You can set your token in the training arguments inside push_to_hub_token.
The Trainer will save the model on disk with save_model, as you need to save it to the repo of the model you will be using before it can git push it to the model hub.

1 Like

So you mean I should set push_to_hub_token in Training arguments. Then train the model and save it using trainer.save_model() function. Then I should just recreate it from the saved file using

fine_tuned_model = AutoModel.from_pretrained("./file_path")

And then finally push it to hub using

fine_tuned_model.push_to_hub("Name of model")

No, you should just do trainer.push_to_hub() once you’re done with training. Look at any of the notebooks examples for more context, or the push to hub video.


Thank you very much. I was able to solve my problem after I saw the training argument “push_to_hub_model_id” and transformers-cli from your example notebook “Train a language model”.

1 Like