couldn’t connect to ‘https://huggingface.co’ 问题解决

一般来说这类都是访问不了huggingface导致的,我遇到具体问题描述如下

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 bert-base-uncased is not the path to a directory containing a file named config.json.

可以提供通过将资源下载到本地解决,这里我通过huggingface镜像站下载的方式解决

Step1 安装依赖
pip install -U huggingface_hub
Step2 设置环境变量
export HF_ENDPOINT=https://hf-mirror.com
Step3 下载资源
huggingface-cli download --resume-download --local-dir-use-symlinks False bert-base-uncased --local-dir bert-base-uncased
Step4 替换路径

由于每个人遇到的资源问题不一致,一版都是 tokenizer 的问题,而且报错是都会有堆栈信息,大家稍加细心便能发现问题

#model = AutoModelWithHeads.from_pretrained("bert-base-uncased")
model = AutoModelWithHeads.from_pretrained("资源本地路径", local_files_only=True)

#tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
tokenizer = AutoTokenizer.from_pretrained("资源本地路径", local_files_only=True)
Logo

鸿蒙生态一站式服务平台。

更多推荐