服务器无法连接huggingface下载模型

报错代码

import torch
from FlagEmbedding.visual.modeling import Visualized_BGE

def image_retrival():
    ############ Use Visualized BGE doing composed image retrieval
    model = Visualized_BGE(model_name_bge = "BAAI/bge-m3", model_weight="/data/suanfa/meng/mybge-m3/Visualized_m3.pth")
    model.eval()
    with torch.no_grad():
        query_emb = model.encode(image="../image/whitedogwithyellowleaf.jpg/", text="Make the background dark, as if the camera has taken the photo at night")
        candi_emb_1 = model.encode(image="../image/4dogs_on_lawn.jpg")
        candi_emb_2 = model.encode(image="../image/whitedog.jpg")

    sim_1 = query_emb @ candi_emb_1.T
    sim_2 = query_emb @ candi_emb_2.T
    print(sim_1, sim_2)
if __name__=='__main__':
    image_retrival()

报错

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-m3 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-model'.

解决方法1:offline-mode形式

1.打开hugging face 官网:https://huggingface.co/docs/transformers/installation#offline-mode 并点击Models
在这里插入图片描述
2.搜索我们需要的模型
在这里插入图片描述
输入使用的模型,并点击模型
3.下载文件
在这里插入图片描述
点击file and versions
通过后面的下载按钮下载圈出的五个文件到本地
4.上传文件到服务器

(py38_bge) [root@x.x.x.x /data/suanfa/meng/mybge-m3/bge-m3]$ ll
total 21664
-rw-r--r-- 1 root root      687 Oct  9 20:01 config.json
-rw-r--r-- 1 root root  5069051 Oct 10 19:50 sentencepiece.bpe.model
-rw-r--r-- 1 root root      125 Oct 10 19:53 special_tokens_map.json
-rw-r--r-- 1 root root      444 Oct  9 20:01 tokenizer_config.json
-rw-r--r-- 1 root root 17098108 Oct  9 20:01 tokenizer.json

5.修改py文件

model = Visualized_BGE(model_name_bge = "/data/suanfa/meng/mybge-m3/bge-m3", model_weight="/data/suanfa/meng/mybge-m3/Visualized_m3.pth"

6.运行报错
model.encode行报错

IndexError: index out of range in self

7.问题排查
和解决方法2下载下来的文件进行了对比,发现两个special_tokens_map.json文件内容不一致,于是替换成解决方法2下载下来的该文件替换方法1的该文件,问题成功解决,模型输出:

tensor([[0.5751]]) tensor([[0.5856]])

解决方法2:通过镜像下载模型

1.访问网站:https://hf-mirror.com/
里面有详细步骤:

pip install -U huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值