hf 是 Hugging Face Hub 的命令行工具,取代已弃用的 huggingface-cli。安装:curl -LsSf https://hf.co/cli/install.sh | bash -s。用 hf --help 查看功能,认证命令统一在 hf auth 下,例如 hf auth whoami。
主要能力:用 hf download REPO_ID 下载文件;用 hf upload 上传文件或文件夹(适合单次提交),用 hf upload-large-folder 上传大文件夹(支持断点续传);hf sync 在本地目录与 bucket 间同步;hf cache 管理本地缓存;hf repos、hf models、hf datasets、hf spaces 管理仓库与资源;hf discussions 管理讨论和拉取请求;hf collections 管理集合;hf endpoints 管理推理端点;hf jobs 运行与调度任务;hf webhooks 管理 Webhook;hf papers 浏览与检索论文;hf skills 安装 AI 助手技能。
通用选项:--format json 或 table 控制输出,-q/--quiet 精简输出,--revision 指定分支、标签或提交,--token 使用访问令牌(建议改用 HF_TOKEN 环境变量),--type 指定仓库类型(model、dataset 或 space)。
挂载仓库为本地文件系统可用 hf-mount,按需拉取文件、无需完整下载,安装:curl -fsSL https://raw.githubusercontent.com/huggingface/hf-mount/main/install.sh | sh,例如 hf-mount start repo openai-community/gpt2 /tmp/gpt2 为只读挂载,加 --hf-token $HF_TOKEN 挂载 bucket 可读写,hf-mount status 与 hf-mount stop 用于查看和卸载。
上传前可先做预检查:用 hf auth whoami --format json 确认账号;用 curl -sI -H "Authorization: Bearer $HF_TOKEN" https://huggingface.co/api/whoami-v2 | grep -i '^ratelimit' 查看限流余量,响应头形如 RateLimit: "api";r=<remaining>;t=<seconds-to-reset>,超出会返回 429。存储配额无公开 API,需前往计费面板查看(用户 https://huggingface.co/settings/billing,组织 https://huggingface.co/organizations//billing)。上传与提交相关的具体限额官方未公开且经常变动。