
【python】下载huggingface模型报错:Last error: An error happened while trying to locate the file on the Hub 等
他提供了以下换源的方式比如 换环境变量,使用他们提供的 hfd 工具等等,具体方法这里不再赘述了,他们的官网上面提供的有使用方法(个人感觉很多方法都不好使)。二,我们可以使用hugging face或者 hf-mirror的下载工具,以 hugging face的下载工具为例。我们可以想办法确定 我们linux机器的缓存位置, 然后从能够科学上网的windows上拷贝过来。一,我们可以在win设备
参考链接:https://blog.csdn.net/weixin_43196262/article/details/135268100
1. 问题引入
很多代码中的模型的训练权重是放到 huggingface 上面的,但是这个网站对国内的是不开放的,比如运行下的代码:
model, _, transform = open_clip.create_model_and_transforms(
model_name="coca_ViT-L-14",
pretrained="mscoco_finetuned_laion2B-s13B-b90k"
)
会调用hugging face来下载权重,如果linux系统无法科学上网的时候,会报错:
FileNotFoundError: Failed to download file (open_clip_pytorch_model.bin) for laion/mscoco_finetuned_CoCa-ViT-L-14-laion2B-s13B-b90k. Last error: 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.
有下面几种处理这个问题的思路
2. 处理方法
a. 换成国内源
国内有huggingface 的镜像网站 https://hf-mirror.com/。
他提供了以下换源的方式比如 换环境变量,使用他们提供的 hfd 工具等等,具体方法这里不再赘述了,他们的官网上面提供的有使用方法(个人感觉很多方法都不好使)。
b.从另外一台机器上拷贝过去
我们可以想办法确定 我们linux机器的缓存位置, 然后从能够科学上网的windows上拷贝过来。
linux的准备
linux机器的缓存位置:默认路径是 /home/用户名/.cache/huggingface/hub/
但是即使这个缓存路径是可以自定义的:在代码中加入cache_dir=‘cache_dir’ 就可以将模型缓存到指定的路径中,此时代码变成:
model, _, transform = open_clip.create_model_and_transforms(
model_name="coca_ViT-L-14",
pretrained="mscoco_finetuned_laion2B-s13B-b90k",
cache_dir='cache_dir'
)
用于下载设备的windows的准备:
这个win设备要么能科学上网,要么能从打开镜像网站https://hf-mirror.com/。
这里有两种方法下载权重。
一,我们可以在win设备 运行我们这一段代码,将系统缓存的权重保存下来,拷贝到liunx设备中去。
那么同理,我们可以自定义缓存的路径,比如如下代码:
model, _, transform = open_clip.create_model_and_transforms(
model_name="coca_ViT-L-14",
pretrained="mscoco_finetuned_laion2B-s13B-b90k",
cache_dir='cache_dir'
)
在完成这段权重加载后,我们只需要把cache_dir 文件夹原封不动的拷贝到linux设备中即可。
二,我们可以使用hugging face或者 hf-mirror的下载工具,以 hugging face的下载工具为例
官方使用说明:https://huggingface.co/docs/huggingface_hub/guides/download
安装:
pip install -U huggingface_hub
最基本的用法:
huggingface-cli download
它至少需要明确的 模型的 用户名/模型名为参数,比如下载 knowlm-13b-ie
权重,我们需要其中使用命令
huggingface-cli download zjunlp/knowlm-13b-ie
那么如何获得这个 用户名/模型 参数,可以在hugging face或者 hf-mirror 上直接搜权重名字就可以,比如我 搜索coca_ViT-L-14 可以得到:
把图中的第一行完整的输进去下载即可。
下载好了之后再把完整的文件夹拷贝到 linux设备中。
更多推荐
所有评论(0)