隆重介绍 `hf`:一个更快、更友好的 Hugging Face 命令行工具 ✨
我们很高兴地宣布一项期待已久的生活质量改进:Hugging Face CLI 已正式从
huggingface-cli
更名为 hf
!
那么……为什么要做出这个改变呢?
频繁输入 huggingface-cli
很快就会让人厌烦。更重要的是,随着时间的推移,新功能(上传、下载、缓存管理、代码仓库管理等)的不断增加,CLI 的命令结构变得混乱。重命名 CLI 是一个机会,可以借此将命令重组为更清晰、更一致的格式。
我们决定不重复造轮子,而是遵循一个众所周知的 CLI 模式:hf <resource> <action>
。这种可预测的语法使得 Hugging Face CLI 更加人性化且易于探索,同时也为即将推出的功能奠定了基础。
快速入门
要开始体验新的 CLI,你需要安装最新版本的 huggingface_hub
pip install -U huggingface_hub
并重新加载你的终端会话。要测试安装是否成功,请运行 hf version
➜ hf version
huggingface_hub version: 0.34.0
接下来,让我们用 hf --help
探索新的语法
➜ hf --help
usage: hf <command> [<args>]
positional arguments:
{auth,cache,download,jobs,repo,repo-files,upload,upload-large-folder,env,version,lfs-enable-largefiles,lfs-multipart-upload}
hf command helpers
auth Manage authentication (login, logout, etc.).
cache Manage local cache directory.
download Download files from the Hub
jobs Run and manage Jobs on the Hub.
repo Manage repos on the Hub.
repo-files Manage files in a repo on the Hub.
upload Upload a file or a folder to the Hub. Recommended for single-commit uploads.
upload-large-folder
Upload a large folder to the Hub. Recommended for resumable uploads.
env Print information about the environment.
version Print information about the hf version.
options:
-h, --help show this help message and exit
正如我们所见,命令按“资源”(hf auth
, hf cache
, hf repo
等)分组。我们还将 hf upload
和 hf download
放在根级别,因为它们预计是使用最频繁的命令。
要深入了解任何命令组,只需附加 --help
➜ hf auth --help
usage: hf <command> [<args>] auth [-h] {login,logout,whoami,switch,list} ...
positional arguments:
{login,logout,whoami,switch,list}
Authentication subcommands
login Log in using a token from huggingface.co/settings/tokens
logout Log out
whoami Find out which huggingface.co account you are logged in as.
switch Switch between access tokens
list List all stored access tokens
options:
-h, --help show this help message and exit
🔀 迁移指南
如果你习惯使用 huggingface-cli
,大多数命令看起来会很熟悉。最大的变化是身份验证部分
huggingface-cli login
# became
hf auth login
huggingface-cli whoami
# became
hf auth whoami
huggingface-cli logout
# became
hf auth logout
所有 auth
命令都已与现有的 hf auth switch
(用于在不同本地配置文件之间切换)和 hf auth list
(用于列出本地配置文件)归组在一起。
旧版的 huggingface-cli
仍然可用且功能齐全。我们会保留它以简化过渡过程。如果你使用旧版 CLI 的任何命令,你会看到一个警告,指引你使用新的等效 CLI 命令
➜ huggingface-cli whoami
⚠️ Warning: 'huggingface-cli whoami' is deprecated. Use 'hf auth whoami' instead.
Wauplin
orgs: huggingface,competitions,hf-internal-testing,templates,HF-test-lab,Gradio-Themes,autoevaluate,HuggingFaceM4,HuggingFaceH4,open-source-metrics,sd-concepts-library,hf-doc-build,hf-accelerate,HFSmolCluster,open-llm-leaderboard,pbdeeplinks,discord-community,llhf,sllhf,mt-metrics,DDUF,hf-inference,changelog,tiny-agents
还有一件事... 💥 hf jobs
我们忍不住要发布我们第一个专属命令:hf jobs。
Hugging Face Jobs 是一项新服务,可让你在 Hugging Face 基础设施上,使用你选择的硬件规格来运行任何脚本或 Docker 镜像。计费方式为“按需付费”,即你只需为你使用的秒数付费。以下是如何启动你的第一个命令
# Run "nvidia-smi" on an A10G GPU
hf jobs run --flavor=a10g-small ubuntu nvidia-smi
该 CLI 的设计深受 Docker 那些熟悉的命令的启发
➜ hf jobs --help
usage: hf <command> [<args>] jobs [-h] {inspect,logs,ps,run,cancel,uv} ...
positional arguments:
{inspect,logs,ps,run,cancel,uv}
huggingface.co jobs related commands
inspect Display detailed information on one or more Jobs
logs Fetch the logs of a Job
ps List Jobs
run Run a Job
cancel Cancel a Job
uv Run UV scripts (Python with inline dependencies) on HF infrastructure
options:
-h, --help show this help message and exit
通过阅读指南了解更多关于 Jobs 的信息。