huggingface加速

方法一:huggingface-cli

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

  1. 安装依赖
bash 复制代码
pip install -U huggingface_hub
  1. 设置环境变量: Linux
bash 复制代码
export HF_ENDPOINT=https://hf-mirror.com

建议将上面这一行写入~/.bashrc 。

3.1 下载模型

bash 复制代码
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 参数禁用文件软链接,这样下载路径下所见即所得,语句中gpt2和wikitext为模型名和数据集名称根据需要可替换。
方法二:使用hfd

  1. 下载hfd
bash 复制代码
wget https://hf-mirror.com/hfd/hfd.sh && chmod a+x hfd.sh
  1. 设置环境变量: Linux
bash 复制代码
export HF_ENDPOINT=https://hf-mirror.com

3.1 下载模型

bash 复制代码
./hfd.sh gpt2 --tool aria2c-x4

3.2 下载数据集

bash 复制代码
./hfd.sh wikitext --dataset --tool aria2c -x4

语句中gpt2和wikitext为模型名和数据集名称根据需要可替换,aria2c为预装工具,安装口令:'apt update && apt install aria2'

部分 Gated Repo 问题

部分Gated Repo需登陆申请许可。前往Hugging Face获取AccessToken后使用命令行下载。

部分工具下载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_***

注:容器内下载存在限速,下载大数据集或大模型时,建议本地下载后再使用SFTP上传

相关推荐
Mqh18076233 分钟前
day61 经典时序模型3
python
我想吃烤肉肉35 分钟前
logger比print优秀之处
python
Cosmoshhhyyy40 分钟前
《Effective Java》解读第32条:谨慎并用泛型和可变参数
java·python
Cherry的跨界思维1 小时前
【AI测试全栈:Vue核心】19、Vue3+ECharts实战:构建AI测试可视化仪表盘全攻略
前端·人工智能·python·echarts·vue3·ai全栈·ai测试全栈
海棠AI实验室1 小时前
第十七章 调试与排错:读懂 Traceback 的方法论
python·pandas·调试
2501_941878741 小时前
在奥克兰云原生实践中构建动态配置中心以支撑系统稳定演进的工程经验总结
开发语言·python
Rabbit_QL1 小时前
【Pytorch使用】CUDA 显存管理与 OOM 排查实战:以 PyTorch 联邦学习训练为例
人工智能·pytorch·python
weixin_443297881 小时前
Python打卡训练营第31天
开发语言·python
宏基骑士1 小时前
Python之类中函数间的参数传递(有继承和无继承)
python
540_5401 小时前
ADVANCE Day41
人工智能·python·深度学习