实验背景,尝试下载离线模型,代码报错提示:
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 IDEA-CCNL/Erlangshen-SimCSE-110M-Chinese 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'.
意思是无法访问这个网址,主要是代码会从huggingface上下载模型,但是国内又存在墙的问题,因此,我们有两种解决方式。
1. 科学上网,访问该网址
通过全局代理的方式,实现模型的下载。
2. 使用镜像网址
国内huggingface镜像地址:https://hf-mirror.com/
往下翻,直接可看到使用教程。主要有四种解决方式。最直接的方式就是一个个下载使用。
3. 在代码中增加配置
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
截取部分代码如下所示:
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
from transformers import AutoModelForCausalLM, AutoTokenizer
# access_token="Your_huggingface_access_tokens" # 有些需要token
model_name = "Qwen/Qwen2.5-1.5B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
方法三是最简单的方式,也是最直接的方式,但是记得添加代码内容放在最前面,否则无效。需要什么模型,替换名字即可实现。
4. 吐槽
md,这个问题查的过程中,好几个要付费订阅专栏,真的是醉了,至于吗一个个收费,太扯了!