make internet connection only if local cache is missing
Author: James4Ever0
Pull request: no

### Feature request

Check if local cache has the model, and download the model only if have to.

### Motivation

My connection to github or huggingface is unstable. I don't want make this unstable internet connection if I can find the cache of the model, breaking things and logics.

### Your contribution

I already mentioned it at #2867. I also made some changes at #20876

Comments:
hi james, can you assign this issue to me?

Thanks for opening this issue, but we're not interested in implementing this feature as this would break the auto-update mechanism (if someone updates the model, it would no longer be downloaded).

If the connection fails for any reason, local files are used instead.

okay, no problem, i'll look for another issue, which i can fix.
thanx for replying.

> this would break the auto-update mechanism

In the code the default value of this parameter is set to "False", so it won't be turned on unless you set it to "True".

Auto-updating model is not always needed, though by default it will check for updates everytime.

It's based on the "local_files_only" #2930, which will skip updates after all.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

I've made some updates on my fork, though might be incomplete, shall cover most cases on model loading.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

> Thanks for opening this issue, but we're not interested in implementing this feature as this would break the auto-update mechanism (if someone updates the model, it would no longer be downloaded).
> 
> If the connection fails for any reason, local files are used instead.

When I'm debugging locally I don't want the model to suddenly change when all my tests so far have been conducted on a specific version. Also, I was wondering why the python script was hanging all the time. Not sure what exactly caused it, could also be ChromaDB doing requests to https://us-api.i.posthog.com which I find very concerning (probably telemetry, will have to disable this), but I observed that the main thread sends a request to https://huggingface.co/sentence-transformers/paraphrase-multilingual-mpnet-base-v2/resolve/main/modules.json and this is not required when files are already local.

Maybe there should be a versioning system where someone can specify a version like "1.2.4" and if it's already available locally, there won't be a request.

See also https://github.com/huggingface/transformers/issues/2867#issuecomment-588141691

I want to use "disable_outgoing" but it's not in the code even though it's mentioned in the commit:
https://github.com/huggingface/transformers/commit/a143d9479e3908ebe5bb32e9689dbf7d24eb536c

How do I pass "local_files_only" when using "SentenceTransformer"?

I tried this but there is no way to pass the config OR local_files_only to SentenceTransformer:

```
        config = AutoConfig.from_pretrained(
            pretrained_model_name_or_path=args.embedding_model,
            local_files_only=True,
            trust_remote_code=False,
            device="cpu" if args.embedding_on_cpu else "cuda",
        )
        self.embedding = SentenceTransformer(
            pretrained_model_name_or_path=args.embedding_model,
            # ?
        )
```