From 10f112e501f58252394f2d1053b42d0292be281f Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Tue, 28 Apr 2020 13:09:03 +0200 Subject: [PATCH] Added slurm support to launchBatches --- .gitignore | 1 + UD_any/launchBatches.py | 67 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 336944a..338c71d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin/ *\.stderr *\.stdout +*\.slurm __pycache__ config diff --git a/UD_any/launchBatches.py b/UD_any/launchBatches.py index 3195812..2ee79cd 100755 --- a/UD_any/launchBatches.py +++ b/UD_any/launchBatches.py @@ -3,11 +3,11 @@ import sys import os import subprocess +import time ############################################################################### def printUsageAndExit() : - print("USAGE : %s (train | eval) (bash | oar) batchesDescription.py (--time nbHours)"%sys.argv[0], - file=sys.stderr) + print("USAGE : %s (train | eval) (bash | oar | slurm) batchesDescription.py (--time nbHours)"%sys.argv[0], file=sys.stderr) exit(1) ############################################################################### @@ -23,6 +23,8 @@ def launchTrain(mode, expName, arguments, launcher, nbHours) : launchTrainBash(mode, expName, arguments) elif launcher == "oar" : launchTrainOar(mode, expName, arguments, nbHours) + elif launcher == "slurm" : + launchTrainSlurm(mode, expName, arguments, nbHours) else : printUsageAndExit() ############################################################################### @@ -55,12 +57,42 @@ def launchTrainOar(mode, expName, arguments, nbHours) : subprocess.Popen(command, shell=True).wait() ############################################################################### +############################################################################### +def launchTrainSlurm(mode, expName, arguments, nbHours) : + filename = "train.{}.slurm".format(expName) + sFile = open(filename, "w") + + print("""#! /usr/bin/env bash + +#SBATCH --job-name=train:{} +#SBATCH --output={}.stdout +#SBATCH --error={}.stderr +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=10 +#SBATCH --gres=gpu:1 +#SBATCH --hint=nomultithread +#SBATCH --partition=gpu_p1 +#SBATCH --time={}:00:00 + +module purge +module load gcc/9.1.0 +module load python/3.7.5 + +./train.sh {} bin/{} {} --silent +""".format(expName, expName, expName, nbHours, mode, expName, arguments), file=sFile) + sFile.close() + + subprocess.Popen("sbatch {}".format(filename), shell=True).wait() +############################################################################### + ############################################################################### def launchEval(mode, expName, launcher, nbHours) : if launcher == "bash" : launchEvalBash(mode, expName) elif launcher == "oar" : launchEvalOar(mode, expName, nbHours) + elif launcher == "slurm" : + launchEvalSlurm(mode, expName, nbHours) else : printUsageAndExit() ############################################################################### @@ -88,11 +120,38 @@ def launchEvalOar(mode, expName, nbHours) : subprocess.Popen(command, shell=True).wait() ############################################################################### +############################################################################### +def launchEvalSlurm(mode, expName, nbHours) : + filename = "eval.{}.slurm".format(expName) + sFile = open(filename, "w") + + print("""#! /usr/bin/env bash + +#SBATCH --job-name=eval:{} +#SBATCH --output={}.stdout +#SBATCH --error={}.stderr +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=10 +#SBATCH --gres=gpu:1 +#SBATCH --hint=nomultithread +#SBATCH --partition=gpu_p1 +#SBATCH --time={}:00:00 + +module purge +module load gcc/9.1.0 +module load python/3.7.5 + +./evaluate.sh {} bin/{} --silent +""".format(expName, expName, expName, nbHours, mode, expName), file=sFile) + sFile.close() + + subprocess.Popen("sbatch {}".format(filename), shell=True).wait() +############################################################################### + ############################################################################### def getOarNbLongJobs() : return int(subprocess.Popen('oarstat -u | grep "Q=long" | wc -l', shell=True, stdout=subprocess.PIPE).stdout.read()) - ############################################################################### ############################################################################### @@ -181,7 +240,7 @@ if __name__ == "__main__" : else : printUsageAndExit() - if mode not in ["train","eval"] or launcher not in ["bash","oar"] : + if mode not in ["train","eval"] or launcher not in ["bash","oar","slurm"] : printUsageAndExit() desc = __import__(os.path.splitext(batchesDescription)[0]) -- GitLab