Skip to main content

Batch bsub launcher

Pure python script to create batched GPU jobs using BSUB

Installation / Update

pip install -U git+https://github.com/ferrine/gpu-batch.sub
# or
pip install -U gpu-batch-sub

Example Config

Default config for script (location ~/.gpubatch.conf) should look like

> cat config
[gpubatch]
batch=-1
gpu=1
; use ';' for comments
;paths are relative
out=bsub-log/out
err=bsub-log/err
hosts=host1 host2 host3
queue=normal
header=
    #BSUB option1
    #BSUB option2
    #BSUB option3
    custom code you want

Examples

# batch by -1
# yields 1 job
> gpu-batch.sub 'python script_1.py' 'python script_2.py' 'python script_2.py --other-args'

# batch by 2
# yields 2 jobs
> gpu-batch.sub -b 2 'python script_1.py' 'python script_2.py' 'python script_2.py --other-args'

# run from file
> gpu-batch.sub -b 2 -f filewithjobs1 filewithjobs2 filewithjobs3
> cat filewithjobs1
multiline \ # comments are ok
    job number one
# comments here are ok too
multiline \
    job number two

# naming jobs
# special syntax is applied (no spaces allowed in jobname)
gpu-batch.sub 'jobname : python script1.py'

# running sequential jobs
# yields 2 jobs with sequentially running commands
> gpu-batch.sub -b 2 -s 'python script_1.py' 'python script_2.py' 'python script_2.py --other-args'

Checking Command Submission

--debug flag helps to print expected submissions to LSF

> gpu-batch.sub --debug --batch 2 command1 command2 named:command3
>>>>>>>>>>
#SUBMIT: 0
vvvvvvvvvv
#!/bin/sh
#BSUB -J gpu-batch.sub
#BSUB -o bsub-log/out/gpu-batch.sub-%J-stats.out
#BSUB -q normal
#BSUB -n 1
#BSUB -gpu "num=1:j_exclusive=no:mode=shared"
cd ${LS_SUBCWD}
mkdir -p bsub-log/out
mkdir -p bsub-log/err
{
command1 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-0.0.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-0.0.0.err ;
} & {
command2 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-0.1.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-0.1.0.err ;
} & wait

>>>>>>>>>>
#SUBMIT: 1
vvvvvvvvvv
#!/bin/sh
#BSUB -J gpu-batch.sub
#BSUB -o bsub-log/out/gpu-batch.sub-%J-stats.out
#BSUB -q normal
#BSUB -n 1
#BSUB -gpu "num=1:j_exclusive=no:mode=shared"
cd ${LS_SUBCWD}
mkdir -p bsub-log/out
mkdir -p bsub-log/err
{
command3 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-1.0.0-named.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-1.0.0-named.err ;
} & wait

Running commands from file

> cat commands
command1
command2
<sequential> # indicates sequential jobs start
command3
command4
</sequential> # indicates sequential jobs end
> gpu-batch.sub --debug -b 2 -f commands
>>>>>>>>>>
#SUBMIT: 0
vvvvvvvvvv
#!/bin/sh
#BSUB -J gpu-batch.sub
#BSUB -o bsub-log/out/gpu-batch.sub-%J-stats.out
#BSUB -q normal
#BSUB -n 1
#BSUB -gpu "num=1:j_exclusive=no:mode=shared"
cd ${LS_SUBCWD}
mkdir -p bsub-log/out
mkdir -p bsub-log/err
{
command1 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-0.0.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-0.0.0.err ;
} & {
command2 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-0.1.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-0.1.0.err ;
} & wait

>>>>>>>>>>
#SUBMIT: 1
vvvvvvvvvv
#!/bin/sh
#BSUB -J gpu-batch.sub
#BSUB -o bsub-log/out/gpu-batch.sub-%J-stats.out
#BSUB -q normal
#BSUB -n 1
#BSUB -gpu "num=1:j_exclusive=no:mode=shared"
cd ${LS_SUBCWD}
mkdir -p bsub-log/out
mkdir -p bsub-log/err
{
command3 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-1.0.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-1.0.0.err ;
command4 >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-1.0.1.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-1.0.1.err ;
} & wait

Running single command, no quotes

> gpu-batch.sub --debug -C python main.py
>>>>>>>>>>
#SUBMIT: 0
vvvvvvvvvv
#!/bin/sh
#BSUB -J gpu-batch.sub
#BSUB -o bsub-log/out/gpu-batch.sub-%J-stats.out
#BSUB -q normal
#BSUB -n 1
#BSUB -gpu "num=1:j_exclusive=no:mode=shared"
cd ${LS_SUBCWD}
mkdir -p bsub-log/out
mkdir -p bsub-log/err
{
python main.py >\
  bsub-log/out/gpu-batch.sub-${LSB_JOBID}-0.0.0.out 2> bsub-log/err/gpu-batch.sub-${LSB_JOBID}-0.0.0.err ;
} & wait

Program Description

usage: gpu-batch.sub [-h] [--batch BATCH] [--sequential] [--gpu GPU]
                     [--out OUT] [--err ERR] [--name NAME] [--hosts HOSTS]
                     [--files FILES [FILES ...]] [-C [C [C ...]]]
                     [--queue QUEUE] [--exclusive] [--debug]
                     [--bsub-bin BSUB_BIN] [--version]
                     [jobs [jobs ...]]

gpu-batch.sub is a util to wrap submissions to LSF in a batch. It
automatically collects jobs, prepares submission file you can check beforehand
with `--debug` flag. `gpu-batch.sub` asks LSF for desired number of GPU per
batch and allocates them in shared or exclusive (not recommended) mode.

positional arguments:
  jobs                  Jobs to execute (e.g. 'python script.py') enclosed as
                        strings, you can specify either files or explicit jobs
                        in command line. Multiline jobs in files are
                        supported. Optional naming schema for jobs has the
                        following syntax 'name:command' (default: [])

optional arguments:
  -h, --help            show this help message and exit
  --batch BATCH, -b BATCH
                        Number of jobs in batch where -1 stands for unlimited
                        batch (default: -1)
  --sequential, -s      Make all jobs sequential within bsub submit (default:
                        False)
  --gpu GPU, -g GPU     Number of gpu per batch (default: 1)
  --out OUT, -o OUT     Output path for stdout (default: bsub-log/out)
  --err ERR, -e ERR     Output path for stderr (default: bsub-log/err)
  --name NAME, -n NAME  Name for job, defaults to base directory of execution
                        (default: $(basename `pwd`))
  --hosts HOSTS         Space or comma separated allowed hosts. Empty string
                        holds for ALL visible hosts. It is suggested to
                        specify hosts in `.conf` file. Passing hosts in
                        command line looks like `--hosts ''` for ALL or
                        `--hosts 'host1,host2'` for 2 hosts (default: )
  --files FILES [FILES ...], -f FILES [FILES ...]
                        Read jobs from files. File can contain multiline jobs
                        for readability (default: [])
  -C [C [C ...]]        Single command, does not require quotes (default: [])
  --queue QUEUE, -q QUEUE
                        Queue name (default: normal)
  --exclusive, -x       Exclusive mode allocates GPU only for 1 separate job.
                        (default: no)
  --debug               Print submissions and exit (default: False)
  --bsub-bin BSUB_BIN   bsub binary path (default: bsub)
  --version             Print version and exit (default: False)

Default settings are stored in `$HOME/.gpubatch.conf`. They will override the
help message as well. Possible settings for config file: batch, gpu, hosts,
header, queue. Header will be appended to LSF submission file as is, there is
no default extra header.

Metadata

Release files for gpu-batch-sub 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpu-batch-sub 0.1.2
File Size Uploaded Provenance Actions
gpu-batch-sub-0.1.2.tar.gz 7.3 kB Without provenance Details for gpu-batch-sub-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpu-batch-sub 0.1.2
File Interpreter ABI Platform Actions
gpu_batch_sub-0.1.2-py3-none-any.whl Python 3 none any Details for gpu_batch_sub-0.1.2-py3-none-any.whl

Total release size: 19.0 kB

Release files / gpu-batch-sub-0.1.2.tar.gz

Download URL gpu-batch-sub-0.1.2.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f75d50ed113412ec22f94ab61b948b8702bb58d81551fddb5bdac8af771a182
BLAKE2b-256 checksum
How to use checksums
958537fab88d7e6a335f8dea2c8f3adae04b78c2f6de058edf03e9f366fb2a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.19.5 CPython/3.6.3

Release files / gpu_batch_sub-0.1.2-py3-none-any.whl

Download URL gpu_batch_sub-0.1.2-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb918296e34f361477036964968fb34733fb87001e02ff907c00f909034fd1e3
BLAKE2b-256 checksum
How to use checksums
89974b1d1908d8bcfff49afc5ec8e5861401025f99e1be62c42fdbcc0c0e442e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.19.5 CPython/3.6.3

Security for gpu-batch-sub 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page