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 mini language
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
.
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
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
[matrix.parameters]
task = ["sst2", "sst5"]
seed = 42
evaluation-strategy = ["simple", "fast"]
will generate the following sbatch script and submit it to the cluster (use --dry-run
to only print the script):
#!/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-15
task=( 'sst2' 'sst5' )
workdir='$HOME/evoprompt'
rest=( '1' '2' )
seed='42'
evaluation_strategy=( 'simple' 'early-stopping' 'shortest-first' 'hardest-first' )
echo --cwd ${workdir} python $HOME/evoprompt/main.py --task ${task[$(( (SLURM_ARRAY_TASK_ID / 1) % 2 ))]} --evaluation-strategy ${evaluation_strategy[$(( (SLURM_ARRAY_TASK_ID / 4) % 4 ))]} --seed ${seed} --rest=${rest[$(( (SLURM_ARRAY_TASK_ID / 2) % 2 ))]}
which will run the following commands on the cluster:
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy simple --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy shortest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy hardest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy hardest-first --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy simple --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy simple --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy simple --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy early-stopping --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy early-stopping --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy early-stopping --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst5 --evaluation-strategy early-stopping --seed 42 --rest=2
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.py --task sst2 --evaluation-strategy shortest-first --seed 42 --rest=1
echo --cwd $HOME/evoprompt python /home/ma/g/griesshaber/evoprompt/main.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
Built Distribution
File details
Details for the file slurmbatcher-0.3.0.tar.gz
.
File metadata
- Download URL: slurmbatcher-0.3.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55afc47c6608c5ebe837ccbc99e905dd747269a708932795b93d9bcf22f4d36f |
|
MD5 | 7096880b88027a8e2c1afa1cbab38ac5 |
|
BLAKE2b-256 | 3acebc9dd350c0d9fb42ad56416c135be94bf47984be9efefec109ca22846045 |
File details
Details for the file slurmbatcher-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: slurmbatcher-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | e180d87688bc76cdc57eb41020f38da53df1da6499daba2706c6bfbe9b688ae1 |
|
MD5 | 63e4fd4f63ade42266465a299680d358 |
|
BLAKE2b-256 | dd44a82acdcfb7dcb104744bbe18fc7795fd77e333e445d220d8947fd57dfe86 |