Hub Python 函式庫文件

Jobs

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

作業 (Jobs)

請查閱 HfApi 文件頁面,以獲取在 Hub 上管理作業的方法參考。

資料結構

JobInfo

class huggingface_hub.JobInfo

< >

( **kwargs )

參數

  • id (str) — 作業 ID。
  • created_at (datetimeNone) — 作業建立時間。
  • started_at (datetimeNone) — 作業開始運行的時間。當作業仍處於排程階段時為 None。
  • finished_at (datetimeNone) — 作業完成時間。當作業仍處於排程或執行階段時為 None。
  • docker_image (strNone) — 用於該作業的 Docker Hub Docker 映像檔。如果存在 space_id,則可以為 None。
  • space_id (strNone) — 用於該作業的 Hugging Face Spaces Docker 映像檔。如果存在 docker_image,則可以為 None。
  • command (list[str]None) — 作業的指令,例如 ["python", "-c", "print('hello world')"]
  • arguments (list[str]None) — 傳遞給指令的參數
  • environment (dict[str]None) — 以字典形式表示的作業環境變數。
  • secrets (dict[str]None) — 作業的密鑰環境變數(已加密)。
  • flavor (strNone) — 硬體類型,與 Hugging Face Spaces 相同。請參閱 SpaceHardware 以了解可能的值。例如 "cpu-basic"
  • labels (dict[str, str]None) — 要附加到作業的標籤(鍵值對)。
  • volumes (list[Volume]None) — 掛載在作業容器中的磁碟區(儲存桶、模型、資料集、Spaces)。
  • status — (JobStatusNone):作業狀態,例如 JobStatus(stage="RUNNING", message=None)。請參閱 JobStage 以了解可能的階段值。
  • durations (JobDurationsNone) — 作業的時間細分。適用於所有作業狀態,包括 SCHEDULING。
  • owner — (JobOwnerNone):作業擁有者,例如 JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")
  • initiator (JobInitiatorNone) — 觸發作業的原因,例如用於排程作業 (cron-triggered run) 的 JobInitiator(type="scheduled-job", id="...")

包含有關作業的資訊。

範例

>>> from huggingface_hub import run_job
>>> job = run_job(
...     image="python:3.12",
...     command=["python", "-c", "print('Hello from the cloud!')"]
... )
>>> job
JobInfo(id='687fb701029421ae5549d998', created_at=datetime.datetime(2025, 7, 22, 16, 6, 25, 79000, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 7, 22, 16, 6, 31, 79000, tzinfo=datetime.timezone.utc), finished_at=None, docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', labels=None, status=JobStatus(stage='RUNNING', message=None), durations=JobDurations(scheduling_secs=6, running_secs=2, total_secs=8), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), initiator=JobInitiator(type='user', id='5e9ecfc04957053f60648a3e', name='lhoestq'), endpoint='https://huggingface.co', url='https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998')
>>> job.id
'687fb701029421ae5549d998'
>>> job.url
'https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998'
>>> job.status.stage
'RUNNING'

JobOwner

class huggingface_hub.JobOwner

< >

( id: str name: str type: str )

JobStage

class huggingface_hub.JobStage

< >

( value names = None module = None qualname = None type = None start = 1 )

Hub 上作業可能階段的列舉。

值可以與字串進行比較

assert JobStage.COMPLETED == "COMPLETED"
可能的值為: `COMPLETED`、`CANCELED`、`ERROR`、`DELETED`、`SCHEDULING`、`RUNNING`。取自 https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (私人網址)。

JobStatus

class huggingface_hub.JobStatus

< >

( stage: JobStage message: str | None )

Volume

class huggingface_hub.Volume

< >

( **kwargs )

參數

  • type (str) — 磁碟區類型: "bucket""model""dataset""space"
  • source (str) — 來源識別碼,例如 "username/my-bucket""username/my-model"
  • mount_path (str) — 容器內的掛載路徑,例如 "/data"。必須以 / 開頭。
  • revision (strNone) — Git 版本(僅適用於儲存庫,預設為 "main")。
  • read_only (boolNone) — 唯讀掛載。儲存庫強制為 True,儲存桶預設為 False
  • path (strNone) — 要掛載的儲存桶/儲存庫內的子資料夾前綴,例如 "path/to/dir"

描述在 Space 或作業容器中掛載的磁碟區。

to_dict

< >

( )

序列化為 Hub API 預期的 JSON 酬載。

to_uri

< >

( )

以 CLI 預期的格式回傳磁碟區作為 HF 掛載 URI。

在 GitHub 上更新

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