Download models for local loading

Hi,

Because of some dastardly security block, I’m unable to download a model (specifically distilbert-base-uncased) through my IDE. Specifically, I’m using simpletransformers (built on top of huggingface, or at least uses its models). I tried the from_pretrained method when using huggingface directly, also, but the error is the same:

OSError: Can’t load weights for ‘distilbert-base-uncased’

From where can I download this pretrained model so that I can load it locally?

Thanks very much,

Mark

You can now (since the switch to git models explained here: [Announcement] Model Versioning: Upcoming changes to the model hub) just git clone a model to your laptop and make from_pretrained point to it:

# In a google colab install git-lfs
!sudo apt-get install git-lfs
!git lfs install

# Then
!git clone https://huggingface.co/ORGANIZATION_OR_USER/MODEL_NAME

from transformers import AutoModel

model = AutoModel.from_pretrained('./MODEL_NAME')

For instance:

# In a google colab install git-lfs
!sudo apt-get install git-lfs
!git lfs install

# Then
!git clone https://huggingface.co/facebook/bart-base

from transformers import AutoModel

model = AutoModel.from_pretrained('./bart-base')

cc @julien-c for confirmation

9 Likes

Hi thomwolf,
But how to download only the pytorch model? I found that git cone also downloads tensorflows models, which is useless and time-comsuing for me.

This works for me

from sentence_transformers import SentenceTransformer

# download pretrained
model = SentenceTransformer(‘bert-base-nli-mean-tokens’)

# save to local directory
model.save(“./model/”)

model = None

# load from local file
model = SentenceTransformer(“./model/”)

5 Likes

Didnt work for me with “dandelin/vilt-b32-finetuned-vqa”. Thomwolf’s solution did though.

So I downloaded stable diffusion. I want to add new models, but I don’t know how to download them, at all.

How can I define the revision=float16 here? Because I am trying to download the GPT-J6B model and it is around 24GB. But with revision=float16 I can get it for 12GB.

How to download the 12GB version?

I have followed the same steps to download mpt-7B-instruct, but when loading the model I get the following error:

Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack

Any idea why? I have all the files from the repo, but I feel from_pretrained method is assuming I’m loading a different type of model and is looking for a different weights file.

2 Likes

Were you able to fix this? I’m encountering similar issues

I encountered the same issue because i saved the file in the wrong directory.

Saving it under “C:/users/USER/.cache/huggingface/hub/” solved the issue for me!

how can I download the models from huggingface directly in my specified local machine directroy rather it downloads automatically into cached location.

model_id =  "meta-llama/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id,
                                             device_map="auto")
1 Like

The model_id parameter can take a folder location, so if you find out where the model has been downloaded to, you can put that in instead of the model_id.

So if your model was downloaded to c:/llama-chat you would change the line to:
model = AutoModelForCausalLM.from_pretrained("c:/llama-chat", device_map="auto")

I hope that helps.