How to download model from huggingface?

Viewed 24316
https://huggingface.co/models

For example, I want to download 'bert-base-uncased', but cann't find a 'Download' link. Please help. Or is it not downloadable?

3 Answers

Accepted answer is good, but writing code to download model is not always convenient. It seems git works fine with getting models from huggingface. Here is an example:

git lfs clone https://huggingface.co/sberbank-ai/ruT5-base

where 'lfs' stays for 'large file storage'. Technically this command is deprecated and simple 'git clone' should work, but then you need to setup filters to not skip large files (How do I clone a repository that includes Git LFS files?)

The models are automatically cached locally when you first use it. So, to download a model, all you have to do is run the code that is provided in the model card (I chose the corresponding model card for bert-base-uncased).

At the top right of the page you can find a button called "Use in Transformers", which even gives you the sample code, showing you how to use it in Python. Again, for bert-base-uncased, this gives you the following code snippet:

from transformers import AutoTokenizer, AutoModelForMaskedLM
  
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForMaskedLM.from_pretrained("bert-base-uncased")

When you run this code for the first time, you will see a download bar appear on screen. See this post (disclaimer: I gave one of the answers) if you want to find the actual folder where Huggingface stores their models.

I aggre with Jahjajaka's answer. In addition, you can find the git url by clicking the button called "Use in Transformers", shown in the picture. clicking the button called "Use in Transformers"

Related