# Load a cached custom model in offline mode

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-a-cached-custom-model-in-offline-mode%2F23190%3E%5C
**Category:** 🤗Transformers\
**Created:** [September 15, 2022, 3:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-a-cached-custom-model-in-offline-mode%2F23190 "2022-09-15T15:19:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johngiorgi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/johngiorgi/32/31960_2.png) [@johngiorgi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjohngiorgi)%5C
**Post date:** [September 15, 2022, 3:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-a-cached-custom-model-in-offline-mode%2F23190%2F1 "2022-09-15T15:19:06Z")

</div>

I am having trouble loading a custom model from the HuggingFace hub in offline mode. My steps are as follows:

1. With an internet connection, download and cache the model

```python
from transformers import AutoModelForSeq2SeqLM

_ = AutoModelForSeq2SeqLM.from_pretrained("ccdv/lsg-bart-base-4096-wcep", force_download=True, trust_remote_code=True)

```

1. Without an internet connection, try to use said model

```python
import os
from transformers import AutoModelForSeq2SeqLM

os.environ["TRANSFORMERS_OFFLINE"] = "1"

# This hangs, because it tries to make a request in an offline environment
_ = AutoModelForSeq2SeqLM.from_pretrained("ccdv/lsg-bart-base-4096-wcep", force_download=True, trust_remote_code=True)

```

Unfortunately, the code just hangs. If I command/ctrl-c it, I can see it was trying to make a request

```bash
line 85, in create_connection
    sock.connect(sa)
KeyboardInterrupt

```

Which of course hangs because there is no access to the internet. A couple notes:

- This works fine for models without custom code
- I need this to work in an offline environment because the compute nodes of the cluster I am working on do not have access to the internet

Is this a known/unknown bug? Or am I making a mistake in how I download and cache the custom model?

---

<div class="post-metadata">

**Author:** ![johngiorgi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/johngiorgi/32/31960_2.png) [@johngiorgi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjohngiorgi)%5C
**Post date:** [September 19, 2022, 6:26pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-a-cached-custom-model-in-offline-mode%2F23190%2F2 "2022-09-19T18:26:53Z")

</div>

One solution is to load the model _with internet access_, save it to your local disk (with `save_pretrained()`) and then load it with `AutoModel.from_pretrained` from that path. Ideally, you would be able to load it right from the model’s name and avoid explicitly saving it to disk, but this works.
