Skip to main content

No project description provided

Project description

slurmbatcher

Easily create sbatch scripts for running jobs on a cluster.

Installation

pip install slurmbatcher

Configuration

Create a configuration file in toml format. The configuration file must contain a command_template and a matrix.parameters section. The command_template is a string that will be used to generate the sbatch script. The matrix.parameters section contains the parameters that will be used to generate the cartesian product of all possible parameter combinations. Additional parameters can be added to the sbatch.parameters section to specify sbatch parameters.

command_template

The command_template is a string that will be used to generate the commands that are run on the cluster. You can use placeholders in the command_template string to insert parameters from the matrix.parameters section. Placeholders are enclosed in curly braces that contain the name of the parameter to be inserted. You can also use the special **parameters placeholder to insert all parameters as keyword arguments. The **parameters placeholder will insert all parameters as keyword arguments in the form --parameter-name value.

The command template can contain arbitrary bash code and span multiple lines. The command template will be written to the sbatch script as is. The placeholders will be replaced with the corresponding values from the matrix configuration.

command_template mini language

You can use format specifiers to format the inserted values. The format specifier is a colon followed by a format string. The format string is passed to the python format method. For example, {seed:04d} will format the seed parameter as a zero-padded 4-digit integer. Additionally the following format specifiers are available:

  • :value: gets replaced with the value of the parameter in the current matrix configuration (same as no format specifier)
  • :name: gets replaced with the name of the parameter
  • :option: gets replaces with a keyword argument in the form --name value

sbatch.parameters section

You can specify additional parameters for the sbatch script in the sbatch.parameters section. The parameters are written as #SBATCH --parameter-name=value lines in the generated sbatch script. You can use all parameters available in the sbatch command, except for array as this is automatically generated.

matrix.parameters section

The matrix.parameters section contains the parameters that will be used to generate the cartesian product of all possible parameter combinations. Each parameter is specified as a list of values or a scalar. The cartesian product of all parameter values will be generated and each combination will be used to generate a task in the array job.

matrix.jobs section

If you specify parameters in the matrix.jobs section instead of the matrix.parameters section, the cartesian product of all parameter values will be generated and each combination will be used to generate a seperate job. This can be used if you want to split the array into different jobs for a better overview (e.g. to send emails for each job separately). Technically this will create multiple sbatch scripts that will be submitted to the cluster for each combination in the cartesian product of the parameters.

Example:

running slurmbatcher example.toml with the following example.toml:

command_template="""\
    echo --cwd {workdir} \
    python $HOME/evoprompt/main.py --task {task} {evaluation-strategy:option} --{seed:name} {seed} {**parameters}\
"""
[sbatch.parameters]
partition = "gpu"
gpus = 1
mail-type = "END,FAIL"
mail-user = "griesshaber@hdm-stuttgart.de"
cpus-per-task = 4
nodelist = "tars"


[matrix.parameters]
workdir="$HOME/evoprompt"
seed = 42
evaluation-strategy = ["shortest-first", "hardest-first"]
rest=["1", 2]

[matrix.jobs]
task = ["sst2", "sst5"]

will generate 2 sbatch scripts and submit it to the cluster. The generated sbatch scripts will look like this:

 1 #!/bin/bash
 #SBATCH --partition=gpu
 #SBATCH --gpus=1
 #SBATCH --mail-type=END,FAIL
 #SBATCH --mail-user=griesshaber@hdm-stuttgart.de
 #SBATCH --cpus-per-task=4
 #SBATCH --nodelist=tars
 #SBATCH --array=0-3

task='sst5'
workdir='$HOME/evoprompt'

seed='42'

rest_list=( '1' '2' )
rest=${rest_list[$(((SLURM_ARRAY_TASK_ID / 1) % 1))]}

evaluation_strategy_list=( 'simple' 'early-stopping' 'shortest-first' 'hardest-first' )
evaluation_strategy=${evaluation_strategy_list[$(((SLURM_ARRAY_TASK_ID / 2) % 2))]}

python ${workdir}/train.py --task ${task} --evaluation-strategy ${evaluation_strategy} --seed ${seed} --rest=${rest}```

which will run the following commands on the cluster in 2 separate jobs:

# commands in Job 1
python $HOME/evoprompt/train.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=2
python $HOME/evoprompt/train.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=1
python $HOME/evoprompt/train.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=2
python $HOME/evoprompt/train.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=1

# commands in Job 2
python $HOME/evoprompt/train.py --task sst5 --evaluation-strategy shortest-first --seed 42 --rest=2
python $HOME/evoprompt/train.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=1
python $HOME/evoprompt/train.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=2
python $HOME/evoprompt/train.py --task sst5 --evaluation-strategy shortest-first --seed 42 --rest=1

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

slurmbatcher-0.3.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

slurmbatcher-0.3.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file slurmbatcher-0.3.3.tar.gz.

File metadata

  • Download URL: slurmbatcher-0.3.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for slurmbatcher-0.3.3.tar.gz
Algorithm Hash digest
SHA256 37811c4511dbec2e3ec18a71983c8ecd777fe9be9d79b63f294ccd4b34de607f
MD5 452615772fdf1fad62b62d9861175066
BLAKE2b-256 c57e8c3a5dcd85e263587e966b163beaa23f8bd2e4bd2cd144c5082eac60286b

See more details on using hashes here.

File details

Details for the file slurmbatcher-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: slurmbatcher-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/24.0.0

File hashes

Hashes for slurmbatcher-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 09df229b5868933093de4a83b6fb8ced88e2d5be2ace4e91e1ef4ec05de08026
MD5 c27da7085d422039c2fa4c3f3613a2fb
BLAKE2b-256 a59ba98626690806bce688dc7812f4dcb37e831fd83a2bf9b9d9efe6a0ec6293

See more details on using hashes here.

Supported by

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