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

3 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/”)