Huggingface国内下载
内容纲要
huggingface-cli 是 Hugging Face 官方提供的命令行工具,自带完善的下载功能。
1. 安装依赖
pip install -U huggingface_hubCopy
2. 设置环境变量
Linux
export HF_ENDPOINT=https://hf-mirror.comCopy
Windows Powershell
$env:HF_ENDPOINT = "https://hf-mirror.com"Copy
建议将上面这一行写入 ~/.bashrc。
3.1 下载模型
huggingface-cli download --resume-download gpt2 --local-dir gpt2Copy
3.2 下载数据集
huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitextCopy
可以添加 --local-dir-use-symlinks False 参数禁用文件软链接,这样下载路径下所见即所得。
Q: 有些项目需要登录,如何下载?
A:部分 Gated Repo 需登录申请许可。为保障账号安全,本站不支持登录,需先前往 Hugging Face 官网登录、申请许可,在官网这里获取 Access Token 后回镜像站用命令行下载。
部分工具下载 Gated Repo 的方法:
huggingface-cli: 添加--token参数
huggingface-cli download --token hf_*** --resume-download meta-llama/Llama-2-7b-hf --local-dir Llama-2-7b-hfCopy