Skip to main content

A Prefect 3 TaskRunner that submits tasks to SLURM clusters via submitit

Project description

prefect-submitit

A Prefect 3 TaskRunner that submits tasks to SLURM clusters via submitit.

Features

  • Single task submission -- submit individual Prefect tasks as SLURM jobs
  • Job arrays -- submit task.map() calls as SLURM job arrays with automatic chunking when the array exceeds cluster limits
  • Batched execution -- group multiple items per SLURM job with units_per_worker to reduce scheduling overhead
  • Local mode -- swap to local execution for testing without changing your flow code (execution_mode="local" or SLURM_TASKRUNNER_BACKEND=local)
  • Prefect UI integration -- task run names include SLURM job IDs for easy cross-referencing with squeue/sacct

Installation

pip install prefect-submitit

Or with conda (after the first conda-forge release):

conda install -c conda-forge prefect-submitit

Quick Start

from prefect import flow, task
from prefect_submitit import SlurmTaskRunner

@task
def add(x: int, y: int) -> int:
    return x + y

@flow(task_runner=SlurmTaskRunner(partition="cpu", time_limit="00:10:00"))
def my_flow():
    # Single task
    future = add.submit(1, 2)
    print(future.result())  # 3

    # Map over inputs (submitted as a SLURM job array)
    futures = add.map([1, 2, 3], [4, 5, 6])
    print([f.result() for f in futures])  # [5, 7, 9]

if __name__ == "__main__":
    my_flow()

Configuration

SlurmTaskRunner(
    partition="gpu",          # SLURM partition
    time_limit="04:00:00",    # Wall time (HH:MM:SS)
    mem_gb=16,                # Memory per job
    gpus_per_node=1,          # GPUs per job
    units_per_worker=10,      # Items per SLURM job (batched mode)
    execution_mode="slurm",   # "slurm" or "local"
    slurm_array_parallelism=100,  # Max concurrent array tasks
    log_folder="slurm_logs",  # Where submitit writes logs
    fail_on_error=True,       # Raise on SLURM job failure
)

Any additional keyword arguments are passed through to submitit (e.g. slurm_gres="gpu:a100:1").

Local Testing

Set the environment variable to skip SLURM entirely:

export SLURM_TASKRUNNER_BACKEND=local

Or pass it directly:

SlurmTaskRunner(execution_mode="local")

Development

Requires Pixi:

pixi install
pixi run -e dev test
pixi run -e dev fmt

License

BSD 3-Clause. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect_submitit-0.1.2.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_submitit-0.1.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file prefect_submitit-0.1.2.tar.gz.

File metadata

  • Download URL: prefect_submitit-0.1.2.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for prefect_submitit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8ec1df0813d73c575e468c90dac5d3cdcd9a5a409c08187d2244243d32005849
MD5 5493844ace0e59a0ab2088fc742fd9bc
BLAKE2b-256 7943ce4d735e606468acae8de326dca5892d6b48ed1b3ecf208a6a9d509fc68d

See more details on using hashes here.

File details

Details for the file prefect_submitit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_submitit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aab1ad2cdaeff71fbb0c5ec104f9f80ebcec42e069fd021ec6ad03dba97a6776
MD5 b90ba3cf56e98bdb0e272c6a05a31fdf
BLAKE2b-256 43006bd02c770ef370300f81592825d1b15149af28fc4bea92749621dc8957a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page