← 返回命令列表

Linux command

hf 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Log in to Hugging Face

hf auth login

Download a model

hf download [gpt2]

Download specific files

hf download [meta-llama/Llama-2-7b] [config.json] [model.safetensors]

Upload a folder

hf upload [username/my-model] [./models] [.]

List trending models

hf models ls

Run a job on GPU

hf jobs run --flavor [a10g-small] [pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel] [python train.py]

View cache usage

hf cache ls

说明

hf (formerly huggingface-cli) is the official command-line interface for Hugging Face Hub. It provides direct terminal access to download models and datasets, upload files, manage repositories, run compute jobs, and interact with the ML community platform. The CLI follows a consistent hf resource action pattern. Files are cached locally in ~/.cache/huggingface/hub/ with smart deduplication. The download command supports partial downloads with --include/--exclude patterns and resumable transfers. hf jobs enables running code on Hugging Face infrastructure including GPUs (T4, A10G, A100) and TPUs, with Docker-like commands. Jobs support environment variables, secrets, scheduled execution, and UV scripts for self-contained Python tasks. Authentication is managed via hf auth login which stores tokens locally. Tokens can also be set via the HF_TOKEN environment variable for scripting.

参数

--repo-type _type_
Repository type: model, dataset, or space.
--revision _ref_
Specific revision (branch, tag, or commit hash).
--local-dir _path_
Download to specific local directory instead of cache.
--include _pattern_
Include files matching glob pattern.
--exclude _pattern_
Exclude files matching glob pattern.
--token _token_
Authentication token for private repos.
--quiet
Suppress verbose output, print only final result.
--flavor _hardware_
Hardware for jobs: cpu-basic, t4-small, a10g-small, a100-large, etc.
--timeout _duration_
Job timeout with units: 30m, 2h, 1d.
--help
Display help for any command.

FAQ

What is the hf command used for?

hf (formerly huggingface-cli) is the official command-line interface for Hugging Face Hub. It provides direct terminal access to download models and datasets, upload files, manage repositories, run compute jobs, and interact with the ML community platform. The CLI follows a consistent hf resource action pattern. Files are cached locally in ~/.cache/huggingface/hub/ with smart deduplication. The download command supports partial downloads with --include/--exclude patterns and resumable transfers. hf jobs enables running code on Hugging Face infrastructure including GPUs (T4, A10G, A100) and TPUs, with Docker-like commands. Jobs support environment variables, secrets, scheduled execution, and UV scripts for self-contained Python tasks. Authentication is managed via hf auth login which stores tokens locally. Tokens can also be set via the HF_TOKEN environment variable for scripting.

How do I run a basic hf example?

Run `hf auth login` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --repo-type _type_ do in hf?

Repository type: model, dataset, or space.