🤗 Huggingface 镜像站

热门排行🔥

全部
模型
数据集

如何使用镜像站🌟

本站域名 hf-mirror.com,用于镜像 huggingface.co 域名。作为一个公益项目,致力于帮助国内AI开发者快速、稳定的下载模型、数据集。捐赠支持请看网页左下角,感谢支持!
更多详细用法请看《这篇教程》

方法一:网页下载

在本站搜索,并在模型主页的Files and Version中下载文件。

方法二:huggingface-cli

huggingface-cli 是 Hugging Face 官方提供的命令行工具,自带完善的下载功能。

1. 安装依赖
pip install -U huggingface_hub
2. 设置环境变量
Linux
export HF_ENDPOINT=https://hf-mirror.com
Windows Powershell
$env:HF_ENDPOINT = "https://hf-mirror.com"
建议将上面这一行写入 ~/.bashrc
3.1 下载模型
huggingface-cli download --resume-download gpt2 --local-dir gpt2
3.2 下载数据集
huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitext
可以添加 --local-dir-use-symlinks False 参数禁用文件软链接,这样下载路径下所见即所得,详细解释请见上面提到的教程。

方法三:使用 hfd

hfd 是本站开发的 huggingface 专用下载工具,基于成熟工具 git+aria2,可以做到稳定下载不断线。

1. 下载hfd
wget https://hf-mirror.com/hfd/hfd.sh
chmod a+x hfd.sh
2. 设置环境变量
Linux
export HF_ENDPOINT=https://hf-mirror.com
Windows Powershell
$env:HF_ENDPOINT = "https://hf-mirror.com"
3.1 下载模型
./hfd.sh gpt2 --tool aria2c -x 4
3.2 下载数据集
./hfd.sh wikitext --dataset --tool aria2c -x 4

方法四:使用环境变量(非侵入式)

非侵入式,能解决大部分情况。huggingface 工具链会获取HF_ENDPOINT环境变量来确定下载文件所用的网址,所以可以使用通过设置变量来解决。

HF_ENDPOINT=https://hf-mirror.com python your_script.py
                
不过有些数据集有内置的下载脚本,那就需要手动改一下脚本内的地址来实现了。

常见问题

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-hf
                        
hfd: 添加--hf_username--hf_token参数
                            hfd meta-llama/Llama-2-7b --hf_username YOUR_HF_USERNAME --hf_token hf_***
                        
其余如from_pretrainedwgetcurl如何设置认证 token,详见上面第一段提到的教程。