# Download models for local loading

**URL:** <https://discuss.huggingface.co/t/download-models-for-local-loading/1963>\
**Category:** Beginners\
**Created:** [November 10, 2020, 2:04pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963 "2020-11-10T14:04:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![markemb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/markemb/32/560_2.png) [@markemb](https://discuss.huggingface.co/u/markemb)\
**Post date:** [November 10, 2020, 2:04pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/1 "2020-11-10T14:04:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thomwolf](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thomwolf/32/2198_2.png) [@thomwolf](https://discuss.huggingface.co/u/thomwolf)\
**Post date:** [November 12, 2020, 1:01pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/2 "2020-11-12T13:01:06Z")

</div>

You can now (since the switch to git models explained here: [[Announcement] Model Versioning: Upcoming changes to the model hub](https://discuss.huggingface.co/t/announcement-model-versioning-upcoming-changes-to-the-model-hub/1914/27)) just git clone a model to your laptop and make `from_pretrained` point to it:

```python
# 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:

```python
# 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

---

<div class="post-metadata">

**Author:** ![ZhaoweiWang](https://avatars.discourse-cdn.com/v4/letter/z/f9ae1b/32.png) [@ZhaoweiWang](https://discuss.huggingface.co/u/ZhaoweiWang)\
**Post date:** [March 26, 2022, 8:03am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/3 "2022-03-26T08:03:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BennB](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@BennB](https://discuss.huggingface.co/u/BennB)\
**Post date:** [October 14, 2022, 4:02am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/4 "2022-10-14T04:02:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edmond](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@edmond](https://discuss.huggingface.co/u/edmond)\
**Post date:** [December 15, 2022, 9:22am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/6 "2022-12-15T09:22:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Highdie84](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@Highdie84](https://discuss.huggingface.co/u/Highdie84)\
**Post date:** [December 17, 2022, 7:39am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/7 "2022-12-17T07:39:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AayushShah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/aayushshah/32/22671_2.png) [@AayushShah](https://discuss.huggingface.co/u/AayushShah)\
**Post date:** [March 27, 2023, 5:44am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/8 "2023-03-27T05:44:28Z")

</div>

> [@thomwolf](#):
>
> ```auto
> # Then
> !git clone https://huggingface.co/ORGANIZATION_OR_USER/MODEL_NAME
> 
> ```

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?

---

<div class="post-metadata">

**Author:** ![sebrahimi](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@sebrahimi](https://discuss.huggingface.co/u/sebrahimi)\
**Post date:** [June 22, 2023, 9:34am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/9 "2023-06-22T09:34:08Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![czh5372](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@czh5372](https://discuss.huggingface.co/u/czh5372)\
**Post date:** [October 19, 2023, 3:04pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/10 "2023-10-19T15:04:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bmaxi2000](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bmaxi2000](https://discuss.huggingface.co/u/bmaxi2000)\
**Post date:** [January 19, 2024, 12:38pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/11 "2024-01-19T12:38:53Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Iamexperimenting](https://avatars.discourse-cdn.com/v4/letter/i/839c29/32.png) [@Iamexperimenting](https://discuss.huggingface.co/u/Iamexperimenting)\
**Post date:** [February 25, 2024, 10:22pm UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/12 "2024-02-25T22:22:04Z")

</div>

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

```auto
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")

```

---

<div class="post-metadata">

**Author:** ![fasterinnerlooper](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/fasterinnerlooper/32/28824_2.png) [@fasterinnerlooper](https://discuss.huggingface.co/u/fasterinnerlooper)\
**Post date:** [March 18, 2024, 1:28am UTC](https://discuss.huggingface.co/t/download-models-for-local-loading/1963/13 "2024-03-18T01:28:52Z")

</div>

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.
