couldn‘t connect to ‘https://huggingface.co‘ to load this file

部署运行你感兴趣的模型镜像

huggingface网络连接问题:

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 BAAI/bge-large-en-v1.5 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'.

例如:BAAI/bge-large-en-v1.5



model_name = "BAAI/bge-large-en-v1.5"
model_kwargs = {"device": "cpu"}
encode_kwargs = {"normalize_embeddings": True}

embedding_model = HuggingFaceBgeEmbeddings(
    model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs
)


问题描述

OSError: We couldn‘t connect to ‘https://huggingface.co‘ to load this file, couldn‘t find it(亲测有效)

解决方案:

提示:https://hf-mirror.com/
点进去这个镜像网站,里面有四种解决办法

方案一:
去hugging face 上手动下载

方案二:

  1. 安装依赖
    pip install -U huggingface_hub

  2. 设置环境变量
    Linux
    export HF_ENDPOINT=https://hf-mirror.com
    Windows Powershell
    $env:HF_ENDPOINT = "https://hf-mirror.com"
    建议将上面这一行写入 ~/.bashrc。
    3.1 下载模型
    huggingface-cli download --resume-download gpt2 --local-dir gpt2
    3.2 下载数据集
    huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitext
    可以添加 --local-dir-use-symlinks False 参数禁用文件软链接,这样下载路径下所见即所得,详细解释请见上面提到的教程。

方案三:

  1. 下载hfd
    wget https://hf-mirror.com/hfd/hfd.sh chmod a+x hfd.sh

  2. 设置环境变量
    Linux
    export HF_ENDPOINT=https://hf-mirror.com
    Windows Powershell
    $env:HF_ENDPOINT = "https://hf-mirror.com"

  3. 下载模型
    ./hfd.sh gpt2

  4. 下载数据集
    ./hfd.sh wikitext --dataset

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

### 无法连接 `https://huggingface.co` 加载文件的解决办法 #### 使用代理 如果因为网络限制无法连接到 `https://huggingface.co`,可以设置代理。以使用 `pip` 为例,在命令行中设置代理: ```bash pip install transformers --proxy=http://your_proxy_address:your_proxy_port ``` 在 Python 代码中使用代理: ```python import os os.environ['HTTP_PROXY'] = 'http://your_proxy_address:your_proxy_port' os.environ['HTTPS_PROXY'] = 'http://your_proxy_address:your_proxy_port' ``` #### 使用镜像源 可以使用国内的镜像源来下载相关文件。例如,使用阿里云镜像源: ```bash pip install transformers -i https://mirrors.aliyun.com/pypi/simple/ ``` ### 本地缓存无文件的解决办法 #### 手动下载文件 可以手动从 `https://huggingface.co` 下载所需的文件。对于 `bert-base-chinese` 模型,通常需要下载以下文件: - `config.json`:模型配置文件,存储模型结构参数。 - `pytorch_model.bin`:存储模型的权重。 - `vocab.txt`:词表文件。 将这些文件下载到本地指定目录。 #### 代码中指定缓存目录 在代码中指定缓存目录,确保文件下载到指定位置: ```python from transformers import BertModel, BertTokenizer model_name = "bert-base-chinese" cache_dir = "path/to/your/cache/dir" tokenizer = BertTokenizer.from_pretrained(model_name, cache_dir=cache_dir) model = BertModel.from_pretrained(model_name, cache_dir=cache_dir) ``` ### `bert-base-chinese` 不是包含 `config.json` 文件的目录路径的解决办法 #### 检查路径 确保 `bert-base-chinese` 指向的是包含 `config.json` 文件的正确目录路径。可以使用绝对路径来避免路径问题: ```python from transformers import BertModel model_path = "absolute/path/to/bert-base-chinese" model = BertModel.from_pretrained(model_path) ``` #### 重新组织文件结构 如果文件结构不正确,将 `config.json`、`pytorch_model.bin` 和 `vocab.txt` 等文件移动到同一个目录下,并使用该目录路径加载模型。 ```python from transformers import BertModel, BertTokenizer model_path = "path/to/your/bert-base-chinese" tokenizer = BertTokenizer.from_pretrained(model_path) model = BertModel.from_pretrained(model_path) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值