隆重介紹 `hf`:一個更快、更友好的 Hugging Face 命令列工具 ✨

釋出於 2025 年 7 月 25 日
在 GitHub 上更新

我們很高興地宣佈一項期待已久的生活質量改進: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 uploadhf 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 使用者以及 團隊或企業組織開放。升級你的套餐即可開始使用!

社群

文章作者

第一個!

註冊登入 以發表評論

© . This site is unofficial and not affiliated with Hugging Face, Inc.