AutoTokenizer always tries to download from hub even if the model is cached. Thus it fails to run when running in an docker environment without SSL.
Author: kalpesh22-21
Pull request: no

### System Info

python=3.9
transformers=4.30.2

### Who can help?

@ArthurZucker 

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

1. Run Autotokenizer.frompretrained("path_to_cached_snapshot_directory")

Will throw an SLL error because of no internet connection

Error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /xlm-roberta-large/resolve/main/tokenizer_config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))

problem found in /transformers/utils/hub.py file:

Method def cached_file #line 300

Problem is possibly here:

#line 401
if _commit_hash is not None and not force_download:
    # If the file is cached under that commit hash, we return it directly.
    resolved_file = try_to_load_from_cache(
        path_or_repo_id, full_filename, cache_dir=cache_dir, revision=_commit_hash, repo_type=repo_type
    )
    if resolved_file is not None:
        if resolved_file is not _CACHED_NO_EXIST:
            return resolved_file
        elif not _raise_exceptions_for_missing_entries:
            return None
        else:
              raise EnvironmentError(f"Could not locate {full_filename} inside {path_or_repo_id}.")

The script only try to load from cache if it has a _commit_hash provided which will not be the case in the example above.

I tried to do solve this internally this might help:

#line 401
if not force_download:
    # If the file is cached under that commit hash, we return it directly.
    resolved_file = try_to_load_from_cache(
        path_or_repo_id, full_filename, cache_dir=cache_dir, revision=_commit_hash, repo_type=repo_type
    )
    if resolved_file is not None:
        if resolved_file is not _CACHED_NO_EXIST:
            return resolved_file
        elif not _raise_exceptions_for_missing_entries:
            return None
        elif _commit_hash is not None:
            raise EnvironmentError(f"Could not locate {full_filename} inside {path_or_repo_id}.")

### Expected behavior

It should not download already cached file.

Comments:
Hey! Thanks for reporting. Before diving a bit deeper, there is a `local_files_only` argument that you can set when calling from pretrained, which activated the `offline mode`. You can also set it using `TRANSFORMERS_OFFLINE=1`.  Can you try with this? It was designed for specific cases like this one! 

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.