跳到正文
北京时间
原文
Hugging Face:Blog·· 2025-07-25精选AI 评分65

Hugging Face CLI 更名为 hf 并推出 hf jobs

Say hello to `hf`: a faster, friendlier Hugging Face CLI ✨

AI 导读

Hugging Face 宣布官方 CLI 由 huggingface-cli 更名为 hf,命令重组为 hf <resource> <action> 的统一结构,旧命令保留并提示迁移。

推荐理由

原文给出了 hf 命令的新语法、迁移对照和 hf jobs 用法示例,熟悉 huggingface-cli 的读者可以直接对照上手。

正文 · AI 翻译

我们很高兴地宣布一项期待已久的体验优化: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 的信息。

Hugging Face Jobs 仅对 Pro 用户和 Team 或 Enterprise 组织可用。升级你的计划即可开始使用!

来源:Hugging Face:Blog · huggingface.co