huggingface-cli 是 Hugging Face 官方 CLI 工具,用于下载/上传模型与数据集、登录验证、缓存管理。
安装
1
| pip install huggingface-hub
|
登录管理
1
2
| huggingface-cli login --token "你的Token"
huggingface-cli logout
|
下载模型/数据集
1
2
3
4
5
| huggingface-cli download bert-base-chinese \
--local-dir ./bert-base-chinese \
--resume-download \
--include "*.bin" "config.json" \
--revision v1.0
|
核心参数
| 参数 | 含义 |
|---|
--repo-type | 仓库类型:model/dataset/space |
--local-dir | 本地保存路径 |
--resume-download | 断点续传 |
--include | 仅下载匹配文件 |
--exclude | 排除匹配文件 |
--revision | 指定版本/分支/Tag |
--force-download | 强制重新下载 |
缓存管理
1
2
| huggingface-cli cache list
huggingface-cli cache prune # 清理未使用缓存
|
高频示例
1
2
3
4
5
6
7
8
| # 下载 LLaMA(仅权重+配置)
huggingface-cli download meta-llama/Llama-2-7b-hf \
--local-dir ./llama-2-7b \
--resume-download \
--include "*.safetensors" "config.json"
# 下载数据集
huggingface-cli download glue --repo-type dataset --local-dir ./glue
|
Comments