实例化 model = SentenceTransformer('moka-ai/m3e-base') 时,为什么显示 ConnectionError呢?
模型实例化时,显示 请求连接失败,有大佬可以帮忙看下这是为什么吗?
具体报错如下:
ConnectionResetError Traceback (most recent call last)
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
704 conn,
705 method,
706 url,
707 timeout=timeout_obj,
708 body=body,
709 headers=headers,
710 chunked=chunked,
711 )
713 # If we're going to release the connection in finally:
, then
714 # the response doesn't need to know about the connection. Otherwise
715 # it will also try to release it and we'll have a double-release
716 # mess.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:386, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
385 try:
--> 386 self._validate_conn(conn)
387 except (SocketTimeout, BaseSSLError) as e:
388 # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1040, in HTTPSConnectionPool._validate_conn(self, conn)
1039 if not getattr(conn, "sock", None): # AppEngine might not have .sock
-> 1040 conn.connect()
1042 if not conn.is_verified:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connection.py:414, in HTTPSConnection.connect(self)
412 context.load_default_certs()
--> 414 self.sock = ssl_wrap_socket(
415 sock=conn,
416 keyfile=self.key_file,
417 certfile=self.cert_file,
418 key_password=self.key_password,
419 ca_certs=self.ca_certs,
420 ca_cert_dir=self.ca_cert_dir,
421 ca_cert_data=self.ca_cert_data,
422 server_hostname=server_hostname,
423 ssl_context=context,
424 tls_in_tls=tls_in_tls,
425 )
427 # If we're using all defaults and the connection
428 # is TLSv1 or TLSv1.1 we throw a DeprecationWarning
429 # for the host.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/util/ssl_.py:449, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password, ca_cert_data, tls_in_tls)
448 if send_sni:
--> 449 ssl_sock = _ssl_wrap_socket_impl(
450 sock, context, tls_in_tls, server_hostname=server_hostname
451 )
452 else:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/util/ssl_.py:493, in _ssl_wrap_socket_impl(sock, ssl_context, tls_in_tls, server_hostname)
492 if server_hostname:
--> 493 return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
494 else:
File /opt/anaconda3/lib/python3.9/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
494 def wrap_socket(self, sock, server_side=False,
495 do_handshake_on_connect=True,
496 suppress_ragged_eofs=True,
497 server_hostname=None, session=None):
498 # SSLSocket class handles server_hostname encoding before it calls
499 # ctx._wrap_socket()
--> 500 return self.sslsocket_class._create(
501 sock=sock,
502 server_side=server_side,
503 do_handshake_on_connect=do_handshake_on_connect,
504 suppress_ragged_eofs=suppress_ragged_eofs,
505 server_hostname=server_hostname,
506 context=self,
507 session=session
508 )
File /opt/anaconda3/lib/python3.9/ssl.py:1040, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1040 self.do_handshake()
1041 except (OSError, ValueError):
File /opt/anaconda3/lib/python3.9/ssl.py:1309, in SSLSocket.do_handshake(self, block)
1308 self.settimeout(None)
-> 1309 self._sslobj.do_handshake()
1310 finally:
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
ProtocolError Traceback (most recent call last)
File /opt/anaconda3/lib/python3.9/site-packages/requests/adapters.py:440, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
439 if not chunked:
--> 440 resp = conn.urlopen(
441 method=request.method,
442 url=url,
443 body=request.body,
444 headers=request.headers,
445 redirect=False,
446 assert_same_host=False,
447 preload_content=False,
448 decode_content=False,
449 retries=self.max_retries,
450 timeout=timeout
451 )
453 # Send the request.
454 else:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:785, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
783 e = ProtocolError("Connection aborted.", e)
--> 785 retries = retries.increment(
786 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
787 )
788 retries.sleep()
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/util/retry.py:550, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
549 if read is False or not self._is_method_retryable(method):
--> 550 raise six.reraise(type(error), error, _stacktrace)
551 elif read is not None:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/packages/six.py:769, in reraise(tp, value, tb)
768 if value.traceback is not tb:
--> 769 raise value.with_traceback(tb)
770 raise value
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
704 conn,
705 method,
706 url,
707 timeout=timeout_obj,
708 body=body,
709 headers=headers,
710 chunked=chunked,
711 )
713 # If we're going to release the connection in finally:
, then
714 # the response doesn't need to know about the connection. Otherwise
715 # it will also try to release it and we'll have a double-release
716 # mess.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:386, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
385 try:
--> 386 self._validate_conn(conn)
387 except (SocketTimeout, BaseSSLError) as e:
388 # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py:1040, in HTTPSConnectionPool._validate_conn(self, conn)
1039 if not getattr(conn, "sock", None): # AppEngine might not have .sock
-> 1040 conn.connect()
1042 if not conn.is_verified:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/connection.py:414, in HTTPSConnection.connect(self)
412 context.load_default_certs()
--> 414 self.sock = ssl_wrap_socket(
415 sock=conn,
416 keyfile=self.key_file,
417 certfile=self.cert_file,
418 key_password=self.key_password,
419 ca_certs=self.ca_certs,
420 ca_cert_dir=self.ca_cert_dir,
421 ca_cert_data=self.ca_cert_data,
422 server_hostname=server_hostname,
423 ssl_context=context,
424 tls_in_tls=tls_in_tls,
425 )
427 # If we're using all defaults and the connection
428 # is TLSv1 or TLSv1.1 we throw a DeprecationWarning
429 # for the host.
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/util/ssl_.py:449, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password, ca_cert_data, tls_in_tls)
448 if send_sni:
--> 449 ssl_sock = _ssl_wrap_socket_impl(
450 sock, context, tls_in_tls, server_hostname=server_hostname
451 )
452 else:
File /opt/anaconda3/lib/python3.9/site-packages/urllib3/util/ssl_.py:493, in _ssl_wrap_socket_impl(sock, ssl_context, tls_in_tls, server_hostname)
492 if server_hostname:
--> 493 return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
494 else:
File /opt/anaconda3/lib/python3.9/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
494 def wrap_socket(self, sock, server_side=False,
495 do_handshake_on_connect=True,
496 suppress_ragged_eofs=True,
497 server_hostname=None, session=None):
498 # SSLSocket class handles server_hostname encoding before it calls
499 # ctx._wrap_socket()
--> 500 return self.sslsocket_class._create(
501 sock=sock,
502 server_side=server_side,
503 do_handshake_on_connect=do_handshake_on_connect,
504 suppress_ragged_eofs=suppress_ragged_eofs,
505 server_hostname=server_hostname,
506 context=self,
507 session=session
508 )
File /opt/anaconda3/lib/python3.9/ssl.py:1040, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1040 self.do_handshake()
1041 except (OSError, ValueError):
File /opt/anaconda3/lib/python3.9/ssl.py:1309, in SSLSocket.do_handshake(self, block)
1308 self.settimeout(None)
-> 1309 self._sslobj.do_handshake()
1310 finally:
ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
Input In [29], in <cell line: 5>()
1 # !pip install -U sentence-transformers
2 # from sentence_transformers import SentenceTransformer
----> 5 model = SentenceTransformer('moka-ai/m3e-base')
File /opt/anaconda3/lib/python3.9/site-packages/sentence_transformers/SentenceTransformer.py:87, in SentenceTransformer.init(self, model_name_or_path, modules, device, cache_folder, use_auth_token)
83 model_path = os.path.join(cache_folder, model_name_or_path.replace("/", "_"))
85 if not os.path.exists(os.path.join(model_path, 'modules.json')):
86 # Download from hub with caching
---> 87 snapshot_download(model_name_or_path,
88 cache_dir=cache_folder,
89 library_name='sentence-transformers',
90 library_version=version,
91 ignore_files=['flax_model.msgpack', 'rust_model.ot', 'tf_model.h5'],
92 use_auth_token=use_auth_token)
94 if os.path.exists(os.path.join(model_path, 'modules.json')): #Load as SentenceTransformer model
95 modules = self._load_sbert_model(model_path)
File /opt/anaconda3/lib/python3.9/site-packages/sentence_transformers/util.py:491, in snapshot_download(repo_id, revision, cache_dir, library_name, library_version, user_agent, ignore_files, use_auth_token)
486 if version.parse(huggingface_hub.version) >= version.parse("0.8.1"):
487 # huggingface_hub v0.8.1 introduces a new cache layout. We sill use a manual layout
488 # And need to pass legacy_cache_layout=True to avoid that a warning will be printed
489 cached_download_args['legacy_cache_layout'] = True
--> 491 path = cached_download(**cached_download_args)
493 if os.path.exists(path + ".lock"):
494 os.remove(path + ".lock")
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:118, in validate_hf_hub_args.._inner_fn(*args, **kwargs)
115 if check_use_auth_token:
116 kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.name, has_token=has_token, kwargs=kwargs)
--> 118 return fn(*args, **kwargs)
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/file_download.py:800, in cached_download(url, library_name, library_version, cache_dir, user_agent, force_download, force_filename, proxies, etag_timeout, resume_download, token, local_files_only, legacy_cache_layout)
797 with temp_file_manager() as temp_file:
798 logger.info("downloading %s to %s", url, temp_file.name)
--> 800 http_get(
801 url_to_download,
802 temp_file,
803 proxies=proxies,
804 resume_size=resume_size,
805 headers=headers,
806 expected_size=expected_size,
807 )
809 logger.info("storing %s in cache at %s", url, cache_path)
810 _chmod_and_replace(temp_file.name, cache_path)
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/file_download.py:505, in http_get(url, temp_file, proxies, resume_size, headers, timeout, max_retries, expected_size)
502 if resume_size > 0:
503 headers["Range"] = "bytes=%d-" % (resume_size,)
--> 505 r = _request_wrapper(
506 method="GET",
507 url=url,
508 stream=True,
509 proxies=proxies,
510 headers=headers,
511 timeout=timeout,
512 max_retries=max_retries,
513 )
514 hf_raise_for_status(r)
515 content_length = r.headers.get("Content-Length")
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/file_download.py:442, in _request_wrapper(method, url, max_retries, base_wait_time, max_wait_time, timeout, follow_relative_redirects, **params)
439 return response
441 # 3. Exponential backoff
--> 442 return http_backoff(
443 method=method,
444 url=url,
445 max_retries=max_retries,
446 base_wait_time=base_wait_time,
447 max_wait_time=max_wait_time,
448 retry_on_exceptions=(Timeout, ProxyError),
449 retry_on_status_codes=(),
450 timeout=timeout,
451 **params,
452 )
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/utils/_http.py:258, in http_backoff(method, url, max_retries, base_wait_time, max_wait_time, retry_on_exceptions, retry_on_status_codes, **kwargs)
255 kwargs["data"].seek(io_obj_initial_pos)
257 # Perform request and return if status_code is not in the retry list.
--> 258 response = session.request(method=method, url=url, **kwargs)
259 if response.status_code not in retry_on_status_codes:
260 return response
File /opt/anaconda3/lib/python3.9/site-packages/requests/sessions.py:529, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
524 send_kwargs = {
525 'timeout': timeout,
526 'allow_redirects': allow_redirects,
527 }
528 send_kwargs.update(settings)
--> 529 resp = self.send(prep, **send_kwargs)
531 return resp
File /opt/anaconda3/lib/python3.9/site-packages/requests/sessions.py:645, in Session.send(self, request, **kwargs)
642 start = preferred_clock()
644 # Send the request
--> 645 r = adapter.send(request, **kwargs)
647 # Total elapsed time of the request (approximately)
648 elapsed = preferred_clock() - start
File /opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/utils/_http.py:63, in UniqueRequestIdAdapter.send(self, request, *args, **kwargs)
61 """Catch any RequestException to append request id to the error message for debugging."""
62 try:
---> 63 return super().send(request, *args, **kwargs)
64 except requests.RequestException as e:
65 request_id = request.headers.get(X_AMZN_TRACE_ID)
File /opt/anaconda3/lib/python3.9/site-packages/requests/adapters.py:501, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
498 raise
500 except (ProtocolError, socket.error) as err:
--> 501 raise ConnectionError(err, request=request)
503 except MaxRetryError as e:
504 if isinstance(e.reason, ConnectTimeoutError):
505 # TODO: Remove this in 3.0.0: see #2811
ConnectionError: (ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')), '(Request ID: ddd4ac08-2e62-424c-9563-9cb91e9d1379)')
网络的原因导致的