opensi·si

You need to be authenticated with hf auth login to run Jobs, and use a token with the permission to start and manage Jobs.

Configuration

Authentication

You need to be authenticated with hf auth login to run Jobs, and use a token with the permission to start and manage Jobs.

Alternatively, pass a Hugging Face token manually with --token in the CLI, or the token argument in Python.

Passing arguments

Use -- to separate Jobs options from your command or script and its arguments. Options after --, such as --help or --timeout, are passed through rather than interpreted by Jobs. This applies to both UV and Docker Jobs.

hf jobs uv run --flavor t4-small -- script.py --early-stopping-patience 3
               └─ Jobs option ┘    └─ script + arguments ─────────────┘

UV Jobs

Specify the UV script or python command to run as you would with UV:

>>> hf jobs uv run train.py
>>> hf jobs uv run python -c 'print("Hello from the cloud!")'

The hf jobs uv run command accepts an UV argument like --with and --python. The --with argument lets you specify python dependencies, and --python lets you choose the python version to use:

>>> hf jobs uv run --with trl train.py
>>> hf jobs uv run --python 3.12 train.py

For example, pass arguments to a command using --:

>>> hf jobs uv run --with trl-jobs -- trl-jobs sft --model_name Qwen/Qwen3-0.6B --dataset_name trl-lib/Capybara

Find the list of all arguments in the CLI documentation and the UV Commands documentation.

By default, UV Jobs run with the ghcr.io/astral-sh/uv:python3.12-bookworm Docker image, but you can use another image as long as it has UV installed, using --image <docker-image>.

See Using Docker images for choosing an image and understanding how its environment interacts with UV dependencies.

Define the launch config in the script

A script that only runs correctly on a specific runtime (a given image, GPU flavor or system interpreter) can carry that configuration with it, in an optional [tool.hf-jobs] table of its PEP 723 header:

# /// script
# requires-python = ">=3.11"
# dependencies = ["vllm", "datasets"]
#
# [tool.hf-jobs]
# image   = "vllm/vllm-openai:unlimited-ocr"
# flavor  = "l4x1"
# python  = "/usr/bin/python3"
# secrets = ["HF_TOKEN"]
# ///

hf jobs uv run ocr.py then launches on that image and hardware. A plain uv run ignores the table, as [tool.*] tables are part of PEP 723 and tools skip the ones they don't own.

Supported keys, all optional: image, flavor, python, timeout, name, namespace, env, secrets, labels, volumes, network_group and network_aliases. They map to the flags of the same name. Values from the script are defaults: an explicit flag always wins, and env, secrets, labels and volumes are merged entry by entry, so -e and -v add to what the script declares. An unknown key is an error, and secrets only lists names: values come from the environment of whoever runs the script, and a secret that is not set locally is an error too.

Use --dry-run to print the resolved configuration without submitting; values that come from the script are marked (from script). See the hf CLI guide for the full merge rules.

Warning The table is read by the hf CLI only. run_uv_job() and create_scheduled_uv_job() ignore it, so pass image=, flavor=, ... explicitly from Python.

Docker Jobs

Specify the Docker image and the command to run as you would with docker:

>>> hf jobs run ubuntu echo "Hello from the cloud!"

Here, --help reaches Python rather than showing Jobs help:

>>> hf jobs run --flavor cpu-basic python:3.12 -- python --help

Find the list of all arguments in the CLI documentation.

See Using Docker images for examples using existing images and images built by Docker Spaces.

Environment variables and Secrets

Built-in environment variables

Similarly to the built-in environment variables in Spaces, Jobs automatically provide the following environment variables inside the container:

Variable Description
JOB_ID The unique identifier of the current job (e.g., 699d874f1aad19adb8aaeadc). This is the same ID shown in the UI and the job URL.
ACCELERATOR The type of accelerator available (e.g., t4-medium, a10g-small, a100x4), or none for CPU-only jobs.
CPU_CORES The number of CPU cores allocated to the job.
MEMORY The amount of memory allocated to the job (e.g., 8Gi).
HF_NETWORK_GROUP_HOSTNAME Hostname resolving to every job in the job's network group. Only set when the job declares one.
HF_NETWORK_GROUP_PREFIX Prefix to prepend to an alias to get the hostname of the group members claiming it (e.g., ${HF_NETWORK_GROUP_PREFIX}master). Only set when the job declares a network group.

You can use these variables to track outputs, adapt your code to available resources, or reference the current job programmatically:

# 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\")}')"

User-defined environment variables

You can pass environment variables to your job using

# Pass environment variables
>>> hf jobs uv run -e FOO=foo -e BAR=bar python -c 'import os; print(os.environ["FOO"], os.environ["BAR"])'
# Pass an environment from a local .env file
>>> hf jobs uv run --env-file .env python -c 'import os; print(os.environ["FOO"], os.environ["BAR"])'
# Pass secrets - they will be encrypted server side
>>> hf jobs uv run -s MY_SECRET=psswrd 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 uv run --secrets-file .env.secrets python -c 'import os; print(os.environ["MY_SECRET"])'

Tip Use --secrets HF_TOKEN to pass your local Hugging Face token implicitly. With this syntax, the secret is retrieved from the environment variable. For HF_TOKEN, it may read the token file located in the Hugging Face home folder if the environment variable is unset.

Volumes

Mount Hugging Face repositories (models, datasets), Storage Buckets, or local directories as volumes in your job container using -v or --volume. Hub sources use the hf:// URL scheme: hf://[TYPE/]SOURCE:/MOUNT_PATH[:ro]; a local directory is passed directly as the source.

Tip Because mounted files are fetched lazily, mounting lets a Job work with datasets far larger than its local disk. See Process Large Datasets for mounting, streaming, and processing big data on Jobs.

Volume types:

Type Example
Model repo -v hf://openai/gpt-oss-120b:/model
Dataset repo -v hf://datasets/stanfordnlp/imdb:/data
Storage bucket -v hf://buckets/username/my-bucket:/mnt
Subfolder -v hf://datasets/org/my-dataset/train:/data
Local directory -v ./training-data:/data

Then use the mounted volume as a local directory inside the container:

# Mount a dataset and query it with DuckDB
>>> hf jobs run -v hf://datasets/stanfordnlp/imdb:/dataset \
...     duckdb/duckdb duckdb -c "SELECT * FROM '/dataset/**/*.parquet' LIMIT 5"

# Mount a bucket to save training checkpoints
>>> hf jobs uv run -v hf://buckets/username/my-bucket:/training-outputs \
...     sft.py --output-dir /training-outputs/training-v3-final

Multiple volumes can be mounted by repeating the -v flag:

>>> hf jobs run -v hf://datasets/username/my-dataset:/data -v hf://buckets/username/my-bucket:/output \
...     python:3.12 python script.py

Models and datasets are always mounted read-only. Storage buckets are read-write by default, which is useful for saving outputs, checkpoints, or intermediate results. Use :ro to mount a bucket in read-only mode:

>>> hf jobs run -v hf://buckets/username/my-bucket:/mnt:ro python:3.12 ls /mnt

Local directories

Passing a local directory as the source syncs it to your private jobs-artifacts Storage Bucket (created automatically) before the Job starts, then mounts it in the container. Local directories are mounted read-only by default; use :rw to write outputs:

>>> hf jobs uv run -v ./pdfs:/input -v ./md-out:/output:rw ocr.py

Re-syncing the same directory only uploads new or modified files. To retrieve files a Job wrote to a read-write volume, sync its bucket folder back once the Job is over — the CLI prints the exact hf buckets sync command when the Job starts. Scheduled jobs work too: the directory is synced once when the schedule is created, and every trigger mounts the same folder. In Python, use sync_job_volume.

In Python, use the Volume class:

from huggingface_hub import Volume, run_job

job = run_job(
    image="python:3.12",
    command=["python", "-c", "import os; print(os.listdir('/data'))"],
    volumes=[
        Volume(type="dataset", source="username/my-dataset", mount_path="/data"),
        Volume(type="bucket", source="username/my-bucket", mount_path="/output"),
    ],
)

Note Volume mounting requires huggingface_hub >= 1.8.0. See the Python client documentation and installation guide for more details.

Hardware flavor

Run jobs on GPUs or TPUs with the flavor argument. For example, to run a PyTorch job on an A10G GPU:

>>> hf jobs uv run --with torch --flavor a10g-small python -c "import torch; print(f'This code ran with the following GPU: {torch.cuda.get_device_name()}')"

Running this will show the following output!

This code ran with the following GPU: NVIDIA A10G

Here is another example to run a fine-tuning script like trl/scripts/sft.py:

>>> hf jobs uv run --with trl --flavor a10g-small -s HF_TOKEN -- sft.py --model_name_or_path Qwen/Qwen2-0.5B ...

Tip For comprehensive guidance on running model training jobs with TRL on Hugging Face infrastructure, check out the TRL Jobs Training documentation. It covers fine-tuning recipes, hardware selection, and best practices for training models efficiently.

See the list of available --flavor options using the hf jobs hardware command (default is cpu-basic):

>>> hf jobs hardware
name             pretty name             cpu       ram      storage   accelerator               cost/min  cost/hour
cpu-basic        CPU Basic               2 vCPU    16 GB    50 GB                               $0.0002   $0.01
cpu-upgrade      CPU Upgrade             8 vCPU    32 GB    50 GB                               $0.0005   $0.03
cpu-performance  CPU Performance         32 vCPU   256 GB   1024 GB                             $0.0317   $1.90
cpu-xl           CPU XL                  16 vCPU   124 GB   1000 GB                             $0.0167   $1.00
t4-small         Nvidia T4 - small       4 vCPU    15 GB    50 GB     1x T4 (16 GB)             $0.0067   $0.40
t4-medium        Nvidia T4 - medium      8 vCPU    30 GB    100 GB    1x T4 (16 GB)             $0.0100   $0.60
a10g-small       Nvidia A10G - small     4 vCPU    15 GB    110 GB    1x A10G (24 GB)           $0.0167   $1.00
a10g-large       Nvidia A10G - large     12 vCPU   46 GB    200 GB    1x A10G (24 GB)           $0.0250   $1.50
a10g-largex2     2x Nvidia A10G - large  24 vCPU   92 GB    1000 GB   2x A10G (48 GB)           $0.0500   $3.00
a10g-largex4     4x Nvidia A10G - large  48 vCPU   184 GB   2000 GB   4x A10G (96 GB)           $0.0833   $5.00
a100-large       Nvidia A100 - large     12 vCPU   142 GB   1000 GB   1x A100 (80 GB)           $0.0417   $2.50
a100x4           4x Nvidia A100          48 vCPU   568 GB   4000 GB   4x A100 (320 GB)          $0.1667   $10.00
a100x8           8x Nvidia A100          96 vCPU   1136 GB  8000 GB   8x A100 (640 GB)          $0.3333   $20.00
h200             Nvidia H200             23 vCPU   256 GB   3000 GB   1x H200 (141 GB)          $0.0833   $5.00
h200x2           Nvidia H200             46 vCPU   512 GB   6000 GB   2x H200 (282 GB)          $0.1667   $10.00
h200x4           Nvidia H200             92 vCPU   1024 GB  12000 GB  4x H200 (564 GB)          $0.3333   $20.00
h200x8           Nvidia H200             184 vCPU  2048 GB  24000 GB  8x H200 (1128 GB)         $0.6667   $40.00
rtx-pro-6000     Nvidia RTX PRO 6000     23 vCPU   256 GB   475 GB    1x RTX PRO 6000 (96 GB)   $0.0458   $2.75
rtx-pro-6000x2   Nvidia RTX PRO 6000     46 vCPU   512 GB   950 GB    2x RTX PRO 6000 (192 GB)  $0.0917   $5.50
rtx-pro-6000x4   Nvidia RTX PRO 6000     92 vCPU   1024 GB  1900 GB   4x RTX PRO 6000 (384 GB)  $0.1833   $11.00
rtx-pro-6000x8   Nvidia RTX PRO 6000     184 vCPU  2048 GB  3800 GB   8x RTX PRO 6000 (768 GB)  $0.3667   $22.00
l4x1             1x Nvidia L4            8 vCPU    30 GB    400 GB    1x L4 (24 GB)             $0.0133   $0.80
l4x4             4x Nvidia L4            48 vCPU   186 GB   3200 GB   4x L4 (96 GB)             $0.0633   $3.80
l40sx1           1x Nvidia L40S          8 vCPU    62 GB    380 GB    1x L40S (48 GB)           $0.0300   $1.80
l40sx4           4x Nvidia L40S          48 vCPU   382 GB   3200 GB   4x L40S (192 GB)          $0.1383   $8.30
l40sx8           8x Nvidia L40S          192 vCPU  1534 GB  6500 GB   8x L40S (384 GB)          $0.3917   $23.50