万万哇 发表于 2025-3-12 12:31:05

服务器无法连接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
https://i-blog.csdnimg.cn/direct/6fa7f0bf768b44c9a8c1b61a1e67dc95.png
2.搜索我们需要的模型
https://i-blog.csdnimg.cn/direct/52ef29bb337542d4a4445ebec67eff23.png
输入利用的模型,并点击模型
3.下载文件
https://i-blog.csdnimg.cn/direct/91a916c9bd9445109fd23bb85e0810d9.png
点击file and versions
通过后面的下载按钮下载圈出的五个文件到本地
4.上传文件到服务器
(py38_bge) $ ll
total 21664
-rw-r--r-- 1 root root      687 Oct9 20:01 config.json
-rw-r--r-- 1 root root5069051 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 Oct9 20:01 tokenizer_config.json
-rw-r--r-- 1 root root 17098108 Oct9 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([]) tensor([])
解决方法2:通过镜像下载模型

1.访问网站:https://hf-mirror.com/
内里有具体步骤:
pip install -U huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 服务器无法连接huggingface下载模型