Hub Python Library documentation
命令行界面(CLI)
命令行界面(CLI)
huggingface_hub Python 包内置了一个名为 hf 的命令行界面(CLI)。该工具允许你直接在终端中与 Hugging Face Hub 进行交互。例如,你可以登录账户、创建仓库、上传和下载文件等。它还提供了便捷的实用功能,用于配置你的机器或管理缓存。在本指南中,我们将介绍该 CLI 的主要功能及其使用方法。
本指南介绍了
hfCLI 最重要的功能。 有关所有命令和选项的完整参考,请参阅 CLI 参考。
使用
hfCLI 搭配 AI 智能体?请安装 Skill 并查看 Hugging Face CLI for AI Agents 指南。# works with Claude Code, Codex, Cursor, OpenCode, Pi and any agent that loads skills from `.agents/skills` hf skills add独立安装程序会为您完成安装(见下文),
hf update则会对其进行更新。
入门
独立安装程序(推荐)
您可以通过一条命令安装 hf CLI:
在 macOS 和 Linux 上:
>>> curl -LsSf https://hf.co/cli/install.sh | bash在 Windows 上:
>>> powershell -ExecutionPolicy ByPass -c "irm https://hf.co/cli/install.ps1 | iex"安装程序还会全局安装 hf-cli 技能,供 Claude Code 以及任何读取 ~/.agents/skills 的代理使用。传入 --exclude-skill 可跳过该步骤:
>>> curl -LsSf https://hf.co/cli/install.sh | bash -s -- --exclude-skill>>> powershell -ExecutionPolicy ByPass -c "& ([scriptblock]::Create((irm https://hf.co/cli/install.ps1))) -ExcludeSkill"安装完成后,您可以检查 CLI 是否已正确配置:
>>> hf --help
Usage: hf [OPTIONS] COMMAND [ARGS]...
Hugging Face Hub CLI
Options:
--skills Print the `hf-cli` SKILL.md to stdout (alias for `hf skills preview`).
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or customize the installation.
-h, --help Show this message and exit.
Main commands:
auth Manage authentication (login, logout, etc.).
buckets Commands to interact with buckets.
cache Manage local cache directory.
collections Interact with collections on the Hub.
datasets Interact with datasets on the Hub.
download Download files from the Hub.
endpoints Manage Hugging Face Inference Endpoints.
extensions Manage hf CLI extensions.
jobs Run and manage Jobs on the Hub.
models Interact with models on the Hub.
papers Interact with papers on the Hub.
repos Manage repos on the Hub.
skills Manage skills for AI assistants.
spaces Interact with spaces on the Hub.
sync Sync files between local directory and a bucket.
upload Upload a file or a folder to the Hub.
Help commands:
env Print information about the environment.
version Print information about the hf version.如果 CLI 安装正确,您应该能看到 CLI 中所有可用选项的列表。如果出现诸如 command not found: hf 的错误信息,请参阅 安装 指南。
--help选项对于获取命令的更多详细信息非常方便。您可以随时使用它来列出所有可用选项及其详细信息。例如,hf upload --help提供了有关如何使用 CLI 上传文件的更多信息。
使用 uv
使用 uvx 是使用 hf CLI 最简单的方式。它始终在隔离环境中运行最新版本——无需安装!
请确保已先安装 uv。有关说明,请参阅 uv 安装指南。
然后直接使用 CLI:
>>> uvx hf auth login
>>> uvx hf download
>>> uvx hf ...
uvx hf使用的是hfPyPI 包。
使用 pip 安装
CLI 也随核心 huggingface_hub 包一起发布:
>>> pip install -U "huggingface_hub"使用 Homebrew
您也可以通过 Homebrew 安装 CLI:
>>> brew install hf有关更多详细信息,请访问 此处 的 Homebrew huggingface 页面。
更新
要升级到最新版本,请运行:
>>> hf update此操作会检测 hf 的安装方式(Homebrew、独立安装程序或 pip),并执行相应的更新命令。如果 hf-cli 技能已全局安装,它也会随之刷新,以便代理看到新的命令界面。如果未安装,则保持未安装状态:如果您之前跳过或移除了它,更新操作不会将其重新安装。
默认情况下,当 PyPI 上有更新版本可用时,CLI 还会向 stderr 打印一行黄色警告。若要将其静默(例如在离线 CI 中),请设置 HF_HUB_DISABLE_UPDATE_CHECK=1。
输出格式
大多数 hf 命令都接受同一组全局格式标志。这些标志在每页 --help 的专用 Formatting options 部分中有说明,并且可以添加到任何命令中,而无需为每个命令单独声明:
| 标志 | 等效 | 描述 |
|---|---|---|
--format <value> | — | 明确选择输出格式。可接受的值为:auto(默认值)、human、agent、json、quiet。 |
--json | --format json | 打印结构化 JSON。便于通过管道传递给 jq 或其他脚本。 |
-q, --quiet | --format quiet | 仅打印 ID(每行一个)。适用于将 ID 通过管道传递给其他命令。 |
--no-truncate | — | 在人类可读的表格中显示完整值,而不是用 ... 截断长值。表格可能会超出终端宽度。对于列表/字典列的结构化输出,请使用 --format json。 |
auto(默认值)在交互式终端下选择 human,在 CLI 由 AI 智能体调用时选择 agent。human 会添加颜色和美观的表格;agent 生成无截断的制表符分隔值;json 输出紧凑的 JSON 对象或数组。同时使用两个输出模式标志(例如 --json 与 --format human 一起使用)会引发用法错误。
Human 表格会根据终端宽度自动调整:仅当自然宽度超出屏幕时,最宽的列才会被截断(因此在宽终端中,您通常可以看到完整值,而不会出现 ...)。传入 --no-truncate 可强制显示完整值,无论宽度如何;使用 --format json 可获取列表/字典列的结构化输出。
# JSON output for scripting
>>> hf models ls --search bert --limit 2 --json | jq '.[].id'
# IDs only, one per line
>>> hf collections ls --owner nvidia -q
nvidia/nemotron-supervised-fine-tuning-69eab9824c9120a3a3b1e25e
nvidia/nvidia-nemotron-v3-69388dda16167bb1607171eahf auth login
在许多情况下,你必须登录 Hugging Face 账户才能与 Hub 进行交互(下载私有仓库、上传文件、创建 PR 等)。为此,请在终端中运行以下命令:
>>> hf auth login如果您已登录,此命令将跳过提示并显示一条消息。若要强制重新登录(例如切换令牌),请使用 --force:
>>> hf auth login --force默认情况下,该命令会通过浏览器为您登录:它会打印一个 URL 和一个简短的代码。打开该 URL,输入代码,批准请求,CLI 便会获取并在您的机器上保存一个访问令牌。令牌会在一段时间后过期,但只要您持续使用它,就会自动刷新。
? How would you like to log in? [Use arrows, Enter to confirm]
> Log in with your browser
Paste an access token
Open this URL in your browser:
https://huggingface.co/oauth/device
And enter the code: ABCD-EFGH
Waiting for authorization...
Token is valid.
The token `oauth-wauplin` has been saved to /home/wauplin/.cache/huggingface/stored_tokens
Your token has been saved to /home/wauplin/.cache/huggingface/token
Login successful.你也可以选择粘贴从你的设置页面生成的用户访问令牌,可以通过交互式方式(选择粘贴访问令牌)或直接从命令行进行。为了更安全,我们建议将令牌作为环境变量传递,以避免将其粘贴到命令历史中。
# Or using an environment variable
>>> hf auth login --token $HF_TOKEN --add-to-git-credential
Token is valid (permission: write).
The token `token_name` has been saved to /home/wauplin/.cache/huggingface/stored_tokens
Your token has been saved in your configured git credential helpers (store).
Your token has been saved to /home/wauplin/.cache/huggingface/token
Login successful
The current active token is: `token_name`当由 AI 代理运行时(自动检测,或使用 --format agent),该命令不会发出任何提示:它会执行浏览器流程,并输出代理可以转达给用户的纯文本说明,然后等待授权:
>>> hf auth login --format agent
Ask the user to open https://huggingface.co/oauth/device in a browser and enter the code ABCD-EFGH. The code expires in 900 seconds. Waiting for authorization...
Login successful: logged in as wauplin (token saved as 'oauth-wauplin').hf auth login 是交互式命令,因此不支持 --format json 和 --format quiet:对于脚本化的非交互式登录,请传入 --token。
有关身份验证的更多详细信息,请参阅此部分。
hf auth whoami
如果您想确认自己是否已登录,可以使用 hf auth whoami。该命令没有任何选项,仅会在 Hub 上打印您的用户名以及您所属的组织:
hf auth whoami
Wauplin
orgs: huggingface,eu-test,OAuthTesters,hf-accelerate,HFSmolCluster如果未登录,系统将打印一条错误消息。
hf auth logout
此命令将您登出。实际上,它会删除您机器上存储的所有令牌。如果您想删除特定的令牌,可以将令牌名称作为参数指定。
如果您使用 HF_TOKEN 环境变量登录(参见参考),此命令不会使您退出登录。在这种情况下,您必须在机器配置中取消设置该环境变量。
hf download
使用 hf download 命令可直接从 Hub 下载文件。其内部使用了 下载 指南中介绍的 hf_hub_download() 和 snapshot_download() 辅助函数,并将返回的路径打印到终端。在下面的示例中,我们将介绍最常见的用例。要查看所有可用选项的完整列表,可以运行:
hf download --help下载单个文件
要从仓库中下载单个文件,只需按以下方式提供 repo_id 和文件名:
>>> hf download gpt2 config.json
downloading https://huggingface.co/gpt2/resolve/main/config.json to /home/wauplin/.cache/huggingface/hub/tmpwrq8dm5o
(…)ingface.co/gpt2/resolve/main/config.json: 100%|██████████████████████████████████| 665/665 [00:00<00:00, 2.49MB/s]
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/11c5a3d5811f50298f278a704980280950aedb10/config.json该命令始终会在最后一行打印出本地机器上文件的路径。
要下载位于仓库子目录中的文件,您应该以 posix 格式提供该文件在仓库中的路径,例如:
>>> hf download HiDream-ai/HiDream-I1-Full text_encoder/model.safetensors下载整个仓库
在某些情况下,您可能只想下载仓库中的所有文件。只需指定仓库 ID 即可实现:
>>> hf download HuggingFaceH4/zephyr-7b-beta
Fetching 23 files: 0%| | 0/23 [00:00<?, ?it/s]
...
...
/home/wauplin/.cache/huggingface/hub/models--HuggingFaceH4--zephyr-7b-beta/snapshots/3bac358730f8806e5c3dc7c7e19eb36e045bf720下载多个文件
您还可以通过一条命令从仓库中下载文件的子集。这可以通过两种方式实现。如果您已经拥有要下载的文件的确切列表,只需按顺序提供它们即可:
>>> hf download gpt2 config.json model.safetensors
Fetching 2 files: 0%| | 0/2 [00:00<?, ?it/s]
downloading https://huggingface.co/gpt2/resolve/11c5a3d5811f50298f278a704980280950aedb10/model.safetensors to /home/wauplin/.cache/huggingface/hub/tmpdachpl3o
(…)8f278a7049802950aedb10/model.safetensors: 100%|██████████████████████████████| 8.09k/8.09k [00:00<00:00, 40.5MB/s]
Fetching 2 files: 100%|████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 3.76it/s]
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/11c5a3d5811f50298f278a704980280950aedb10另一种方法是使用 --include 和 --exclude 提供模式,以筛选要下载的文件。例如,如果您想从 stabilityai/stable-diffusion-xl-base-1.0 下载所有 safetensors 文件,但排除 FP16 精度的文件:
>>> hf download stabilityai/stable-diffusion-xl-base-1.0 --include "*.safetensors" --exclude "*.fp16.*"*
Fetching 8 files: 0%| | 0/8 [00:00<?, ?it/s]
...
...
Fetching 8 files: 100%|█████████████████████████████████████████████████████████████████████████| 8/8 (...)
/home/wauplin/.cache/huggingface/hub/models--stabilityai--stable-diffusion-xl-base-1.0/snapshots/462165984030d82259a11f4367a4eed129e94a7b下载数据集、Space 或内核
上述示例展示了如何从模型仓库下载。要下载数据集、Space 或 kernel,请使用 --repo-type 选项:
# https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k
>>> hf download HuggingFaceH4/ultrachat_200k --repo-type dataset
# https://huggingface.co/spaces/HuggingFaceH4/zephyr-chat
>>> hf download HuggingFaceH4/zephyr-chat --repo-type space
...下载特定版本
上述示例展示了如何从主分支的最新提交下载。要从特定版本(提交哈希、分支名称或标签)下载,请使用 --revision 选项:
>>> hf download bigcode/the-stack --repo-type dataset --revision v1.1
...使用 hf:// URI
您可以提供一个单独的 hf:// URI,而无需将仓库类型、修订版本和文件路径作为独立的参数和选项传入。该 URI 一次性编码了所有信息,其语法为 hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>](完整语法请参阅 HF URIs 参考):
# Equivalent to: hf download bigcode/the-stack --repo-type dataset --revision v1.1
>>> hf download hf://datasets/bigcode/the-stack@v1.1
# Download a single file from a specific revision
>>> hf download hf://datasets/HuggingFaceM4/FineVision@refs/pr/1/data/train.parquet
# Download a subfolder (note the trailing slash)
>>> hf download hf://datasets/HuggingFaceM4/FineVision/art/
# A bare id still works and defaults to a model repo
>>> hf download hf://openai-community/gpt2/config.json当提供 URI 时,--repo-type 和 --revision 也不能被设置,因为它们已经是 URI 的一部分(否则将引发错误),并且 URI 中嵌入的文件路径不能与位置参数文件名组合使用。路径末尾的 / 表示子文件夹(与位置参数相同)。包含 / 的分支名称必须 URL 编码为 %2F(例如 hf://my-org/my-model@feature%2Ffoo)。
下载到本地文件夹
从 Hub 下载文件的推荐(也是默认)方式是使用缓存系统。但在某些情况下,您可能希望下载文件并将其移动到特定文件夹。这有助于使工作流更接近 git 命令所提供的体验。您可以使用 --local-dir 选项来实现这一点。
在本地目录的根目录下会创建一个 .cache/huggingface/ 文件夹,其中包含已下载文件的元数据。如果文件已是最新,这将避免重复下载。如果元数据已更改,则会下载新版本的文件。这使得 local-dir 能够优化为仅拉取最新的更改。
有关将文件下载到本地的更多详细信息,请参阅 download 指南。
>>> hf download adept/fuyu-8b model-00001-of-00002.safetensors --local-dir fuyu
...
fuyu/model-00001-of-00002.safetensors试运行模式
在某些情况下,您可能希望在真正下载之前先检查哪些文件将被下载。您可以使用 --dry-run 参数来执行此操作。它会列出仓库中所有待下载的文件,并检查它们是否已经下载。这有助于了解需要下载的文件数量及其大小。
>>> hf download openai-community/gpt2 --dry-run
[dry-run] Fetching 26 files: 100%|█████████████| 26/26 [00:04<00:00, 6.26it/s]
[dry-run] Will download 11 files (out of 26) totalling 5.6G.
File Bytes to download
--------------------------------- -----------------
.gitattributes -
64-8bits.tflite 125.2M
64-fp16.tflite 248.3M
64.tflite 495.8M
README.md -
config.json -
flax_model.msgpack 497.8M
generation_config.json -
merges.txt -
model.safetensors 548.1M
onnx/config.json -
onnx/decoder_model.onnx 653.7M
onnx/decoder_model_merged.onnx 655.2M
onnx/decoder_with_past_model.onnx 653.7M
onnx/generation_config.json -
onnx/merges.txt -
onnx/special_tokens_map.json -
onnx/tokenizer.json -
onnx/tokenizer_config.json -
onnx/vocab.json -
pytorch_model.bin 548.1M
rust_model.ot 702.5M
tf_model.h5 497.9M
tokenizer.json -
tokenizer_config.json -
vocab.json -有关更多详细信息,请参阅下载指南。
指定缓存目录
如果未使用 --local-dir,所有文件默认会下载到由 HF_HOME 环境变量 定义的缓存目录中。您可以使用 --cache-dir 指定自定义缓存:
>>> hf download adept/fuyu-8b --cache-dir ./path/to/cache
...
./path/to/cache/models--adept--fuyu-8b/snapshots/ddcacbcf5fdf9cc59ff01f6be6d6662624d9c745指定一个标记
要访问私有或受控仓库,必须使用令牌。默认情况下,将使用本地保存的令牌(通过 hf auth login 保存)。若要显式进行身份验证,请使用 --token 选项:
>>> hf download gpt2 config.json --token=hf_****
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/11c5a3d5811f50298f278a704980280950aedb10/config.json安静模式
默认情况下,hf download 命令会输出详细信息,包括警告消息、已下载文件的信息以及进度条。如果您希望静默所有这些输出,请使用 --quiet 选项。此时仅会打印最后一行(即已下载文件的路径)。如果您希望在脚本中将输出传递给其他命令,这可能会非常有用。
>>> hf download gpt2 --quiet
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/11c5a3d5811f50298f278a704980280950aedb10下载超时
在连接较慢的机器上,您可能会遇到如下超时问题:
`httpx2.TimeoutException: (TimeoutException("HTTPSConnectionPool(host='cdn-lfs-us-1.huggingface.co', port=443): Read timed out. (read timeout=10)"), '(Request ID: a33d910c-84c6-4514-8362-c705e2039d38)')`为缓解此问题,您可以将 HF_HUB_DOWNLOAD_TIMEOUT 环境变量设置为更高的值(默认值为 10):
export HF_HUB_DOWNLOAD_TIMEOUT=30有关更多详细信息,请参阅环境变量参考。然后重新运行您的下载命令。
hf upload
使用 hf upload 命令可直接将文件上传到 Hub。其内部使用了 Upload 指南中介绍的 upload_file() 和 upload_folder() 辅助函数。在下面的示例中,我们将介绍最常见的用例。要查看所有可用选项的完整列表,可以运行:
>>> hf upload --help上传整个文件夹
此命令的默认用法为:
# Usage: hf upload [repo_id] [local_path] [path_in_repo]要在仓库的根目录上传当前目录,请使用:
>>> hf upload my-cool-model . .
https://huggingface.co/Wauplin/my-cool-model/tree/main/如果该仓库尚不存在,系统将自动创建它。
您也可以上传特定的文件夹:
>>> hf upload my-cool-model ./models .
https://huggingface.co/Wauplin/my-cool-model/tree/main/最后,您可以将文件夹上传到仓库中的特定位置:
>>> hf upload my-cool-model ./path/to/curated/data /data/train
https://huggingface.co/Wauplin/my-cool-model/tree/main/data/train上传单个文件
你还可以通过将 local_path 设置为指向本地机器上的文件来上传单个文件。在这种情况下,path_in_repo 是可选的,默认值为你本地文件的名称:
>>> hf upload Wauplin/my-cool-model ./models/model.safetensors
https://huggingface.co/Wauplin/my-cool-model/blob/main/model.safetensors如果要上传单个文件到特定目录,请相应地设置 path_in_repo:
>>> hf upload Wauplin/my-cool-model ./models/model.safetensors /vae/model.safetensors
https://huggingface.co/Wauplin/my-cool-model/blob/main/vae/model.safetensors上传多个文件
若要一次性从文件夹上传多个文件而不上传整个文件夹,请使用 --include 和 --exclude 模式。它还可以与 --delete 选项结合使用,在上传新文件的同时删除仓库中的文件。在下面的示例中,我们通过删除远程文件并上传除 /logs 之外的所有文件来同步本地 Space:
# Sync local Space with Hub (upload new files except from logs/, delete removed files)
>>> hf upload Wauplin/space-example --repo-type=space --exclude="/logs/*" --delete="*" --commit-message="Sync local Space with Hub"
...上传到数据集或 Space
要上传到数据集或 Space,请使用 --repo-type 选项:
>>> hf upload Wauplin/my-cool-dataset ./data /train --repo-type=dataset
...上传到组织
要将内容上传到组织拥有的仓库而非个人仓库,您必须在 repo_id 中明确指定:
>>> hf upload MyCoolOrganization/my-cool-model . .
https://huggingface.co/MyCoolOrganization/my-cool-model/tree/main/上传到特定版本
默认情况下,文件会上传到 main 分支。如果您想将文件上传到其他分支或引用,请使用 --revision 选项:
# Upload files to a PR
>>> hf upload bigcode/the-stack . . --repo-type dataset --revision refs/pr/104
...注意:如果 revision 不存在且未设置 --create-pr,则会自动从 main 分支创建一个分支。
使用 hf:// URI
与 hf download 一样,目标可以表示为单个 hf:// URI,其语法为 hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>](完整语法请参阅 HF URIs 参考)。仓库类型、修订版本和 path_in_repo 均从 URI 中读取:
# Equivalent to: hf upload Wauplin/my-cool-dataset ./train.csv data/train.csv --repo-type dataset --revision my-branch
>>> hf upload hf://datasets/Wauplin/my-cool-dataset@my-branch/data/train.csv ./train.csv
# Upload a whole folder to the root of a model repo
>>> hf upload hf://Wauplin/my-cool-model ./models当提供 URI 时,--repo-type 和 --revision 也不能被设置,因为它们已经是 URI 的一部分(否则将引发错误),并且 URI 中嵌入的路径不能与 path_in_repo 参数组合使用。
上传并创建 PR
如果您没有向仓库推送的权限,则必须打开一个 PR 并告知作者您想要进行的更改。可以通过设置 --create-pr 选项来实现:
# Create a PR and upload the files to it
>>> hf upload bigcode/the-stack . . --repo-type dataset --revision refs/pr/104
https://huggingface.co/datasets/bigcode/the-stack/blob/refs%2Fpr%2F104/定期上传
在某些情况下,您可能希望定期向仓库推送更新。例如,如果您正在训练模型并希望每 10 分钟上传一次日志文件夹,这就会很有用。您可以使用 --every 选项来实现:
# Upload new logs every 10 minutes
hf upload training-model logs/ --every=10指定提交信息
使用 --commit-message 和 --commit-description 来为提交设置自定义消息和描述,而不是使用默认值
>>> hf upload Wauplin/my-cool-model ./models . --commit-message="Epoch 34/50" --commit-description="Val accuracy: 68%. Check tensorboard for more details."
...
https://huggingface.co/Wauplin/my-cool-model/tree/main指定一个标记
要上传文件,必须使用令牌。默认情况下,将使用本地保存的令牌(通过 hf auth login 保存)。若要显式进行身份验证,请使用 --token 选项:
>>> hf upload Wauplin/my-cool-model ./models . --token=hf_****
...
https://huggingface.co/Wauplin/my-cool-model/tree/main安静模式
默认情况下,hf upload 命令会输出详细信息,包括警告消息、已上传文件的信息以及进度条。如果您希望静默所有这些输出,请使用 --quiet 选项。此时仅会打印最后一行(即已上传文件的 URL)。如果您希望在脚本中将输出传递给其他命令,这会非常有用。
>>> hf upload Wauplin/my-cool-model ./models . --quiet
https://huggingface.co/Wauplin/my-cool-model/tree/mainhf buckets
使用 hf buckets 来管理 Hugging Face Hub 上的 buckets。Buckets 在 Hugging Face 上提供类似 S3 的对象存储,由 Xet 存储后端提供支持。与基于 git 并跟踪文件历史的仓库不同,buckets 是远程对象存储容器,专为大规模文件设计,并支持基于内容寻址的去重。它们适用于需要简单、快速、可变更存储的场景,例如存储训练检查点、日志、中间产物,或任何无需版本控制的大型文件集合。在下面的示例中,我们将介绍最常见的用例。完整指南请参阅 Buckets 指南。
创建存储桶
要创建新的 bucket,请使用 hf buckets create。默认情况下,该 bucket 将在您的命名空间下创建:
>>> hf buckets create my-bucket您也可以使用 --private 标志创建私有存储桶:
>>> hf buckets create my-bucket --private列出并检查存储桶
要列出所有存储桶,请使用 hf buckets list(或其简写 hf buckets ls)。您也可以在特定组织中列出存储桶:
>>> hf buckets list
ID PRIVATE SIZE TOTAL_FILES CREATED_AT
-------------------- ------- ---------- ----------- ----------
username/my-bucket 32 5 2026-02-16
username/checkpoints 117609095 700 2026-02-13
username/logs 321757477 2000 2026-02-13
# Human-readable sizes
>>> hf buckets list -h
ID PRIVATE SIZE TOTAL_FILES CREATED_AT
-------------------- ------- -------- ----------- ----------
username/my-bucket 32 B 5 2026-02-16
username/checkpoints 117.6 MB 700 2026-02-13
username/logs 321.8 MB 2000 2026-02-13
# List buckets in a specific namespace
>>> hf buckets ls my-org
# Filter buckets by name
>>> hf buckets list --search "checkpoint"要获取特定存储桶的详细信息(以 JSON 格式返回),请使用 hf buckets info:
>>> hf buckets info username/my-bucket
{
"id": "username/my-bucket",
"private": false,
"created_at": "2026-02-16T15:28:32+00:00",
"size": 32,
"total_files": 5
}更改存储桶可见性
要在私有和公开之间切换存储桶,请使用 hf buckets settings:
# Make a bucket private
>>> hf buckets settings username/my-bucket --private
# Make it public again
>>> hf buckets settings username/my-bucket --public删除存储桶
要删除存储桶,请使用 hf buckets delete。除非传入 --yes,否则系统会提示您进行确认:
>>> hf buckets delete username/my-bucket --yes删除文件
使用 hf buckets remove(或其简写 hf buckets rm)从存储桶中删除文件。
要删除单个文件,请指定其路径:
>>> hf buckets rm username/my-bucket/old-model.bin要删除某个前缀下的所有文件,请使用 --recursive:
>>> hf buckets rm username/my-bucket/logs/ --recursive您也可以指定存储桶中所有不带前缀的文件:
>>> hf buckets rm username/my-bucket --recursive --include "*.tmp"使用 --dry-run 可以预览将被删除的内容,而不会实际执行删除操作:
>>> hf buckets rm username/my-bucket/checkpoints/ --recursive --dry-run浏览文件
使用 hf buckets list 并指定存储桶 ID 来列出存储桶中的文件:
>>> hf buckets list username/my-bucket
2048 2026-01-15 10:30:00 big.bin
5 2026-01-15 10:30:00 file.txt
2026-01-15 10:30:00 sub/添加 -R 以进行递归列表显示,添加 -h 以显示人类可读的文件大小和简短日期。你还可以使用 --tree 显示 ASCII 树视图,或使用 --tree --quiet 显示不带元数据的简洁树:
# Recursive with human-readable sizes
>>> hf buckets list username/my-bucket -R -h
2.0 KB Jan 15 10:30 big.bin
5 B Jan 15 10:30 file.txt
14 B Jan 15 10:30 sub/nested.txt
4 B Jan 15 10:30 sub/deep/file.txt
# Tree with human-readable sizes
>>> hf buckets list username/my-bucket --tree -h -R
2.0 KB Jan 15 10:30 ├── big.bin
5 B Jan 15 10:30 ├── file.txt
└── sub/
├── deep/
4 B Jan 15 10:30 │ └── file.txt
14 B Jan 15 10:30 └── nested.txt
# Clean tree without metadata
>>> hf buckets list username/my-bucket --tree --quiet -R
├── big.bin
├── file.txt
└── sub/
├── deep/
│ └── file.txt
└── nested.txt要按前缀进行筛选,请将前缀附加到存储桶路径之后:
>>> hf buckets list username/my-bucket/sub -R复制文件
使用 hf cp 在本地机器、仓库和存储桶之间复制单个文件。源和目的地可以是本地路径、hf:// URI(仓库或存储桶)或 -(stdin/stdout)。
hf cp也作为hf repos cp和hf buckets cp提供——这三个命令完全相同。请根据工作流选择最易读的一个。
要上传文件(本地 → 仓库或存储桶):
# To a repository
>>> hf cp ./model.safetensors hf://username/my-model/model.safetensors
# To a bucket (uses the local filename when the destination ends with /)
>>> hf cp ./data.csv hf://buckets/username/my-bucket/logs/要下载文件(仓库或存储桶 → 本地):
# From a repository
>>> hf cp hf://datasets/username/my-dataset@refs/pr/1/data.csv ./data.csv
# From a bucket, to the current directory (destination omitted)
>>> hf cp hf://buckets/username/my-bucket/config.json您也可以使用 - 将数据流式传输到 stdout 或从 stdin 读取:
# Download to stdout
>>> hf cp hf://buckets/username/my-bucket/config.json - | jq .
# Upload from stdin
>>> echo "hello" | hf cp - hf://username/my-model/hello.txt要在 Hub 上的两个位置之间进行复制(repo/bucket → repo/bucket):
# Repo to repo
>>> hf cp hf://username/source-model/config.json hf://username/dest-model/config.json
# Repo to bucket
>>> hf cp hf://datasets/username/my-dataset/data/train/ hf://buckets/username/my-bucket/datasets/train/
# Bucket to bucket
>>> hf cp hf://buckets/username/source-bucket/logs/ hf://buckets/username/archive-bucket/logs/在两个 Hub 位置之间复制文件夹时,源路径末尾的 / 决定了是嵌套复制文件夹本身,还是仅复制其内容(rsync 风格):
# Without trailing slash: "logs" dir is nested => archive/logs/...
>>> hf cp hf://buckets/username/my-bucket/logs hf://buckets/username/archive-bucket/
# With trailing slash: only contents of "logs" are copied => archive/...
>>> hf cp hf://buckets/username/my-bucket/logs/ hf://buckets/username/archive-bucket/注意事项:
hf cp在涉及本地路径时仅复制单个文件。要将整个目录上传/下载到本地,请使用hf upload/hf download(仓库)或hf buckets sync(存储桶)。- 暂不支持从存储桶复制到仓库。
- 不支持本地到本地的复制(请使用 shell 的
cp)。 - 两个 Hub 位置之间的复制仅在同一个存储区域内有效。
同步目录
使用 hf buckets sync 在本地机器和存储桶之间同步目录。它会比较源目录和目标目录,仅传输已更改的文件。
要将本地目录上传到存储桶:
>>> hf buckets sync ./data hf://buckets/username/my-bucket要从存储桶下载到本地目录:
>>> hf buckets sync hf://buckets/username/my-bucket ./data使用 --delete 删除源中不存在的目标文件:
>>> hf buckets sync ./data hf://buckets/username/my-bucket --delete您可以使用 --include 和 --exclude 模式来筛选要同步的文件:
>>> hf buckets sync ./data hf://buckets/username/my-bucket --include "*.safetensors" --exclude "*.tmp"如果只想更新现有文件(跳过新文件),请使用 --existing。如果只想创建新文件(跳过现有文件),请使用 --ignore-existing:
>>> hf buckets sync ./data hf://buckets/username/my-bucket --existing
>>> hf buckets sync ./data hf://buckets/username/my-bucket --ignore-existing为了更加安全,您可以在执行之前生成一个计划以供审查,然后再应用它:
# Generate a plan
>>> hf buckets sync ./data hf://buckets/username/my-bucket --plan sync-plan.jsonl
# Review and apply the plan
>>> hf buckets sync --apply sync-plan.jsonl使用 --dry-run 可以将同步计划以 JSONL 格式打印到标准输出,而不会执行任何操作。这对于将其通过管道传递给 jq 或其他工具非常方便:
>>> hf buckets sync ./data hf://buckets/username/my-bucket --dry-run | jq .
hf sync是hf buckets sync的便捷顶层别名。有关所有同步选项的完整详细信息,请参阅 Buckets 指南。
hf models
使用 hf models 列出 Hub 上的模型并获取特定模型的详细信息。
列出模型
# List trending models
>>> hf models ls
# Search for models
>>> hf models ls --search "lora"
# Filter by author
>>> hf models ls --author Qwen
# Filter by pipeline tag
>>> hf models ls --pipeline-tag summarization
# Filter by parameter count
>>> hf models ls --num-parameters min:6B,max:128B
# Only non-gated models
>>> hf models ls --no-gated --author google
# Only models runnable by a given app
>>> hf models ls --apps llama.cpp
# Sort by downloads
>>> hf models ls --sort downloads --limit 10当使用模型 ID 调用时,hf models ls 会列出该模型仓库中的文件:
# List files in a model repo
>>> hf models ls meta-llama/Llama-3.2-1B-Instruct
# List files recursively
>>> hf models ls meta-llama/Llama-3.2-1B-Instruct -R
# Tree view with human-readable sizes
>>> hf models ls meta-llama/Llama-3.2-1B-Instruct --tree -h
# List files at a specific revision
>>> hf models ls meta-llama/Llama-3.2-1B-Instruct --revision main获取模型信息
>>> hf models info Lightricks/LTX-2使用 --expand 可获取 downloads、likes、tags 等附加属性。
获取模型卡片
使用 hf models card 获取模型的模型卡(README)。默认情况下,会将完整的模型卡内容打印到标准输出。
# Full card (metadata + text)
>>> hf models card google/gemma-4-31B-it
# Just the metadata (from the YAML frontmatter)
>>> hf models card google/gemma-4-31B-it --metadata
# Metadata as JSON (useful for scripting and agents)
>>> hf models card google/gemma-4-31B-it --metadata --format json
# Just the text body (no YAML frontmatter)
>>> hf models card google/gemma-4-31B-it --texthf datasets
使用 hf datasets 列出 Hub 上的数据集,并获取特定数据集的详细信息。
列出数据集
# List trending datasets
>>> hf datasets ls
# Search for datasets
>>> hf datasets ls --search "code"
# List official benchmark datasets
>>> hf datasets ls --filter benchmark:official
# Sort by downloads
>>> hf datasets ls --sort downloads --limit 10当使用数据集 ID 调用时,hf datasets ls 会列出该数据集仓库中的文件:
# List files in a dataset repo
>>> hf datasets ls HuggingFaceFW/fineweb
# List files recursively with human-readable sizes
>>> hf datasets ls HuggingFaceFW/fineweb -R -h
# Tree view
>>> hf datasets ls HuggingFaceFW/fineweb --tree列出数据集排行榜
使用 hf datasets leaderboard 查看提交到基准数据集的模型分数,以便为特定任务找到最佳模型,或根据基准分数比较不同模型。
>>> hf datasets leaderboard SWE-bench/SWE-bench_Verified
>>> hf datasets leaderboard SWE-bench/SWE-bench_Verified --limit 5 --format json获取数据集信息
>>> hf datasets info HuggingFaceFW/fineweb获取数据集卡片
使用 hf datasets card 获取数据集的数据集卡片(README)。默认情况下,会将完整的卡片内容打印到标准输出。
# Full card (metadata + text)
>>> hf datasets card HuggingFaceFW/fineweb
# Just the metadata (from the YAML frontmatter)
>>> hf datasets card HuggingFaceFW/fineweb --metadata
# Metadata as JSON (useful for scripting and agents)
>>> hf datasets card HuggingFaceFW/fineweb --metadata --format json
# Just the text body (no YAML frontmatter)
>>> hf datasets card HuggingFaceFW/fineweb --text列出 parquet URL
在编写 SQL 查询之前,请使用 hf datasets parquet 来查找数据集的 parquet 文件 URL。
Hub 上的数据集会由 Dataset Viewer 服务在后端自动转换为 Parquet 格式(适用于符合条件的数据集)。
有关详细信息,请参阅 Parquet 转换指南。
>>> hf datasets parquet cfahlgren1/hub-stats
>>> hf datasets parquet cfahlgren1/hub-stats --subset models
>>> hf datasets parquet cfahlgren1/hub-stats --split train
>>> hf datasets parquet cfahlgren1/hub-stats --format json默认的表格输出包含来自 Hub API 的子集、拆分和 parquet 文件 URL。
在数据集 parquet 上运行 SQL
使用 hf datasets sql 通过 DuckDB 对数据集的 parquet URL 执行原始 SQL 查询。
首先使用 hf datasets parquet 发现 URL,然后使用 read_parquet(...) 直接查询它们。
>>> hf datasets sql "SELECT COUNT(*) AS rows FROM read_parquet('https://huggingface.co/api/datasets/cfahlgren1/hub-stats/parquet/models/train/0.parquet')"
>>> hf datasets sql "SELECT * FROM read_parquet('https://huggingface.co/api/datasets/cfahlgren1/hub-stats/parquet/models/train/0.parquet') LIMIT 5" --format json如有需要,请先安装 DuckDB:
# Python package
>>> pip install duckdb
# or standalone DuckDB CLI (Homebrew: macOS/Linux)
>>> brew install duckdbhf spaces
使用 hf spaces 列出 Hub 上的 Spaces,并获取特定 Space 的详细信息。
列出 Spaces
# List trending Spaces
>>> hf spaces ls
# Search for Spaces
>>> hf spaces ls --search "3d"
# Sort by likes
>>> hf spaces ls --sort likes --limit 10当使用 Space ID 调用时,hf spaces ls 会列出该 Space 仓库中的文件:
# List files in a Space repo
>>> hf spaces ls victor/deepsite
# List files recursively with tree view
>>> hf spaces ls victor/deepsite --tree -R -h获取 Space 信息
>>> hf spaces info victor/deepsite获取 Space 卡片
使用 hf spaces card 获取 Space 的卡片(README)。默认情况下,会将完整的卡片内容打印到标准输出。
# Full card (metadata + text)
>>> hf spaces card mteb/leaderboard
# Just the card metadata (from the YAML frontmatter)
>>> hf spaces card mteb/leaderboard --metadata
# Card metadata as JSON
>>> hf spaces card mteb/leaderboard --metadata --format json
# Just the text body (no YAML frontmatter)
>>> hf spaces card mteb/leaderboard --text暂停或重启 Space 会销毁其容器,因此写入临时文件系统的任何内容都会丢失。若要在重启后持久化数据,请使用
hf spaces volumes set挂载 Volume 或存储桶(运行hf spaces volumes --help以查看详细信息)。
暂停一个 Space
使用 hf spaces pause 可在未使用 Space 时将其暂停(暂停期间不计费)。之后可通过 hf spaces restart 重新启动。
>>> hf spaces pause username/my-space重启 Space
使用 hf spaces restart 重启 Space。传入 --factory-reboot 可在不使用构建缓存的情况下从头重建 Space。
>>> hf spaces restart username/my-space
>>> hf spaces restart username/my-space --factory-reboot等待一个 Space
使用 hf spaces wait 可阻塞等待,直到 Space 完成构建/启动并进入稳定状态。如果 Space 处于 RUNNING 状态,则以退出码 0 退出;否则以非零退出码退出(例如 BUILD_ERROR)。在重启或更改硬件后编写脚本时非常实用。
>>> hf spaces wait username/my-space
# With a timeout
>>> hf spaces wait username/my-space --timeout 5m
# Chain with restart
>>> hf spaces restart username/my-space && hf spaces wait username/my-space列出可用硬件
使用 hf spaces hardware 列出 Spaces 的所有可用硬件选项,包括价格。
>>> hf spaces hardware检查您的 ZeroGPU 配额
使用 hf spaces zero-gpu quota 可以查看您的 ZeroGPU 配额剩余量以及重置时间。当您通过脚本、应用或代理调用 ZeroGPU Spaces 时,这有助于跟踪您的使用情况。
>>> hf spaces zero-gpu quota
✓ ZeroGPU quota (in GPU-seconds)
remaining: 1810
base: 2400
resets_at: 2026-09-30T18:12:03+00:00
overquota_used: 0
>>> hf spaces zero-gpu quota --format json
{"remaining": 1810, "base": 2400, "resets_at": "2026-09-30T18:12:03+00:00", "overquota_used": 0}如果您的配额即将用尽,该命令会建议您从账单设置中购买积分,以便在每日配额之外继续使用 ZeroGPU(仅限 PRO、Team 和 Enterprise 用户)。
更新 Space 设置
使用 hf spaces settings 来更新 Space 的设置。
>>> hf spaces settings username/my-space --sleep-time 3600
>>> hf spaces settings username/my-space --hardware t4-medium--sleep-time:Space 进入休眠前的空闲时间(以秒为单位)。使用-1可设置为永不休眠。此选项仅在升级后的硬件上可用(参见 Spaces 休眠时间文档)。--hardware:硬件类型(例如cpu-basic、t4-medium、l4x4)。运行hf spaces hardware以查看所有选项。
管理 Space 密钥
使用 hf spaces secrets ls 列出 Space 上的密钥,使用 hf spaces secrets add 添加或更新一个或多个密钥,使用 hf spaces secrets delete 删除一个密钥。传入 --secrets-file PATH 可从 .env 风格的文件中加载密钥。现有的键会被覆盖。
>>> hf spaces secrets ls username/my-space
>>> hf spaces secrets add username/my-space -s OPENAI_API_KEY=sk-...
>>> hf spaces secrets add username/my-space --secrets-file .env.secrets
>>> hf spaces secrets delete username/my-space OPENAI_API_KEY --yesSecret 值仅可写入,因此
hf spaces secrets ls仅显示密钥、描述和更新时间戳,而不会显示 Secret 值本身。
管理 Space 环境变量
使用 hf spaces variables 在 Space 上管理非机密环境变量。与机密不同,变量是可读的,因此 ls 会同时显示键和值。在 add 时传入 --env-file PATH,即可从 .env 风格的文件中加载。
>>> hf spaces variables ls username/my-space
>>> hf spaces variables add username/my-space -e MODEL_ID=gpt2 -e MAX_TOKENS=512
>>> hf spaces variables add username/my-space --env-file .env
>>> hf spaces variables delete username/my-space MAX_TOKENS --yes通过 SSH 连接到 Space(开发模式)
使用 hf spaces ssh 可以打开到 Space 的 Dev Mode 容器的 SSH 会话。如果未启用 Dev Mode,CLI 会提示你启用它(或使用 --auto 跳过提示)。
您的 SSH 公钥必须已在您的设置中注册。有关更多详细信息,请参阅Dev Mode 文档。
# SSH into a Space
>>> hf spaces ssh username/my-space
# Print the SSH command without running it
>>> hf spaces ssh username/my-space --dry-run
# Auto-enable Dev Mode if disabled
>>> hf spaces ssh username/my-space --auto
# Use a specific SSH key
>>> hf spaces ssh username/my-space -i ~/.ssh/id_ed25519hf papers
使用 hf papers 来列出、搜索、获取 Hub 上论文的结构化信息并阅读其 Markdown 内容。
列出论文
# List most recent daily papers
>>> hf papers ls
# List trending papers
>>> hf papers ls --sort=trending
# List papers from a specific date
>>> hf papers ls --date=2025-01-23
# List today's papers
>>> hf papers ls --date=today
# List papers from a specific week
>>> hf papers ls --week=2025-W09
# List papers from a specific month
>>> hf papers ls --month=2025-02
# List papers submitted by a specific user
>>> hf papers ls --submitter=akhaliq
# Limit results
>>> hf papers ls --sort=trending --limit=5搜索论文
# Search papers by keyword
>>> hf papers search "vision language"
# Limit search results
>>> hf papers search "diffusion models" --limit=10
# Output as JSON
>>> hf papers search "attention" --format=json获取论文信息
# Get structured metadata for a paper (returns JSON)
>>> hf papers info 2601.15621以 Markdown 格式阅读论文
# Read the full paper content as markdown
>>> hf papers read 2601.15621hf 讨论
使用 hf discussions 可以直接在终端中管理 Hub 仓库上的讨论和拉取请求。您可以列出、查看、创建、评论、关闭、重新打开以及合并讨论和 PR。有关 Hub 社区功能工作原理的完整指南,请参阅 讨论和拉取请求指南。
列出讨论
要列出某个仓库中未关闭的讨论和 PR,请将仓库 ID 传递给 hf discussions list(或其简写 hf discussions ls):
>>> hf discussions list username/my-model您可以通过类型(discussion 或 pull_request)、状态(open、closed、merged 或 all)或作者来缩小结果范围:
>>> hf discussions list username/my-model --kind pull_request --status merged
>>> hf discussions list username/my-model --author alice在脚本中,使用 --format json 获取结构化输出,或使用 --quiet 仅打印讨论编号(每行一个):
>>> hf discussions list username/my-model --format json
>>> hf discussions ls username/my-model --quiet获取讨论或 PR 的信息
要查看特定的讨论或 PR,请传入仓库 ID 和讨论编号:
>>> hf discussions info username/my-model 5输出包含讨论元数据(标题、状态、作者等)以及完整的对话事件列表。若要显示拉取请求的 diff,请改用 hf discussions diff。
使用 --format json 获取机器可读的输出,并在将输出通过管道传递给其他工具时设置 NO_COLOR=1 以去除 ANSI 颜色。
创建讨论或 PR
要开启新的讨论,请使用 --title 提供标题。您可以选择使用 --body 内联包含描述,或使用 --body-file 从文件中加载:
>>> hf discussions create username/my-model --title "Bug report"
>>> hf discussions create username/my-model --title "Feature request" --body "Please add X"
>>> hf discussions create username/my-model --title "Report" --body-file report.md若要创建拉取请求而非普通讨论,请添加 --pull-request 标志:
>>> hf discussions create username/my-model --title "Fix typo" --pull-request在讨论或 PR 中发表评论
通过指定编号,为现有的讨论或 PR 添加评论。评论内容可以通过 --body 内联传递,使用 --body-file 从文件读取,或使用 --body-file - 从标准输入(stdin)通过管道传入:
>>> hf discussions comment username/my-model 5 --body "Thanks for reporting!"
>>> hf discussions comment username/my-model 5 --body-file review.md
>>> echo "LGTM" | hf discussions comment username/my-model 5 --body-file -编辑评论
通过传入讨论编号和评论 ID,可以就地编辑现有评论。评论 ID 可通过 hf discussions info 获取:
>>> hf discussions edit username/my-model 5 abc123 --body "Updated comment."
>>> hf discussions edit username/my-model 5 abc123 --body-file fixed.md附加图像和视频
将 --attach 传递给 hf discussions create、comment 或 edit,即可上传图像、视频或音频文件并将其嵌入正文,效果与在 Hub 上将文件拖入评论框相同。如果正文中已引用该文件,例如 ,则该引用将指向上传的文件。否则,该文件将被追加到正文末尾。要为追加的图像设置替代文本,请在 # 后添加:
>>> hf discussions create username/my-model --title "Fix rendering" --pr --body "Before: " --attach ./before.png --attach "./after.png#After the fix"
>>> hf discussions comment username/my-model 5 --body "Here is a demo:" --attach demo.mp4支持的格式包括 PNG、JPEG、GIF、WebP、MP4、MOV、WebM、MP3 和 WAV,文件大小上限为 10MB(视频为 50MB)。
关闭、重新打开和合并
您可以使用 hf discussions close 关闭讨论或 PR。默认情况下,系统会提示您进行确认。传入 --yes 可跳过提示,传入 --comment 可留下关闭留言:
>>> hf discussions close username/my-model 5
>>> hf discussions close username/my-model 5 --yes --comment "Resolved"要重新打开之前已关闭的讨论,请使用 hf discussions reopen:
>>> hf discussions reopen username/my-model 5 --yes要合并拉取请求,请使用 hf discussions merge:
>>> hf discussions merge username/my-model 5 --yes重命名和差异
您可以通过提供新标题来重命名讨论:
>>> hf discussions rename username/my-model 5 "Updated title"要在终端中直接查看拉取请求的 diff,请使用 hf discussions diff:
>>> hf discussions diff username/my-model 5hf repos
hf repos 允许您在 Hugging Face Hub 上列出、创建、复制、删除和移动仓库,更新其设置,以及删除文件。它还包含用于管理分支和标签的子命令。
列出仓库
使用 hf repos ls 列出您所有的仓库(模型、数据集、Spaces 和存储桶),并显示存储信息,按存储用量排序。默认情况下,仅显示前 30 个仓库:
# List all your repos (first 30)
>>> hf repos ls
REPOSITORY TYPE UPDATED VISIBILITY STORAGE % OF TOTAL
------------------------ ------- ---------- ---------- -------- ----------
username/bucket-raw bucket 2026-04-29 public 1.7 TB 72.3%
username/my-model model 2026-05-06 public 4.8 GB 18.1%
username/my-dataset dataset 2024-09-14 private 598.4 MB 5.2%
Hint: Showing 30 of 42 repos. Use `--limit 0` to list all.按仓库类型筛选、按名称搜索或调整限制:
# List only models
>>> hf repos ls --type model
# Search by name
>>> hf repos ls --search "bert"
# List repos from an organization
>>> hf repos ls --namespace my-org
# Combine filters
>>> hf repos ls --namespace my-org --type dataset --search "train"
# List all repos (no limit)
>>> hf repos ls --limit 0使用 --format json 用于脚本,或使用 -q 仅显示 ID。在通过管道传输时,使用 --limit 0 以导出所有仓库:
>>> hf repos ls --limit 0 --format json | jq '.[].id'
>>> hf repos ls -q创建仓库
>>> hf repos create Wauplin/my-cool-model
Successfully created Wauplin/my-cool-model on the Hub.
Your repo is now available at https://huggingface.co/Wauplin/my-cool-model创建私有数据集或 Space:
>>> hf repos create my-cool-dataset --repo-type dataset --private
>>> hf repos create my-gradio-space --repo-type space --sdk gradio如果仓库可能已经存在,请使用 --exist-ok;若要指定企业资源组,请使用 --resource-group-id。
在特定区域创建仓库:
>>> hf repos create my-model --region us复制仓库
使用 hf repos duplicate 将现有的模型、数据集或 Space 复制到您的账户(或组织)。复制操作在服务器上执行,并保留 git 历史记录:
>>> hf repos duplicate openai/gdpval --type dataset
>>> hf repos duplicate openai/gdpval myorg/my-gdpval --type dataset --private新仓库的 LFS/Xet 文件可能在命令返回后仍在后台复制。在这种情况下,系统会打印一条警告,并且在复制完成之前,从新仓库下载这些文件可能会失败。
删除仓库
>>> hf repos delete Wauplin/my-cool-model数据集和 Spaces:
>>> hf repos delete my-cool-dataset --repo-type dataset
>>> hf repos delete my-gradio-space --repo-type space移动仓库
>>> hf repos move old-namespace/my-model new-namespace/my-model更新仓库设置
>>> hf repos settings Wauplin/my-cool-model --gated auto
>>> hf repos settings Wauplin/my-cool-model --private true
>>> hf repos settings Wauplin/my-cool-model --private false--gated:auto、manual、false之一--private true|false:设置仓库的隐私状态
从仓库中删除文件
hf repos delete-files <repo_id> 子命令允许您从存储库中删除文件。以下是一些使用示例。
删除文件夹:
>>> hf repos delete-files Wauplin/my-cool-model folder/
Files correctly deleted from repo. Commit: https://huggingface.co/Wauplin/my-cool-mo...删除多个文件:
>>> hf repos delete-files Wauplin/my-cool-model file.txt folder/pytorch_model.bin
Files correctly deleted from repo. Commit: https://huggingface.co/Wauplin/my-cool-mo...使用通配符模式来删除一组文件。模式是标准通配符(globbing 模式),文档见此处。模式匹配基于fnmatch。
请注意,
fnmatch中的*会跨越路径边界进行匹配,这与传统的 Unix shell 通配符不同。例如,"data/*.json"将同时匹配data/file.json和data/subdir/file.json。若要仅匹配当前目录下的文件,需要显式列出这些文件或使用更具体的模式。
>>> hf repos delete-files Wauplin/my-cool-model "*.txt" "folder/*.bin"
Files correctly deleted from repo. Commit: https://huggingface.co/Wauplin/my-cool-mo...要从仓库中删除文件,您必须经过身份验证并拥有相应权限。默认情况下,将使用本地保存的令牌(通过 hf auth login 保存)。如果您希望显式进行身份验证,请使用 --token 选项:
>>> hf repos delete-files --token=hf_**** Wauplin/my-cool-model file.txthf repos branch
使用 hf repos branch 为 Hub 上的仓库创建和删除分支。
# Create a branch
>>> hf repos branch create Wauplin/my-cool-model dev
# Create a branch from a specific revision
>>> hf repos branch create Wauplin/my-cool-model release-1 --revision refs/pr/104
# Delete a branch
>>> hf repos branch delete Wauplin/my-cool-model dev所有命令都接受
--repo-type(model、dataset或space之一)以及--token(如需显式进行身份验证)。在任何命令上使用--help即可查看所有选项。
hf cache
使用 hf cache 管理您的本地 Hugging Face 缓存目录。该缓存用于存储从 Hub 下载的模型、数据集、Spaces 和内核。
# List cached repositories
>>> hf cache ls
# List cached revisions
>>> hf cache ls --revisions
# Remove specific items from cache
>>> hf cache rm model/gpt2
# Remove unreferenced revisions
>>> hf cache prune
# Verify cached file checksums
>>> hf cache verify gpt2hf cache ls
使用 hf cache ls 可以查看 Hugging Face 缓存中本地存储的内容。默认情况下,它会按仓库聚合信息:
>>> hf cache ls
ID SIZE LAST_ACCESSED LAST_MODIFIED REFS
--------------------------- -------- ------------- ------------- -----------
dataset/nyu-mll/glue 157.4M 2 days ago 2 days ago main script
model/LiquidAI/LFM2-VL-1.6B 3.2G 4 days ago 4 days ago main
model/microsoft/UserLM-8b 32.1G 4 days ago 4 days ago main
Found 3 repo(s) for a total of 5 revision(s) and 35.5G on disk.添加 --revisions 以深入查看特定快照,并串联过滤器以聚焦于关键内容:
>>> hf cache ls --filter "size>30g" --revisions
ID REVISION SIZE LAST_MODIFIED REFS
------------------------- ---------------------------------------- -------- ------------- ----
model/microsoft/UserLM-8b be8f2069189bdf443e554c24e488ff3ff6952691 32.1G 4 days ago main
Found 1 repo(s) for a total of 1 revision(s) and 32.1G on disk.该命令支持多种输出格式以便脚本使用:--format json 打印结构化对象,--format csv 写入逗号分隔的行,--quiet 仅打印 ID。使用 --sort 可按 accessed、modified、name 或 size 对条目进行排序(追加 :asc 或 :desc 以控制排序顺序),并使用 --limit 将结果限制为前 N 个条目。将这些选项与 --cache-dir 结合使用,以指定其他缓存位置。有关高级工作流,请参阅 管理您的缓存 指南。
将使用 hf cache ls --q 选中的缓存条目的 ID 通过管道传入 hf cache rm 以删除它们:
>>> hf cache rm $(hf cache ls --filter "accessed>1y" -q) -y
About to delete 2 repo(s) totalling 5.31G.
- model/meta-llama/Llama-3.2-1B-Instruct (entire repo)
- model/hexgrad/Kokoro-82M (entire repo)
Deleted 2 repo(s) and 2 revision(s); freed 5.31G.hf cache rm
hf cache rm 用于删除缓存的仓库、单个修订版本或单个文件。请传入一个或多个仓库 ID(model/bert-base-uncased)、hf:// URI 或修订版本哈希值:
>>> hf cache rm model/LiquidAI/LFM2-VL-1.6B
About to delete 1 repo(s) totalling 3.2G.
- model/LiquidAI/LFM2-VL-1.6B (entire repo)
Proceed with deletion? [y/N]: y
Deleted 1 repo(s) and 2 revision(s); freed 3.2G.也支持仓库级别的 hf:// URI:
>>> hf cache rm hf://models/openai-community/gpt2 --dry-run
About to delete 1 repo(s) totalling 1.1G.
- model/openai-community/gpt2 (entire repo)
Dry run: no files were deleted.若要删除单个文件而非整个仓库,例如某个 GGUF 量化文件,请传入一个 hf:// 文件 URI。该文件将从仓库的所有已缓存修订版本中移除,并且仅当没有其他已缓存文件仍引用其 blob 时,该 blob 才会被删除:
>>> hf cache rm hf://models/unsloth/gemma-3-27b-it-GGUF/gemma-3-27b-it-Q4_K_M.gguf --dry-run
About to delete 1 file(s) totalling 16.5G.
- model/unsloth/gemma-3-27b-it-GGUF@3f4b5c1d2e6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c/gemma-3-27b-it-Q4_K_M.gguf
Dry run: no files were deleted.修订版本保持可用状态,已删除的文件会在下次需要时重新下载。路径必须完全匹配:不支持文件夹和通配符模式,且在同一次调用中不能将文件目标与仓库或修订版本混用。
在同一次调用中混合使用仓库和特定版本。使用 --dry-run 预览影响,或使用 --yes 跳过确认提示——这在自动化脚本中非常实用:
>>> hf cache rm model/t5-small 8f3ad1c --dry-run
About to delete 1 repo(s) and 1 revision(s) totalling 1.1G.
- model/t5-small:
8f3ad1c [main] 1.1G
Dry run: no files were deleted.在默认缓存位置之外工作时,请将命令与 --cache-dir PATH 搭配使用。
hf cache prune
hf cache prune 是一个便捷命令,用于回收缓存垃圾占用的空间:所有已分离(未被引用)的修订版本(仅保留仍可通过分支或标签访问的修订版本)、因下载中断而残留的 .incomplete 文件,以及不再被任何已缓存仓库引用的共享数据块:
>>> hf cache prune
About to delete 3 unreferenced revision(s) and 2 incomplete download(s) (2.4G total).
- model/t5-small:
1c610f6b [refs/pr/1] 820.1M
d4ec9b72 [(detached)] 640.5M
- dataset/google/fleurs:
2b91c8dd [(detached)] 937.6M
Proceed? [y/N]: y
Deleted 3 unreferenced revision(s) and 2 incomplete download(s); freed 2.4G..incomplete 文件是下载中断后遗留的部分下载文件。它们不会被 hf cache ls/rm(在修订版本级别上工作)所跟踪,因此 hf cache ls 会通过提示指出它们,而 hf cache prune 会自动将其删除。
与其他缓存命令一样,--dry-run、--yes 和 --cache-dir 均可用。有关更多示例,请参阅 管理您的缓存 指南。
hf cache verify
使用 hf cache verify 根据 Hub 上的校验和验证本地文件。您可以验证缓存快照或常规本地目录。
示例:
# Verify main revision of a model in cache
>>> hf cache verify deepseek-ai/DeepSeek-OCR
# Verify a specific revision
>>> hf cache verify deepseek-ai/DeepSeek-OCR --revision refs/pr/5
>>> hf cache verify deepseek-ai/DeepSeek-OCR --revision ef93bf4a377c5d5ed9dca78e0bc4ea50b26fe6a4
# Verify a private repo
>>> hf cache verify me/private-model --token hf_***
# Verify a dataset
>>> hf cache verify karpathy/fineweb-edu-100b-shuffle --repo-type dataset
# Verify files in a local directory
>>> hf cache verify deepseek-ai/DeepSeek-OCR --local-dir /path/to/repo默认情况下,该命令会警告缺失或多余的文件。使用标志可将这些警告转换为错误:
>>> hf cache verify deepseek-ai/DeepSeek-OCR --fail-on-missing-files --fail-on-extra-files成功时,您会看到如下摘要:
✅ Verified 13 file(s) for 'deepseek-ai/DeepSeek-OCR' (model) in ~/.cache/huggingface/hub/models--meta-llama--Llama-3.2-1B-Instruct/snapshots/9213176726f574b556790deb65791e0c5aa438b6 All checksums match.
如果检测到不匹配,该命令会打印详细列表并以非零状态退出。
hf repos tag
使用 hf repos tag 为 Hub 上的仓库创建、列出和删除标签。
# Create a tag
>>> hf repos tag create my-model v1.0
# List tags
>>> hf repos tag list my-model
# Delete a tag
>>> hf repos tag delete my-model v1.0为模型添加标签
要为仓库添加标签,您需要提供repo_id和tag名称:
>>> hf repos tag create Wauplin/my-cool-model v1.0
You are about to create tag v1.0 on model Wauplin/my-cool-model
Tag v1.0 created on Wauplin/my-cool-model在特定修订版本上标记模型
如果要为特定修订版本添加标签,可以使用 --revision 选项。默认情况下,标签将创建在 main 分支上:
>>> hf repos tag create Wauplin/my-cool-model v1.0 --revision refs/pr/104
You are about to create tag v1.0 on model Wauplin/my-cool-model
Tag v1.0 created on Wauplin/my-cool-model为数据集或 Space 添加标签
如果要为数据集或 Space 添加标签,必须指定 --repo-type 选项:
>>> hf repos tag create bigcode/the-stack v1.0 --repo-type dataset
You are about to create tag v1.0 on dataset bigcode/the-stack
Tag v1.0 created on bigcode/the-stack列出标签
要列出仓库的所有标签,请使用 list(或 ls)子命令:
>>> hf repos tag list Wauplin/gradio-space-ci --repo-type space
Tags for space Wauplin/gradio-space-ci:
0.2.2
0.2.1
0.2.0
0.1.2
0.0.2
0.0.1删除标签
要删除标签,请使用 delete 子命令:
>>> hf repos tag delete Wauplin/my-cool-model v1.0
You are about to delete tag v1.0 on model Wauplin/my-cool-model
Proceed? [Y/n] y
Tag v1.0 deleted on Wauplin/my-cool-model您也可以传入 -y 以跳过确认步骤。
hf env
hf env 命令会打印有关您机器配置的信息。在 GitHub 上提交 issue 时,这有助于维护者排查您的问题。
>>> hf env
Copy-and-paste the text below in your GitHub issue.
- huggingface_hub version: 1.0.0.rc6
- Platform: Linux-6.8.0-85-generic-x86_64-with-glibc2.35
- Python version: 3.11.14
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Running in Google Colab Enterprise ?: No
- Token path ?: /home/wauplin/.cache/huggingface/token
- Has saved token ?: True
- Who am I ?: Wauplin
- Configured git credential helpers: store
- Installation method: unknown
- Torch: N/A
- httpx2: 2.0.0
- hf_xet: 1.1.10
- gradio: 5.41.1
- tensorboard: N/A
- pydantic: 2.11.7
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /home/wauplin/.cache/huggingface/hub
- HF_ASSETS_CACHE: /home/wauplin/.cache/huggingface/assets
- HF_TOKEN_PATH: /home/wauplin/.cache/huggingface/token
- HF_STORED_TOKENS_PATH: /home/wauplin/.cache/huggingface/stored_tokens
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_DISABLE_XET: False
- HF_HUB_DISABLE_SHARED_BLOBS: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10hf jobs
在 Hugging Face 基础设施上运行计算任务,使用熟悉的类 Docker 界面。
hf jobs 是一个命令行工具,让你可以通过简单的命令在 Hugging Face 的基础设施(包括 GPU 和 TPU!)上运行任何内容。可以把它想象成 docker run,只不过是在 A100 上运行代码。
有关 Jobs 和定价的总体概述,请参阅 Hub Jobs 文档。 有关 Python API 与 CLI 配合使用的用法,请参阅 运行和管理 Jobs 指南。
# Directly run Python code
>>> hf jobs run --name hello-world python:3.12 python -c 'print("Hello from the cloud!")'
# Use GPUs without any setup
>>> hf jobs run --flavor a10g-small pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel \
... python -c "import torch; print(torch.cuda.get_device_name())"
# Run in an organization account
>>> hf jobs run --namespace my-org-name python:3.12 python -c 'print("Running in an org account")'
# Run from Hugging Face Spaces
>>> hf jobs run hf.co/spaces/lhoestq/duckdb duckdb -c 'select "hello world"'
# Run a Python script with `uv` (experimental)
>>> hf jobs uv run --name my-script my_script.pyHugging Face Jobs 面向任何拥有预付费额度的用户或组织开放。
快速入门
1. 运行您的第一个任务
# Run a simple Python script
>>> hf jobs run python:3.12 python -c 'print("Hello from HF compute!")'此命令会运行任务并显示日志。您可以传入 --detach 在后台运行任务,并仅打印任务 ID。添加 -q 可仅打印任务 ID,这在脚本中捕获该 ID 时非常实用:
>>> JOB_ID=$(hf jobs run -dq python:3.12 python train.py)
>>> hf jobs wait "$JOB_ID"2. 检查任务状态
# List your running jobs
>>> hf jobs ls
# List all jobs
>>> hf jobs ls -a
# Inspect the status of a job
>>> hf jobs inspect <job_id>
# View logs from a job
>>> hf jobs logs <job_id>
# View resources usage stats and metrics of running jobs
>>> hf jobs stats
# View resources usage stats and metrics of some jobs
>>> hf jobs stats [job_ids]...
# Follow live stats until the jobs complete
>>> hf jobs stats -f [job_ids]...
# Cancel a job
>>> hf jobs cancel <job_id>
# Wait until one or more jobs finish (exit code 0 only if all jobs completed successfully)
>>> hf jobs wait <job_id> [<job_id>...]
# Wait for all currently running jobs
>>> hf jobs ls -q | xargs hf jobs wait未分离的 hf jobs run 和 hf jobs wait 在 Job 失败时会以非零代码退出,因此你可以使用 && 来链接命令:
>>> hf jobs run python:3.12 python train.py && echo "training succeeded"3. 在 GPU 上运行
您还可以通过 --flavor 选项在 GPU 或 TPU 上运行任务。例如,要在 A10G GPU 上运行 PyTorch 任务:
# Use an A10G GPU to check PyTorch CUDA
>>> hf jobs run --flavor a10g-small pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel \
... python -c 'import torch; print(f"This code ran with the following GPU: {torch.cuda.get_device_name()}")'运行此命令将显示以下输出!
This code ran with the following GPU: NVIDIA A10G
使用 -- 来分隔 Jobs 选项和传递给命令或脚本的参数。
Jobs 不会解析 -- 之后的选项。
>>> hf jobs run --flavor cpu-basic python:3.12 -- python --help就是这样!你现在已经在 Hugging Face 的基础设施上运行代码了。
常见用例
- 模型训练:在 GPU(T4、A10G、A100)上微调或训练模型,无需管理基础设施
- 合成数据生成:在高性能硬件上使用 LLM 生成大规模数据集
- 数据处理:使用高 CPU 配置处理大规模数据集,以应对并行工作负载
- 批量推理:使用优化的 GPU 配置对数千个样本运行离线推理
- 实验与基准测试:在一致的硬件上运行机器学习实验,以获得可复现的结果
- 开发与调试:无需本地 CUDA 环境即可测试 GPU 代码
传递环境变量和密钥
您可以使用
# Pass environment variables
>>> hf jobs run -e FOO=foo -e BAR=bar python:3.12 python -c 'import os; print(os.environ["FOO"], os.environ["BAR"])'# Pass an environment from a local .env file
>>> hf jobs run --env-file .env python:3.12 python -c 'import os; print(os.environ["FOO"], os.environ["BAR"])'# Pass secrets by name - the value is read from your environment, never from the command line
>>> hf jobs run -s MY_SECRET python:3.12 python -c 'import os; print(os.environ["MY_SECRET"])'# Pass secrets from a local .env.secrets file - they will be encrypted server side
>>> hf jobs run --secrets-file .env.secrets python:3.12 python -c 'import os; print(os.environ["MY_SECRET"])'# Or pipe them in, so the values touch neither the command line nor the disk
>>> printf 'MY_SECRET=psswrd\n' | hf jobs run --secrets-file - python:3.12 python -c 'import os; print(os.environ["MY_SECRET"])'所有三种形式的 Secrets 都会在服务器端进行加密。-s MY_SECRET=psswrd 也可以使用,但此时值会出现在 shell 历史记录和进程列表中(在 Linux 上为 /proc/<pid>/cmdline),因此当您使用该形式时,CLI 会向 stderr 打印警告;请仅将该形式用于并非真正敏感的值。同样的规则也适用于 --token <value>:请优先使用 hf auth login 或 HF_TOKEN 环境变量。env 文件或 secrets 文件应仅对您可读(chmod 600)—— 如果权限设置不当,CLI 会发出警告。
使用
--secrets HF_TOKEN可以隐式地传递您的本地 Hugging Face 令牌。 采用此语法时,密钥将从环境变量中获取。 对于HF_TOKEN,如果未设置环境变量,它可能会读取位于 Hugging Face 主文件夹中的令牌文件。
内置环境变量
在作业容器内部,以下环境变量会自动可用:
| 变量 | 描述 |
|---|---|
JOB_ID | 当前作业的唯一标识符。使用此标识符以编程方式引用该作业。 |
ACCELERATOR | 可用的加速器类型(例如,t4-medium、a10g-small、a100x4)。如果没有加速器,则为空。 |
CPU_CORES | 作业可用的 CPU 核心数(例如,2、4、8)。 |
MEMORY | 作业可用的内存量(例如,16Gi、32Gi)。 |
# Access job environment information
>>> hf jobs run python:3.12 python -c "import os; print(f'Job: {os.environ.get(\"JOB_ID\")}, CPU: {os.environ.get(\"CPU_CORES\")}, Mem: {os.environ.get(\"MEMORY\")}')"作业超时
任务默认超时时间为 30 分钟,超时后会自动停止。对于模型训练等长时间运行的任务,请使用 --timeout 选项设置自定义超时时间:
# Set timeout in seconds (default unit)
>>> hf jobs run --timeout 7200 python:3.12 python train.py
# Use time units: s (seconds), m (minutes), h (hours), d (days)
>>> hf jobs run --timeout 2h pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel python train.py
>>> hf jobs run --timeout 90m python:3.12 python process_data.py
>>> hf jobs run --timeout 1.5h python:3.12 python train.py # floats are supported--timeout 选项同样适用于 UV 脚本和计划任务:
# UV script with timeout
>>> hf jobs uv run --timeout 2h training_script.py
# Scheduled job with timeout
>>> hf jobs scheduled run @daily --timeout 4h python:3.12 python daily_task.py如果您的任务超出了超时时间,它将被自动终止。对于长时间运行的任务,请务必设置一个带有适当缓冲的超时时间,以避免任务意外终止。
重试并重新运行 Job
--attempts 设置最大尝试次数,包括首次运行。它适用于 Docker、UV 和定时任务。重新运行任务会启动一个具有相同已保存规格的新任务:
>>> hf jobs run --attempts 3 --detach python:3.12 python train.py
>>> hf jobs rerun <job_id>尝试次数为 3 表示当 Job 失败时最多允许重试两次。hf jobs rerun 同样会复用原始的尝试次数。与 hf jobs run 类似,它会流式输出新 Job 的日志,直到其完成。使用 --detach 可立即返回。
硬件
可用的 --flavor 选项:
- CPU:
cpu-basic、cpu-upgrade - GPU:
t4-small、t4-medium、l4x1、l4x4、a10g-small、a10g-large、a10g-largex2、a10g-largex4、a100-large - TPU:
v5e-1x1、v5e-2x2、v5e-2x4
(2025 年 7 月更新,源自 Hugging Face suggested_hardware 文档)
卷
使用 -v 或 --volume 在 Job 的磁盘上挂载一个卷。
您可以使用 hf:// URL 方案挂载任何 Hugging Face 仓库(模型/数据集/空间)或 Storage Bucket。例如:
- 挂载模型仓库:
-v hf://openai/gpt-oss-120b:/model - 挂载数据集仓库:
-v hf://datasets/HuggingFaceFW/fineweb:/data - 挂载存储桶:
-v hf://buckets/username/my-bucket:/mnt - 挂载一个空间:
-v hf://spaces/username/my-space:/app - 挂载仓库内的子文件夹:
-v hf://datasets/org/ds/train:/data
然后,您可以将挂载的卷用作本地目录:
# Docker Job with a mounted volume as input
>>> hf jobs run -v hf://datasets/HuggingFaceFW/fineweb:/dataset \
... duckdb/duckdb duckdb -c "SELECT * FROM '/dataset/**/*.parquet' LIMIT 5"
# UV Job with a mounted volume to save checkpoints when training a model
>>> hf jobs uv run -v hf://buckets/username/my-bucket:/training-outputs \
... sft.py --output-dir /training-outputs/training-v3-final ...模型、数据集和空间始终以只读方式挂载。存储桶默认支持读写——这对于频繁变更的数据尤其有用,因为文件可以就地覆盖或删除。
使用 :ro 启用只读:
- 以只读方式挂载存储桶:
-v hf://buckets/username/my-bucket:/mnt:ro
挂载本地数据
-v 的源端也可以是本地目录。它会先同步到您的 jobs-artifacts Storage Bucket,然后将生成的存储桶文件夹挂载到 Job 中:
>>> hf jobs uv run -v ./my-data:/data process.py重新运行该命令只会上传新增或已修改的文件。本地目录默认以只读方式挂载。使用 :rw 可让 Job 向该卷写入数据,例如在 Job 完成后获取输出(使用一个空的本地目录也可以):
>>> hf jobs uv run -v ./pdfs:/input -v ./md-out:/output:rw ocr.py
...
Hint: Volume '/output' is mounted read-write. Once the job is over, pull back its data with:
hf buckets sync hf://buckets/username/jobs-artifacts/md-out-a1b2c3d4 ./md-out标签
使用 -l 或 --label 为 Job 添加标签。标签是键值对,用于为 Job 应用元数据。要为 Job 添加两个标签,请重复使用标签参数(-l 或 --label):
>>> hf jobs run -l my-label --label foo=bar ubuntu echo "This Job has multiple labels"my-label 键未指定值,因此其值默认为空字符串("")。
使用 --name 在创建 Job 时添加 name 标签。名称有助于在 UI 中更轻松地查找和识别 Job;该标签是可选的,且无需唯一。如果不传入 --name,系统会自动根据 Docker 镜像或脚本,以及命令和已解析的运行时设置(flavor、timeout、environment values 等)的简短哈希值来生成名称,因此相同的配置始终会生成相同的名称(例如 python:3.12 foo --truc → python-3-12-1a2b3c4d)。即使命令保持不变,更改设置也会改变名称。您还可以重命名现有的 Job:
>>> hf jobs run --name training-v2 python:3.12 python train.py
>>> hf jobs labels <job_id> --name training-v2在 hf jobs ls 中使用 --status、--label 和 --name 来筛选 Jobs。--status 接受一个或多个状态,--label 接受 key=value 键值对,而 --name 是 --label name=NAME 的快捷方式。Job 必须匹配所有筛选条件才会被列出。Job 名称也会作为独立的 NAME 列显示:
# Show completed Jobs
>>> hf jobs ls -a --status completed
# Show running or scheduling Jobs
>>> hf jobs ls --status running,scheduling
# Show Jobs named `training-v2`
>>> hf jobs ls -a --name training-v2
# Show Jobs with the `model=Qwen3-06B` label
>>> hf jobs ls -a --label model=Qwen3-06B
# Combine filters: running Jobs labelled both `env=prod` and `team=ml`
>>> hf jobs ls --status running --label env=prod --label team=ml默认情况下,hf jobs ps 最多显示 100 个 Job,以避免终端内容过多。使用 --limit 可以更改此限制,或使用 --limit 0 显示所有 Job:
# Show up to 500 Jobs
>>> hf jobs ps -a --limit 500
# Show all Jobs (no limit)
>>> hf jobs ps -a --limit 0公开任务端口
使用 --expose 指定受令牌保护的端口,使用 --expose-public 指定应允许未认证访问的端口。这两个标志均可重复使用并组合使用,并且适用于 Docker、UV 和定时任务(scheduled Jobs)。
# Start a Job with a public HTTP server
>>> hf jobs run --detach --expose-public 8000 python:3.12 python -m http.server 8000
# Replace the configuration on a running Job: port 8000 is private, 9000 is public
>>> hf jobs expose <job_id> 8000 --public 9000
# Close all exposed ports
>>> hf jobs expose <job_id> --clearhf jobs expose 将受令牌保护的端口作为位置参数,并使用 --public 指定公开端口。它会在不重新运行 Job 的情况下应用更改。未包含在替换列表中的端口将被关闭。
SSH 到作业
将 --ssh 传递给 hf jobs run(或 hf jobs uv run),即可通过 SSH 访问该 Job 的容器,然后使用 hf jobs ssh 进行连接:
# Start a job with SSH enabled
>>> hf jobs run --ssh --detach python:3.12 sleep infinity
# Open an SSH session into it
>>> hf jobs ssh <job_id>
# Print the SSH command instead of running it
>>> hf jobs ssh <job_id> --dry-run
# Use a specific identity file
>>> hf jobs ssh <job_id> -i ~/.ssh/id_ed25519只有对 Job 命名空间具有写入权限的用户(即 Job 创建者或所有者组织的成员)才被允许进入,并通过在 https://huggingface.co/settings/keys 注册的 SSH 公钥进行身份验证。
网络组
将 --network-group <name> 传递给 hf jobs run(或 hf jobs uv run),以便同一命名空间和资源组中的 Jobs 能够在所有端口上相互访问。在每个成员内部,$HF_NETWORK_GROUP_HOSTNAME 会解析为组内的所有 Job,而 ${HF_NETWORK_GROUP_PREFIX}<alias> 则解析为通过 --network-alias <alias> 声明了别名的成员:
# Start a server, reachable by the other members of the group as "master"
>>> hf jobs run --detach --network-group train --network-alias master python:3.12 python -m http.server 8000
# Start a client in the same group
>>> hf jobs run --detach --network-group train python:3.12 sh -c 'curl --retry 10 --retry-connrefused "http://${HF_NETWORK_GROUP_PREFIX}master:8000/"'成员在就绪之前即可解析,因此连接时需使用重试机制。组名称和别名仅包含小写字母、数字和连字符,最大长度分别为 46 个字符和 34 个字符。
UV 脚本(实验性)
在 HF 基础设施上运行 UV 脚本(带有内联依赖项的 Python 脚本)。UV 脚本是 Python 脚本,它们使用特殊的注释语法将依赖项直接包含在文件中。
# Run a UV script (creates temporary repo)
>>> hf jobs uv run my_script.py
# Run with persistent repo
>>> hf jobs uv run --repo my-uv-scripts my_script.py
# Run with GPU
>>> hf jobs uv run --flavor t4-small ml_training.py
# Pass arguments to script
>>> hf jobs uv run process.py input.csv output.parquet
# Add dependencies
>>> hf jobs uv run --with transformers --with torch train.py
# Run a script directly from a URL
>>> hf jobs uv run https://huggingface.co/datasets/username/scripts/resolve/main/example.py
# Run a command
>>> hf jobs uv run --with lighteval python -c 'import lighteval'UV 脚本是 Python 脚本,它使用特殊的注释语法将依赖项直接包含在文件中。这使得它们非常适合无需复杂项目配置的自包含任务。有关 UV 脚本的更多信息,请参阅 UV 文档。
使用 -- 将冲突的选项传递给您的脚本。在这里,--help 会到达 train.py,而不是显示 Jobs 的帮助:
>>> hf jobs uv run --flavor t4-small train.py -- --help此规则同样适用于格式化标志:hf jobs run、hf jobs uv run 及其 scheduled 变体在任何位置都会消费 --format、--json 和 -q,因此当您的脚本需要这些标志时,请使用 --。
将启动配置与脚本一起发布
某些脚本只能在特定的运行时环境中正确运行:例如特定的镜像、GPU 型号、系统解释器等。脚本可以在其 PEP 723 头部中通过可选的 [tool.hf-jobs] 表来携带该配置:
# /// script
# requires-python = ">=3.11"
# dependencies = ["vllm", "datasets"]
#
# [tool.hf-jobs]
# name = "unlimited-ocr"
# image = "vllm/vllm-openai:unlimited-ocr"
# flavor = "l4x1"
# python = "/usr/bin/python3"
# timeout = "2h"
# env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages", BATCH_SIZE = "64" }
# secrets = ["HF_TOKEN"]
# labels = { task = "ocr" }
# volumes = ["hf://datasets/org/pdfs:/input"]
# ///hf jobs uv run ocr.py in_ds out_ds 随后会以正确的运行时启动,而不是在错误的解释器下静默地运行于 CPU 镜像上。普通的 uv run 看不到该表格:[tool.*] 表格属于 PEP 723 的一部分,工具会忽略不属于它们的表格。
支持的键,均为可选:image、flavor、python、timeout、name、namespace、env、secrets、labels、volumes、network_group 和 network_aliases。它们映射到同名的标志(name 作为 name 标签存储,volumes 接受与 -v 相同的 hf://...:/MOUNT_PATH 规范,network_aliases 是 --network-alias 值的列表)。未知的键会引发错误,而不是被静默丢弃——像 flavour 这样的拼写错误正是该功能旨在防止的故障。
所有值都必须是字符串,包括 env 和 labels 的值:-e BATCH_SIZE=64 对应 env = { BATCH_SIZE = "64" },而不是 env = { BATCH_SIZE = 64 }(TOML 会将后者解析为整数,并拒绝该表)。唯一的例外是 timeout,它也接受以秒为单位的整数(timeout = 7200 等同于 timeout = "2h")。
脚本中的值为默认值:显式指定的标志始终优先,且env、secrets、labels和volumes会逐项合并,因此-e和-v可以在脚本声明的基础上进行补充:
# Same script, on bigger hardware, with one extra env var
>>> hf jobs uv run --flavor a10g-large -e BATCH_SIZE=64 ocr.py in_ds out_dsnetwork_aliases 是个例外:Job 所声明的别名构成一个集合,因此 --network-alias 会替换脚本中的列表,而不是向其追加。计划任务(Scheduled Jobs)根本不存在网络组,所以 hf jobs scheduled uv run 会拒绝声明了 network_group 或 network_aliases 的脚本。
secrets 仅列出密钥的 名称:其值始终来自运行脚本者的环境变量,而非脚本本身(HF_TOKEN 同样从 hf auth login 中解析)。如果请求的密钥在本地未设置,则会报错,而不是让 Job 静默地接收到空值。使用 --dry-run 时,它会显示为 <not set>,以便在密钥尚未配置时,脚本的配置仍然可见。
每次运行都会回显其提交的配置,并标记出来自脚本的值。使用 --dry-run 可以仅打印配置而不启动任何内容:
>>> hf jobs uv run --dry-run --flavor a10g-large ocr.py in_ds out_ds
Warning: The script's [tool.hf-jobs] table requests HF_TOKEN: the value(s) from your local environment would be sent to the Job.
Job configuration:
script ocr.py
args in_ds out_ds
image vllm/vllm-openai:unlimited-ocr (from script)
flavor a10g-large
python /usr/bin/python3 (from script)
timeout 2h (from script)
env PYTHONPATH=/usr/local/lib/python3.12/dist-packages (from script)
BATCH_SIZE=64 (from script)
secrets HF_TOKEN=*** (from script)
volumes hf://datasets/org/pdfs:/input (from script)
labels task=ocr (from script)
name=unlimited-ocr (from script)
(dry run) Job not submitted.对于位于 URL 后方的脚本,此方法同样适用:在提交 Job 时,脚本会被下载一次(以读取其头部),然后像本地脚本一样被传输到 Job 中,而无需容器再次下载。该 URL 必须可从您的机器访问。与本地脚本一样,URL 脚本使用保留的
/data工件挂载点;请为您的输入卷使用其他挂载路径。
对于 hf jobs scheduled uv run,此操作会将脚本固定为其创建时的内容。更新源 URL 不再影响未来的运行:如需获取新版本,请重新创建该定时 Job。
--dry-run 也可用于 hf jobs run、hf jobs scheduled run 和 hf jobs scheduled uv run。它会跳过提交和本地卷上传。Docker 和 UV Jobs 的自动生成名称包含解析后的启动配置,因此更改运行时设置或环境变量值会改变名称。
hf jobs scheduled
计划和将在 HF 基础设施上运行的任务。
计划应为 @annually、@yearly、@monthly、@weekly、@daily、@hourly 之一,或为 CRON 计划表达式(例如,"0 9 * * 1" 表示每周一上午 9 点)。
# Schedule a job that runs every hour
>>> hf jobs scheduled run @hourly --name hourly-task python:3.12 python -c 'print("This runs every hour!")'
# Use the CRON syntax
>>> hf jobs scheduled run "*/5 * * * *" python:3.12 python -c 'print("This runs every 5 minutes!")'
# Schedule with GPU
>>> hf jobs scheduled run @hourly --flavor a10g-small pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel \
... python -c 'import torch; print(f"This code ran with the following GPU: {torch.cuda.get_device_name()}")'
# Schedule a UV script
>>> hf jobs scheduled uv run @hourly --name hourly-script my_script.py使用与 hf jobs run 相同的参数来传递环境变量、密钥、超时等。
使用
# List your active scheduled jobs
>>> hf jobs scheduled ls
# Same filters as `hf jobs ls`: --status, --label and --name
>>> hf jobs scheduled ls --all
>>> hf jobs scheduled ls --status suspended
>>> hf jobs scheduled ls --name hourly-task --label env=prod
# Inspect the status of a job
>>> hf jobs scheduled inspect <scheduled_job_id>
# Suspend (pause) a scheduled job
>>> hf jobs scheduled suspend <scheduled_job_id>
# Resume a scheduled job
>>> hf jobs scheduled resume <scheduled_job_id>
# Change future run times (Mondays at 9:00)
>>> hf jobs scheduled reschedule <scheduled_job_id> "0 9 * * 1"
# Trigger a scheduled job to run right now (does not change the schedule)
>>> hf jobs scheduled trigger <scheduled_job_id>
# Delete a scheduled job
>>> hf jobs scheduled delete <scheduled_job_id>hf sandbox
hf sandbox 基于 Jobs 启动隔离的云端机器:创建一个实例,运行命令并实时流式输出,以及将文件复制进出。任何包含 /bin/sh 的 Docker 镜像均可使用。有关 Python API,请参阅 Sandboxes 指南;有关其底层工作原理,请参阅 概念指南。
沙箱功能目前处于实验阶段,其 API 和行为可能会在不另行通知的情况下发生变更。共享沙箱适用于同一信任边界内的工作负载;对于互不信任的工作负载,请使用专用沙箱。
# Create a sandbox (waits until it is ready, prints its id)
>>> hf sandbox create
✓ Sandbox ready id=687f911eaea852de79c4a50a image=python:3.12 elapsed=6.0s
# Attach labels to the underlying Job
>>> hf sandbox create --label controller-run=run-42 --label team=data-infra
# Run commands inside it (output is streamed, exit code is propagated)
>>> hf sandbox exec 687f911eaea852de79c4a50a -- python -c "print('hi')"
hi
# Copy files in and out (docker-style)
>>> hf sandbox cp data.csv 687f911eaea852de79c4a50a:/data/data.csv
>>> hf sandbox cp 687f911eaea852de79c4a50a:/app/results.json results.json
# Terminate a sandbox
>>> hf sandbox kill 687f911eaea852de79c4a50a使用 --flavor 来选择硬件(例如 a10g-small),使用 --idle-timeout 来限制沙箱的生命周期,并使用 -l / --label 为其 Job 附加标签。若要并行启动大量低成本的 CPU 沙箱,可使用 hf sandbox pool create 预热一个池,并通过 hf sandbox create --pool <id> 在其中创建沙箱(参见 沙箱指南)。
将环境变量和密钥传递到沙箱
存在两个独立的通道,它们具有不同的存储特性:
| channel | flags | 专用沙盒 | 池化沙箱 (--pool) |
|---|---|---|---|
| environment | -e / --env, --env-file | 存储在任务元数据中 | 在创建时传递给主机,而非存储在作业元数据中 |
| secrets | -s / --secrets, --secrets-file | 服务器端加密 | 不可用 — 请使用 --env |
# Plain environment variables
>>> hf sandbox create -e LOG_LEVEL=debug --env-file .env
# Secrets, read from your environment by name (nothing sensitive on the command line)
>>> hf sandbox create -s OPENAI_API_KEY -s HF_TOKEN
# Secrets from a file, or piped in on stdin
>>> hf sandbox create --secrets-file .env.secrets
>>> printf 'OPENAI_API_KEY=sk-...\n' | hf sandbox create --secrets-file --s KEY=value 也可以,但该值会记录在 shell 历史记录和进程列表中,因此 CLI 会在 stderr 中发出警告,即使在静默模式下也是如此。池化沙箱会直接拒绝 --secrets:池没有加密密钥通道,hf sandbox create --pool <id> -s KEY=value 会报错并指向 --env。
hf webhooks
hf webhooks 允许你直接在终端中管理 Hugging Face Hub 上的 Webhooks。Webhooks 允许你监听仓库、用户或组织上的事件(推送、讨论等)并触发操作——通过 ping 远程 URL 或在 Hugging Face 基础设施上运行 Job 来实现。
列出 Webhooks
>>> hf webhooks ls
ID URL DISABLED DOMAINS WATCHED
wh-abc123 https://example.com/hook False repo model:bert-base-uncased
wh-def456 https://example.com/other-hook False repo org:HuggingFace使用 --format json 获取机器可读的输出,或使用 -q 仅打印 ID:
>>> hf webhooks ls --format json
>>> hf webhooks ls -q获取 webhook 信息
>>> hf webhooks info wh-abc123以 JSON 格式打印完整的 webhook 详细信息。
创建 Webhook
创建一个 webhook,用于将负载发送到 URL:
>>> hf webhooks create --url https://example.com/hook --watch model:bert-base-uncased
>>> hf webhooks create --url https://example.com/hook --watch org:HuggingFace --watch model:gpt2 --domain repo或者创建一个 Webhook 来触发一个 Job:
>>> hf webhooks create --job-id 687f911eaea852de79c4a50a --watch user:julien-c源 Job 的 secrets 不会复制到 webhook 中。请使用 --secrets 或 --secrets-file(语法与 hf jobs run 相同)将它们传递给被触发的 Job。例如,--secrets HF_TOKEN 会传递你本地的 Hugging Face token:
>>> hf webhooks create --job-id 687f911eaea852de79c4a50a --watch bucket:my-org/my-bucket --secrets HF_TOKEN--watch 选项使用 type:name 格式,其中 type 为 model、dataset、space、bucket、org 或 user 之一。可以重复使用以监视多个项目。使用 --domain 将事件筛选为 repo 或 discussion,并使用 --secret 设置签名密钥。
更新 Webhook
>>> hf webhooks update wh-abc123 --url https://new-url.com/hook
>>> hf webhooks update wh-abc123 --watch model:gpt2 --domain repo仅更改所提供的选项。请注意,指定 --watch 时会替换整个监视列表。
要更新由 Job 触发的 webhook 的密钥,请将 --job-id 与 --secrets 一起传入。列出的密钥将替换已存储的值,而其他所有密钥将保持不变:
>>> hf webhooks update wh-abc123 --job-id 687f911eaea852de79c4a50a --secrets HF_TOKEN启用 / 禁用 webhook
>>> hf webhooks enable wh-abc123
>>> hf webhooks disable wh-abc123删除 webhook
>>> hf webhooks delete wh-abc123
Are you sure you want to delete webhook 'wh-abc123'? [y/N]: y
Webhook deleted: wh-abc123使用 --yes 可跳过确认提示:
>>> hf webhooks delete wh-abc123 --yes所有命令都接受
--token以覆盖身份验证。在任何命令上使用--help即可查看所有选项。
hf endpoints
使用 hf endpoints 可直接在终端中列出、部署、描述和管理 Inference Endpoints。出于兼容性考虑,旧版 hf inference-endpoints 别名仍然可用。
# Lists endpoints in your namespace
>>> hf endpoints ls
# List the hardware you can deploy on
>>> hf endpoints hardware
# Deploy an endpoint from Model Catalog
>>> hf endpoints catalog deploy --repo openai/gpt-oss-120b --name my-endpoint
# Deploy an endpoint from the Hugging Face Hub
>>> hf endpoints deploy my-endpoint --repo gpt2 --framework pytorch --accelerator cpu --instance-size x2 --instance-type intel-icl
# List catalog entries
>>> hf endpoints catalog ls
# Show status and metadata
>>> hf endpoints describe my-endpoint
# Pause the endpoint
>>> hf endpoints pause my-endpoint
# Delete without confirmation prompt
>>> hf endpoints delete my-endpoint --yes添加
--namespace以指定组织,添加--token以覆盖身份验证。
查找用于部署的硬件
hf endpoints deploy 需要五个硬件参数(--vendor、--region、--accelerator、--instance-type 和 --instance-size)。hf endpoints hardware 会列出有效的组合,并显示每个副本每小时的美元价格以及您命名空间的加速器配额:
>>> hf endpoints hardware --vendor aws --region eu-west-1
VENDOR REGION ACCELERATOR INSTANCE_TYPE INSTANCE_SIZE MEMORY_GB GPU_MEMORY_GB PRICE_PER_HOUR QUOTA STATUS
------ --------- ----------- ------------- ------------- --------- ------------- -------------- ----- ---------
aws eu-west-1 cpu intel-spr x1 2.0 0.033 0/60 available
aws eu-west-1 cpu intel-spr x2 4.0 0.067 0/60 available
aws eu-west-1 cpu intel-spr x4 8.0 0.134 0/60 available
aws eu-west-1 cpu intel-spr x8 16.0 0.268 0/60 available
aws eu-west-1 cpu intel-spr x16 32.0 0.536 0/60 available
aws eu-west-1 gpu nvidia-a10g x1 30.0 24 1.0 0/16 available
aws eu-west-1 gpu nvidia-t4 x1 15.0 16 0.5 1/30 available
Hint: Deploy on one of these, e.g.: hf endpoints deploy my-endpoint --repo <repo> --framework <framework> --vendor aws --region eu-west-1 --accelerator cpu --instance-type intel-spr --instance-size x1过滤标志即部署标志(--vendor、--region、--accelerator、--instance-type),因此您用于过滤的条件就是传递给 deploy 的参数。列表中仅包含当前可部署的硬件:状态可用,且您的命名空间中剩余足够的加速器配额以支持一个副本。添加 --all 还可查看已弃用、暂时不可用或配额不足的硬件。--format json 会为每个条目添加剩余的每副本规格(vCPU、架构、加速器数量)。
配额是按命名空间划分的,它决定了哪些行会被列出。如果您正在向某个组织部署,请传入与
deploy相同的--namespace——否则您查看的是个人配额,这既可能隐藏组织可部署的硬件,也可能显示组织无法使用的硬件。
部署自定义容器
若要部署自己的 Docker 镜像而非 Hugging Face 托管的镜像,请同时传入 --framework custom 和 --custom-image。模型仓库会挂载到容器内的 /repository 路径。使用 --container-args(以及可选的 --container-command)来传入带引号的启动字符串,使用 --env/--secrets 来注入环境变量,并使用 --type 来设置访问类型(public、authenticated 或 private):
>>> hf endpoints deploy nex-n2-pro \
--repo nex-agi/Nex-N2-Pro \
--framework custom \
--accelerator gpu --vendor aws --region us-east-1 \
--instance-type nvidia-h200 --instance-size x8 \
--custom-image nexagi/sglang:v0.5.12 \
--health-route /health --port 30000 \
--container-args "--reasoning-parser qwen3 --tool-call-parser qwen3_coder --mamba-scheduler-strategy extra_buffer --tp 8" \
--env MODEL_ID=/repository \
--type authenticated--container-args 和 --container-command 并不局限于自定义镜像:它们对应于 API 负载中的 model.args 和 model.command,同样适用于托管镜像。对于现有端点,这两个标志会替换当前值,而不是追加,因此请传入您想要的完整列表,并使用空字符串来清除它。从目录部署的端点已经带有调优过的引擎标志,因此在覆盖之前,请检查 hf endpoints describe:
>>> hf endpoints update my-endpoint \
--container-args "--enable-auto-tool-choice --tool-call-parser lfm2"部署托管引擎镜像
单独使用 --custom-image 可以部署任意容器。添加 --engine 可将其作为 API 管理的引擎之一运行(vllm、sglang、tgi、tei、llamacpp、hf-serve 等),从而启用该引擎的配置项,包括 --tensor-parallel-size 和 --data-parallel-size。vLLM 和 SGLang 默认使用一个加速器,而端点会获取其实例的所有加速器,因此如果两者均未设置,模型将只加载到一个加速器上,其余加速器处于空闲状态,但系统仍会报告健康状态。正因如此,API 现在会拒绝该配置:
>>> hf endpoints deploy gpt-oss-120b-vllm \
--repo openai/gpt-oss-120b \
--framework custom \
--accelerator gpu --vendor aws --region us-east-1 \
--instance-type nvidia-h200 --instance-size x8 \
--engine vllm --custom-image vllm/vllm-openai:v0.23.0 \
--tensor-parallel-size 8这与上述的 --container-args "... --tp 8" 不同:--tensor-parallel-size 会写入引擎的 model.image 配置,API 会依据该配置来校验实例的加速器数量;而 --container-args 仅会在命令行末尾追加一个标志。对于没有 image 字段的引擎标志,以及没有并行度字段的普通自定义容器,请使用 --container-args。
若要重新调整正在运行的端点,请单独传入尺寸。model.image 作为整体发送,需要 url,因此会获取端点当前的图像并就地更新:
>>> hf endpoints update gpt-oss-120b-vllm --tensor-parallel-size 4 --data-parallel-size 2hf endpoints update 同样支持 --custom-image 和 --engine,这是通过 CLI 更改端点镜像的唯一方式。该操作会替换 model.image 而不是对其进行修补,因此请先运行 hf endpoints describe,并传回您希望保留的内容。
hf endpoints 目录
使用 hf endpoints catalog 与 Inference Endpoints 模型目录进行交互。您可以直接从目录中部署模型,并使用优化后的配置。
每个目录模型都附带一个或多个配方:即针对该模型经过测试的硬件与引擎组合。hf endpoints catalog ls会为每个配方打印一行,因此同时具有 GPU 和 Neuron 配方的模型会显示两次:
# List available catalog models
>>> hf endpoints catalog ls
REPO_ID TASK LICENSE ACCELERATOR ENGINE GGUF_FILE RECIPE_ID
----------------------------------- ------------------ ---------- ----------- -------- ----------------------------- -------------------------
meta-llama/Llama-3.1-8B-Instruct text-generation Llama 3.1 gpu vllm sizzling-biryani-g4xsi1ac
meta-llama/Llama-3.1-8B-Instruct text-generation Llama 3.1 neuron vllmNeuron artisanal-quinoa-yz9ynamx
bartowski/QwQ-32B-Preview-GGUF text-generation Apache 2.0 gpu llamacpp QwQ-32B-Preview-Q8_0.gguf baked-orange-m863gx7d
# Narrow it down
>>> hf endpoints catalog ls --engine vllm --task text-generation --search llama --limit 10--accelerator、--engine、--license、--task、--search 和 --limit 均在服务器端进行过滤。
# Deploy the default recipe of a model
>>> hf endpoints catalog deploy --repo meta-llama/Llama-3.2-1B-Instruct
# Deploy an exact recipe listed above
>>> hf endpoints catalog deploy --recipe artisanal-quinoa-yz9ynamx
# Deploy with a custom name
>>> hf endpoints catalog deploy --repo meta-llama/Llama-3.2-1B-Instruct --name my-llama-endpoint使用 --repo 时,可以通过 --accelerator(cpu、gpu、neuron)和 --gguf-file(针对每种量化对应一个 recipe 的模型)来缩小默认 recipe 的范围。这两个参数与 --recipe 互斥,因为后者已经指定了单个 recipe。