### Describe the bug
Hi I am consistently getting this error when I try to usβ¦e a tokenizer, mode or pipeline from pretrained hf models:
> OSError: We couldn't connect to 'https://huggingface.co/' to load this file, couldn't find it in the cached files and it looks like google-bert/bert-base-german-cased is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
I checked my connection and cleared out the cache. Moreover when I update hugging face_hub[cli] with pip install huggingface_hub[cli], I get the following warning:
> WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc032677010>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /simple/huggingface-hub/
The models I try to access were google-bert/bert-base-german-cased and dbmdz/bert-base-german-uncased. I am running the code on google cloud instances on n2d-standard-4 (4 vCPUs, 16 GB RAM) machine with transformers version 4.40.2. Could you please let me know what leads to this error and help me solve it?
### Reproduction
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-german-cased")
model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-german-cased")
### Logs
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self)
197 try:
--> 198 sock = connection.create_connection(
199 (self._dns_host, self.port),
200 self.timeout,
201 source_address=self.source_address,
202 socket_options=self.socket_options,
203 )
204 except socket.gaierror as e:
File /opt/conda/lib/python3.10/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
84 try:
---> 85 raise err
86 finally:
87 # Break explicitly a reference cycle
File /opt/conda/lib/python3.10/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
72 sock.bind(source_address)
---> 73 sock.connect(sa)
74 # Break explicitly a reference cycle
OSError: [Errno 101] Network is unreachable
The above exception was the direct cause of the following exception:
NewConnectionError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/urllib3/connectionpool.py:793, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
792 # Make the request on the HTTPConnection object
--> 793 response = self._make_request(
794 conn,
795 method,
796 url,
797 timeout=timeout_obj,
798 body=body,
799 headers=headers,
800 chunked=chunked,
801 retries=retries,
802 response_conn=response_conn,
803 preload_content=preload_content,
804 decode_content=decode_content,
805 **response_kw,
806 )
808 # Everything went great!
File /opt/conda/lib/python3.10/site-packages/urllib3/connectionpool.py:491, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
490 new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 491 raise new_e
493 # conn.request() calls http.client.*.request, not the method in
494 # urllib3.request. It also calls makefile (recv) on the socket.
File /opt/conda/lib/python3.10/site-packages/urllib3/connectionpool.py:467, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
466 try:
--> 467 self._validate_conn(conn)
468 except (SocketTimeout, BaseSSLError) as e:
File /opt/conda/lib/python3.10/site-packages/urllib3/connectionpool.py:1099, in HTTPSConnectionPool._validate_conn(self, conn)
1098 if conn.is_closed:
-> 1099 conn.connect()
1101 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791
File /opt/conda/lib/python3.10/site-packages/urllib3/connection.py:616, in HTTPSConnection.connect(self)
615 sock: socket.socket | ssl.SSLSocket
--> 616 self.sock = sock = self._new_conn()
617 server_hostname: str = self.host
File /opt/conda/lib/python3.10/site-packages/urllib3/connection.py:213, in HTTPConnection._new_conn(self)
212 except OSError as e:
--> 213 raise NewConnectionError(
214 self, f"Failed to establish a new connection: {e}"
215 ) from e
217 # Audit hooks are only available in Python 3.8+
NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa15b2b3880>: Failed to establish a new connection: [Errno 101] Network is unreachable
The above exception was the direct cause of the following exception:
MaxRetryError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
485 try:
--> 486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
489 body=request.body,
490 headers=request.headers,
491 redirect=False,
492 assert_same_host=False,
493 preload_content=False,
494 decode_content=False,
495 retries=self.max_retries,
496 timeout=timeout,
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
File /opt/conda/lib/python3.10/site-packages/urllib3/connectionpool.py:847, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
845 new_e = ProtocolError("Connection aborted.", new_e)
--> 847 retries = retries.increment(
848 method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
849 )
850 retries.sleep()
File /opt/conda/lib/python3.10/site-packages/urllib3/util/retry.py:515, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
514 reason = error or ResponseError(cause)
--> 515 raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
517 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)
MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /google-bert/bert-base-german-cased/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa15b2b3880>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:1722, in _get_metadata_or_catch_error(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, local_files_only, relative_filename, storage_folder)
1721 try:
-> 1722 metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
1723 except EntryNotFoundError as http_error:
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
112 kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:1645, in get_hf_file_metadata(url, token, proxies, timeout, library_name, library_version, user_agent, headers)
1644 # Retrieve metadata
-> 1645 r = _request_wrapper(
1646 method="HEAD",
1647 url=url,
1648 headers=headers,
1649 allow_redirects=False,
1650 follow_relative_redirects=True,
1651 proxies=proxies,
1652 timeout=timeout,
1653 )
1654 hf_raise_for_status(r)
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:372, in _request_wrapper(method, url, follow_relative_redirects, **params)
371 if follow_relative_redirects:
--> 372 response = _request_wrapper(
373 method=method,
374 url=url,
375 follow_relative_redirects=False,
376 **params,
377 )
379 # If redirection, we redirect only relative paths.
380 # This is useful in case of a renamed repository.
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:395, in _request_wrapper(method, url, follow_relative_redirects, **params)
394 # Perform request and return if status_code is not in the retry list.
--> 395 response = get_session().request(method=method, url=url, **params)
396 hf_raise_for_status(response)
File /opt/conda/lib/python3.10/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
591 return resp
File /opt/conda/lib/python3.10/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
705 # Total elapsed time of the request (approximately)
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_http.py:66, in UniqueRequestIdAdapter.send(self, request, *args, **kwargs)
65 try:
---> 66 return super().send(request, *args, **kwargs)
67 except requests.RequestException as e:
File /opt/conda/lib/python3.10/site-packages/requests/adapters.py:519, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
517 raise SSLError(e, request=request)
--> 519 raise ConnectionError(e, request=request)
521 except ClosedPoolError as e:
ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /google-bert/bert-base-german-cased/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa15b2b3880>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: 8df1d542-4895-405c-b79d-4d2ca4001529)')
The above exception was the direct cause of the following exception:
LocalEntryNotFoundError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/transformers/utils/hub.py:398, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
396 try:
397 # Load from URL or cache if already cached
--> 398 resolved_file = hf_hub_download(
399 path_or_repo_id,
400 filename,
401 subfolder=None if len(subfolder) == 0 else subfolder,
402 repo_type=repo_type,
403 revision=revision,
404 cache_dir=cache_dir,
405 user_agent=user_agent,
406 force_download=force_download,
407 proxies=proxies,
408 resume_download=resume_download,
409 token=token,
410 local_files_only=local_files_only,
411 )
412 except GatedRepoError as e:
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
112 kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:1221, in hf_hub_download(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, legacy_cache_layout, resume_download, force_filename, local_dir_use_symlinks)
1220 else:
-> 1221 return _hf_hub_download_to_cache_dir(
1222 # Destination
1223 cache_dir=cache_dir,
1224 # File info
1225 repo_id=repo_id,
1226 filename=filename,
1227 repo_type=repo_type,
1228 revision=revision,
1229 # HTTP info
1230 headers=headers,
1231 proxies=proxies,
1232 etag_timeout=etag_timeout,
1233 endpoint=endpoint,
1234 # Additional options
1235 local_files_only=local_files_only,
1236 force_download=force_download,
1237 )
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:1325, in _hf_hub_download_to_cache_dir(cache_dir, repo_id, filename, repo_type, revision, headers, proxies, etag_timeout, endpoint, local_files_only, force_download)
1324 # Otherwise, raise appropriate error
-> 1325 _raise_on_head_call_error(head_call_error, force_download, local_files_only)
1327 # From now on, etag, commit_hash, url and size are not None.
File /opt/conda/lib/python3.10/site-packages/huggingface_hub/file_download.py:1826, in _raise_on_head_call_error(head_call_error, force_download, local_files_only)
1824 else:
1825 # Otherwise: most likely a connection issue or Hub downtime => let's warn the user
-> 1826 raise LocalEntryNotFoundError(
1827 "An error happened while trying to locate the file on the Hub and we cannot find the requested files"
1828 " in the local cache. Please check your connection and try again or make sure your Internet connection"
1829 " is on."
1830 ) from head_call_error
LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.
The above exception was the direct cause of the following exception:
OSError Traceback (most recent call last)
Cell In[13], line 3
1 from transformers import AutoTokenizer, AutoModelForMaskedLM
----> 3 tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-german-cased")
4 model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-german-cased")
File /opt/conda/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py:819, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
817 if config_tokenizer_class is None:
818 if not isinstance(config, PretrainedConfig):
--> 819 config = AutoConfig.from_pretrained(
820 pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
821 )
822 config_tokenizer_class = config.tokenizer_class
823 if hasattr(config, "auto_map") and "AutoTokenizer" in config.auto_map:
File /opt/conda/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:928, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
925 trust_remote_code = kwargs.pop("trust_remote_code", None)
926 code_revision = kwargs.pop("code_revision", None)
--> 928 config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
929 has_remote_code = "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]
930 has_local_code = "model_type" in config_dict and config_dict["model_type"] in CONFIG_MAPPING
File /opt/conda/lib/python3.10/site-packages/transformers/configuration_utils.py:631, in PretrainedConfig.get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
629 original_kwargs = copy.deepcopy(kwargs)
630 # Get config dict associated with the base config file
--> 631 config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
632 if "_commit_hash" in config_dict:
633 original_kwargs["_commit_hash"] = config_dict["_commit_hash"]
File /opt/conda/lib/python3.10/site-packages/transformers/configuration_utils.py:686, in PretrainedConfig._get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
682 configuration_file = kwargs.pop("_configuration_file", CONFIG_NAME)
684 try:
685 # Load from local folder or from cache or download from model Hub and cache
--> 686 resolved_config_file = cached_file(
687 pretrained_model_name_or_path,
688 configuration_file,
689 cache_dir=cache_dir,
690 force_download=force_download,
691 proxies=proxies,
692 resume_download=resume_download,
693 local_files_only=local_files_only,
694 token=token,
695 user_agent=user_agent,
696 revision=revision,
697 subfolder=subfolder,
698 _commit_hash=commit_hash,
699 )
700 commit_hash = extract_commit_hash(resolved_config_file, commit_hash)
701 except EnvironmentError:
702 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
703 # the original exception.
File /opt/conda/lib/python3.10/site-packages/transformers/utils/hub.py:441, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
435 if (
436 resolved_file is not None
437 or not _raise_exceptions_for_missing_entries
438 or not _raise_exceptions_for_connection_errors
439 ):
440 return resolved_file
--> 441 raise EnvironmentError(
442 f"We couldn't connect to '{HUGGINGFACE_CO_RESOLVE_ENDPOINT}' to load this file, couldn't find it in the"
443 f" cached files and it looks like {path_or_repo_id} is not the path to a directory containing a file named"
444 f" {full_filename}.\nCheckout your internet connection or see how to run the library in offline mode at"
445 " 'https://huggingface.co/docs/transformers/installation#offline-mode'."
446 ) from e
447 except EntryNotFoundError as e:
448 if not _raise_exceptions_for_missing_entries:
OSError: We couldn't connect to 'https://huggingface.co/' to load this file, couldn't find it in the cached files and it looks like google-bert/bert-base-german-cased is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
### System info
```shell
- huggingface_hub version: 0.23.1
- Platform: Linux-5.10.0-29-cloud-amd64-x86_64-with-glibc2.31
- Python version: 3.10.14
- Running in iPython ?: Yes
- iPython shell: ZMQInteractiveShell
- Running in notebook ?: Yes
- Running in Google Colab ?: No
- Token path ?: /home/jupyter/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers:
- FastAI: N/A
- Tensorflow: N/A
- Torch: 2.3.0
- Jinja2: 3.1.4
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: 10.3.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: 2.6.2.2
- numpy: 1.26.4
- pydantic: 1.10.15
- aiohttp: 3.9.5
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /home/jupyter/.cache/huggingface/hub
- HF_ASSETS_CACHE: /home/jupyter/.cache/huggingface/assets
- HF_TOKEN_PATH: /home/jupyter/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
```