关于 hugging-face-cli
介绍用于操作 Hugging Face Hub 的 `hf` 命令行界面的 skill,涵盖仓库与缓存管理、下载和上传、Hub 浏览、作业及端点操作。
主要功能
- 01登录并管理令牌
- 02下载和上传仓库文件
- 03创建和管理 Hub 仓库
- 04浏览模型、数据集和 spaces
- 05管理缓存、作业和端点
适用场景
- 01将模型下载到本地目录
- 02向 Hub 发布模型或数据集文件
- 03检查缓存或管理计算作业
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ huggingface/ skills --skill hugging-face-cli安装后在 Claude Code 中输入/hugging-face-cli确认已加载。
附带文件references/commands.mdreferences/examples.md
详细介绍
Hugging Face CLI
hf CLI 可直接在终端访问 Hugging Face Hub,用于下载、上传和管理仓库、缓存及计算资源。
快速命令参考
| 任务 | 命令 |
|---|---|
| 登录 | hf auth login |
| 下载模型 | hf download <repo_id> |
| 下载到文件夹 | hf download <repo_id> --local-dir ./path |
| 上传文件夹 | hf upload <repo_id> . . |
| 创建仓库 | hf repo create <name> |
| 创建标签 | hf repo tag create <repo_id> <tag> |
| 删除文件 | hf repo-files delete <repo_id> <files> |
| 列出缓存 | hf cache ls |
| 从缓存中移除 | hf cache rm <repo_or_revision> |
| 列出模型 | hf models ls |
| 获取模型信息 | hf models info <model_id> |
| 列出数据集 | hf datasets ls |
| 获取数据集信息 | hf datasets info <dataset_id> |
| 列出 Spaces | hf spaces ls |
| 获取 Space 信息 | hf spaces info <space_id> |
| 列出端点 | hf endpoints ls |
| 运行 GPU 作业 | hf jobs run --flavor a10g-small <image> <cmd> |
| 环境信息 | hf env |
核心命令
身份验证
hf auth login # Interactive login
hf auth login --token $HF_TOKEN # Non-interactive
hf auth whoami # Check current user
hf auth list # List stored tokens
hf auth switch # Switch between tokens
hf auth logout # Log out
下载
hf download <repo_id> # Full repo to cache
hf download <repo_id> file.safetensors # Specific file
hf download <repo_id> --local-dir ./models # To local directory
hf download <repo_id> --include "*.safetensors" # Filter by pattern
hf download <repo_id> --repo-type dataset # Dataset
hf download <repo_id> --revision v1.0 # Specific version
上传
hf upload <repo_id> . . # Current dir to root
hf upload <repo_id> ./models /weights # Folder to path
hf upload <repo_id> model.safetensors # Single file
hf upload <repo_id> . . --repo-type dataset # Dataset
hf upload <repo_id> . . --create-pr # Create PR
hf upload <repo_id> . . --commit-message="msg" # Custom message
仓库管理
hf repo create <name> # Create model repo
hf repo create <name> --repo-type dataset # Create dataset
hf repo create <name> --private # Private repo
hf repo create <name> --repo-type space --space_sdk gradio # Gradio space
hf repo delete <repo_id> # Delete repo
hf repo move <from_id> <to_id> # Move repo to new namespace
hf repo settings <repo_id> --private true # Update repo settings
hf repo list --repo-type model # List repos
hf repo branch create <repo_id> release-v1 # Create branch
hf repo branch delete <repo_id> release-v1 # Delete branch
hf repo tag create <repo_id> v1.0 # Create tag
hf repo tag list <repo_id> # List tags
hf repo tag delete <repo_id> v1.0 # Delete tag
删除仓库文件
hf repo-files delete <repo_id> folder/ # Delete folder
hf repo-files delete <repo_id> "*.txt" # Delete with pattern
缓存管理
hf cache ls # List cached repos
hf cache ls --revisions # Include individual revisions
hf cache rm model/gpt2 # Remove cached repo
hf cache rm <revision_hash> # Remove cached revision
hf cache prune # Remove detached revisions
hf cache verify gpt2 # Verify checksums from cache
浏览 Hub
# Models
hf models ls # List top trending models
hf models ls --search "MiniMax" --author MiniMaxAI # Search models
hf models ls --filter "text-generation" --limit 20 # Filter by task
hf models info MiniMaxAI/MiniMax-M2.1 # Get model info
# Datasets
hf datasets ls # List top trending datasets
hf datasets ls --search "finepdfs" --sort downloads # Search datasets
hf datasets info HuggingFaceFW/finepdfs # Get dataset info
# Spaces
hf spaces ls # List top trending spaces
hf spaces ls --filter "3d" --limit 10 # Filter by 3D modeling spaces
hf spaces info enzostvs/deepsite # Get space info
作业(云计算)
hf jobs run python:3.12 python script.py # Run on CPU
hf jobs run --flavor a10g-small <image> <cmd> # Run on GPU
hf jobs run --secrets HF_TOKEN <image> <cmd> # With HF token
hf jobs ps # List jobs
hf jobs logs <job_id> # View logs
hf jobs cancel <job_id> # Cancel job
推理端点
hf endpoints ls # List endpoints
hf endpoints deploy my-endpoint \
--repo openai/gpt-oss-120b \
--framework vllm \
--accelerator gpu \
--instance-size x4 \
--instance-type nvidia-a10g \
--region us-east-1 \
--vendor aws
hf endpoints describe my-endpoint # Show endpoint details
hf endpoints pause my-endpoint # Pause endpoint
hf endpoints resume my-endpoint # Resume endpoint
hf endpoints scale-to-zero my-endpoint # Scale to zero
hf endpoints delete my-endpoint --yes # Delete endpoint
GPU 规格: cpu-basic、cpu-upgrade、cpu-xl、t4-small、t4-medium、l4x1、l4x4、l40sx1、l40sx4、l40sx8、a10g-small、a10g-large、a10g-largex2、a10g-largex4、a100-large、h100、h100x8
常见用法
在本地下载并使用模型
# Download to local directory for deployment
hf download meta-llama/Llama-3.2-1B-Instruct --local-dir ./model
# Or use cache and get path
MODEL_PATH=$(hf download meta-llama/Llama-3.2-1B-Instruct --quiet)
发布模型/数据集
hf repo create my-username/my-model --private
hf upload my-username/my-model ./output . --commit-message="Initial release"
hf repo tag create my-username/my-model v1.0
将 Space 与本地同步
hf upload my-username/my-space . . --repo-type space \
--exclude="logs/*" --delete="*" --commit-message="Sync"
检查缓存使用情况
hf cache ls # See all cached repos and sizes
hf cache rm model/gpt2 # Remove a repo from cache
关键选项
--repo-type:model(默认)、dataset、space--revision:分支、标签或提交哈希--token:覆盖身份验证--quiet:仅输出必要信息(路径/URL)
参考资料
- 完整命令参考:参见 references/commands.md
- 工作流示例:参见 references/examples.md
评论
支持 Markdown