一、Huggingface镜像站的使用方法

使用Huggingface镜像站非常简单,只需要按照以下步骤进行设置即可:

安装依赖:首先,确保你的计算机上已经安装了pip这个Python包管理工具。然后,通过以下命令安装huggingface_hub和hf_transfer这两个库:

1
pip install -U huggingface_hub hf_transfer

如果你想使用清华源加速下载,可以加上-i https://pypi.tuna.tsinghua.edu.cn/simple参数:

1
pip install -U huggingface_hub hf_transfer -i https://pypi.tuna.tsinghua.edu.cn/simple

设置环境变量:接下来,设置环境变量HF_ENDPOINT为Huggingface镜像站的地址:

1
export HF_ENDPOINT=https://hf-mirror.com

这样,后续的命令就会使用这个镜像站点而非Huggingface的主仓库。

下载模型:现在,你可以使用huggingface-cli命令来下载模型了。例如,要下载名为“openai-community/gpt2-medium”的模型,可以运行以下命令:

1
huggingface-cli download --resume-download openai-community/gpt2-medium --local-dir /path/to/local/directory

其中,–local-dir参数指定了模型下载的本地目录。你可以将其替换为你想要保存模型的路径。

下载需要登录的模型(Gated Model)
请添加–token hf_***参数,其中hf_***是 access token,请在huggingface官网这里获取(账号 – setting – token)。示例:

1
2
huggingface-cli download --token hf_*** --resume-download meta-llama/Meta-Llama-3-8B-Instruct
# huggingface-cli download --token hf_*** --resume-download bigscience/bloom-560m --local-dir bloom-560m

也可以登录账号再拉取数据:

1
2
pip install --upgrade huggingface_hub
huggingface-cli login

二、使用url直接下载

使用url直接下载时,将 huggingface.co 直接替换为本站域名hf-mirror.com。使用浏览器或者 wget -c、curl -L、aria2c 等命令行方式即可。

参考

  1. Huggingface 镜像站:提升国内访问速度与稳定性 https://cloud.baidu.com/article/3251091