DeployU
Interviews / AI & MLOps / How do you share a model on the Hugging Face Hub?

How do you share a model on the Hugging Face Hub?

practical Ecosystem Interactive Quiz Code Examples

The Scenario

You are a research scientist at a university. You have just finished training a new state-of-the-art model for image classification. You want to share the model with the research community so that others can build on your work.

You need to upload the model to the Hugging Face Hub in a way that is professional, responsible, and easy for others to use.

The Challenge

What is your strategy for sharing this model on the Hub? What are the key steps you would take, from creating a repository to writing a model card? What are some of the best practices you would follow to ensure that your model is well-received by the community?

Wrong Approach

A junior engineer might just upload the model files to a new repository without any documentation or context. They might not be aware of the importance of creating a good model card, adding a license, or providing example usage.

Right Approach

A senior engineer would understand that sharing a model is about more than just uploading the files. They would follow a systematic process to ensure that the model is well-documented, easy to use, and responsibly shared. They would also take the time to engage with the community and answer any questions that people have about the model.

Step 1: Create a Repository

The first step is to create a new repository on the Hub for your model.

huggingface-cli repo create my-awesome-model

This will create a new repository on the Hub and clone it to your local machine.

Step 2: Upload the Model

The next step is to upload the model files to the repository.

MethodDescriptionProsCons
push_to_hubA method on all models and tokenizers that allows you to push them to the Hub with a single line of code.Very easy to use.Less flexible than using git.
huggingface-cliA command-line tool that allows you to interact with the Hub.Can be used to upload any type of file, not just models and tokenizers.Requires you to use the command line.
gitThe standard way to interact with Git repositories.Very flexible, allows you to have full control over the upload process.Can be more complex to use than the other methods.

We will use git to upload the model, because it gives us the most control over the process.

# Move the model files to the repository
mv /path/to/my-model/* my-awesome-model/

# Push the files to the Hub
cd my-awesome-model
git add .
git commit -m "Add my awesome model"
git push

Step 3: Create a Model Card

The model card is the most important part of sharing a model on the Hub. It should include all the information that people need to understand and use your model.

See the “What are model cards and why are they important for responsible AI?” question for more information on how to create a good model card.

Step 4: Add a License

It is important to add a license to your model so that others know how they are allowed to use it. You can add a license by creating a LICENSE file in the root of your repository.

Step 5: Engage with the Community

The final step is to engage with the community and answer any questions that people have about your model. You can do this by:

  • Responding to questions and comments on the Hub.
  • Creating a Space for your model so that people can try it out in their browser.
  • Writing a blog post or a paper about your model.

Practice Question

You are sharing a model that you have trained on a proprietary dataset. Which of the following should you do?