云计算百科
云计算领域专业知识百科平台

服务器无法连接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/bgem3 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/mybgem3/bgem3]$ ll
total 21664
rwrr 1 root root 687 Oct 9 20:01 config.json
rwrr 1 root root 5069051 Oct 10 19:50 sentencepiece.bpe.model
rwrr 1 root root 125 Oct 10 19:53 special_tokens_map.json
rwrr 1 root root 444 Oct 9 20:01 tokenizer_config.json
rwrr 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://hfmirror.com

赞(0)
未经允许不得转载:网硕互联帮助中心 » 服务器无法连接huggingface下载模型
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!