How to download model from huggingface?
Solution 1
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.
Solution 2
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?)
![marlon](https://lh3.googleusercontent.com/-swRsP46mbOM/AAAAAAAAAAI/AAAAAAAAAAA/AKF05nDXd35-wgFUunYOlpBSMnvFhD82kw/photo.jpg?sz=256)
marlon
Updated on June 12, 2022Comments
-
marlon about 2 years
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?
-
Shaida Muhammad over 2 yearsHow to download the models to local disk?
-
Shaida Muhammad over 2 yearsWhat if I want to download the model to a specific directory?
-
dennlinger over 2 yearsI think that merits its own question; in fact, I believe a possible answer is given here: stackoverflow.com/questions/63312859/…
-
rkechols over 2 yearsThis should be a comment on Jahjajaka's answer
-
S.Fan over 2 yearsi have no permission to make a comment under jahjajaka's answer, it requires 50 reputation, at least.