Huggingface_hub更换下载源

使用Huggingface_hub库下载模型时会遇到:
“无法连接到 Hugging Face Hub 下载预训练的 VAE 模型,导致模型初始化失败。具体原因是网络连接超时(Connection to huggingface.co timed out),可能是由于网络限制、代理问题或访问速度过慢。”的问题

可以通过修改下载源的网址的方式来避免该问题,具体方式为:

找到环境中Huggingface_hub库所在的位置,例如“\anaconda3\envs\env-name(你的环境的名字)\Lib\site-packages\huggingface_hub”,找到其中的constants.py文件,用记事本打开,将其中HUGGINGFACE_CO_URL_HOME与_HF_DEFAULT_ENDPOINT的值修改为"https://hf-mirror.com",保存后关闭即可。

awq) root@develop-i73kxjbp-67f8fc7755-g4zsx:/home/dataset/data/s30078333/AutoAWQ# export HF_ENDPOINT=https://hf-mirror.com (awq) root@develop-i73kxjbp-67f8fc7755-g4zsx:/home/dataset/data/s30078333/AutoAWQ# /home/ma-user/anaconda3/envs/awq/bin/python /home/dataset/data/s30078333/AutoAWQ/examples/quantize.py /home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/awq/__init__.py:21: DeprecationWarning: I have left this message as the final dev message to help you transition. Important Notice: - AutoAWQ is officially deprecated and will no longer be maintained. - The last tested configuration used Torch 2.6.0 and Transformers 4.51.3. - If future versions of Transformers break AutoAWQ compatibility, please report the issue to the Transformers project. Alternative: - AutoAWQ has been adopted by the vLLM Project: https://github.com/vllm-project/llm-compressor For further inquiries, feel free to reach out: - X: https://x.com/casper_hansen_ - LinkedIn: https://www.linkedin.com/in/casper-hansen-804005170/ warnings.warn(_FINAL_DEV_MESSAGE, category=DeprecationWarning, stacklevel=1) Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connection.py", line 198, in _new_conn sock = connection.create_connection( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection raise err File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) TimeoutError: timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen response = self._make_request( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connectionpool.py", line 488, in _make_request raise new_e File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connectionpool.py", line 464, in _make_request self._validate_conn(conn) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1093, in _validate_conn conn.connect() File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connection.py", line 753, in connect self.sock = sock = self._new_conn() File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connection.py", line 207, in _new_conn raise ConnectTimeoutError( urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x7f9e7884c610>, 'Connection to hf-mirror.com timed out. (connect timeout=10)') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/requests/adapters.py", line 667, in send resp = conn.urlopen( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/connectionpool.py", line 841, in urlopen retries = retries.increment( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/urllib3/util/retry.py", line 519, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='hf-mirror.com', port=443): Max retries exceeded with url: /Qwen/Qwen2.5-14B-Instruct/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f9e7884c610>, 'Connection to hf-mirror.com timed out. (connect timeout=10)')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1546, in _get_metadata_or_catch_error metadata = get_hf_file_metadata( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1463, in get_hf_file_metadata r = _request_wrapper( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 286, in _request_wrapper response = _request_wrapper( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 309, in _request_wrapper response = http_backoff(method=method, url=url, **params, retry_on_exceptions=(), retry_on_status_codes=(429,)) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 310, in http_backoff response = session.request(method=method, url=url, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 96, in send return super().send(request, *args, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/requests/adapters.py", line 688, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: (MaxRetryError("HTTPSConnectionPool(host='hf-mirror.com', port=443): Max retries exceeded with url: /Qwen/Qwen2.5-14B-Instruct/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f9e7884c610>, 'Connection to hf-mirror.com timed out. (connect timeout=10)'))"), '(Request ID: 594a7347-12f8-4773-9668-1b5c9e78f346)') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/utils/hub.py", line 476, in cached_files hf_hub_download( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1010, in hf_hub_download return _hf_hub_download_to_cache_dir( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1117, in _hf_hub_download_to_cache_dir _raise_on_head_call_error(head_call_error, force_download, local_files_only) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1661, in _raise_on_head_call_error raise LocalEntryNotFoundError( huggingface_hub.errors.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: Traceback (most recent call last): File "/home/dataset/data/s30078333/AutoAWQ/examples/quantize.py", line 9, in <module> model = AutoAWQForCausalLM.from_pretrained(model_path) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/awq/models/auto.py", line 80, in from_pretrained model_type = check_and_get_model_type( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/awq/models/auto.py", line 51, in check_and_get_model_type config = AutoConfig.from_pretrained( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 1244, in from_pretrained config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/configuration_utils.py", line 649, in get_config_dict config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/configuration_utils.py", line 708, in _get_config_dict resolved_config_file = cached_file( File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/utils/hub.py", line 318, in cached_file file = cached_files(path_or_repo_id=path_or_repo_id, filenames=[filename], **kwargs) File "/home/ma-user/anaconda3/envs/awq/lib/python3.10/site-packages/transformers/utils/hub.py", line 550, in cached_files raise OSError( OSError: We couldn't connect to 'https://hf-mirror.com' to load the files, and couldn't find them in the cached files. Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值