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上传

相关推荐
该用户已不存在几秒前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP2 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户8356290780517 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i8 小时前
python中类的基本结构、特殊属性于MRO理解
python
liwulin05068 小时前
【ESP32-CAM】HELLO WORLD
python
Doris_20238 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_20239 小时前
Python 模式匹配match case
前端·后端·python
这里有鱼汤9 小时前
Python量化实盘踩坑指南:分钟K线没处理好,小心直接亏钱!
后端·python·程序员
大模型真好玩10 小时前
深入浅出LangGraph AI Agent智能体开发教程(五)—LangGraph 数据分析助手智能体项目实战
人工智能·python·mcp
测试老哥10 小时前
Selenium 使用指南
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例