I noticed that when loading a pretrained model (BertForSequenceClassification
in my case) while running a virtual environment that an error occurs:
HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/config.json (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
Traceback (most recent call last):
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/connection.py", line 506, in _connect_tls_proxy
ssl_context=ssl_context,
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/aclifton/anaconda3/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/home/aclifton/anaconda3/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/home/aclifton/anaconda3/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/config.json (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/configuration_utils.py", line 505, in get_config_dict
user_agent=user_agent,
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/file_utils.py", line 1337, in cached_path
local_files_only=local_files_only,
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/file_utils.py", line 1499, in get_from_cache
r = requests.head(url, headers=headers, allow_redirects=False, proxies=proxies, timeout=etag_timeout)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/api.py", line 104, in head
return request('head', url, **kwargs)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/requests/adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/config.json (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1086, in from_pretrained
**kwargs,
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/configuration_utils.py", line 440, in from_pretrained
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/aclifton/venvs/hf_test/lib/python3.7/site-packages/transformers/configuration_utils.py", line 517, in get_config_dict
raise EnvironmentError(msg)
OSError: Can't load config for 'bert-base-uncased'. Make sure that:
- 'bert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'bert-base-uncased' is the correct path to a directory containing a config.json file
However, not running the venv, the pretrained model loads fine. Here is an example:
from transformers import BertForSequenceClassification
model = BertForSequenceClassification.from_pretrained('bert-base-uncased')