如何将 SLURM-jobID 作为输入参数传递给 python?

fem*_*onk 3 slurm deep-learning python-3.6

我是使用 SLURM 训练一批卷积神经网络的新手。为了轻松跟踪所有经过训练的 CNN,我想将 SLURM jobID 作为输入参数传递给 python。将其他变量作为参数传递可以正常工作。但是,我无法访问 SLURM jobid 来通过。

我已经尝试使用${SLURM_JOBID}${SLURM_JOB_ID}%j%J我还尝试在传递给 python 之前将这些 slurm 环境变量写入变量中。

这是我最新的代码:

#!/bin/bash

# --- info to user
echo "script started ... "

# --- setup environment
module purge            # clean up
module load python/3.6
module load nvidia/10.0
module load cudnn/10.0-v7 

# --- display information
HOST=`hostname`
echo "This script runs the CNN. Slurm scheduled it on node $HOST"
echo "I am interested of all environment variables Slurm adds:"
env | grep -i slurm

# --- start running ... 
echo " --- run --- "

# --- define some varibles
dc="dice"
sm="softmax"

# --- run a job using a slurm batch script
for layer in {3..15..2}
  do
    sbatch -N 1 -n 1 --mem=20G --mail-type=END --gres=gpu:V100:3 --wrap="singularity --noslurm tensorflow_19.03-py3.simg python run_CNN_dynlayer.py ${SLURM_JOBID} ${layer} ${dc}"
    sleep 1 # pause 1s to be kind to the scheduler...
    echo "jobid: "+${SLURM_JOBID}
    echo " --- next --- "
  done    
Run Code Online (Sandbox Code Playgroud)

cmd 看起来像这样:

femonk@rarp1 [CNN] ./run_CNN_test.slurm
script started ... 
This script runs the CNN. Slurm scheduled it on node rarp1
I am interested of all environment variables Slurm adds:
SLURM_ACCOUNT=AI
PYTHONPATH=/cluster/slurm/lib64/python3.6/site-packages:/cluster/slurm/lib64/python3.6/site-packages:/cluster/slurm/lib64/python3.6/site-packages:
 --- run --- 
Submitted batch job 3182711
jobid: 
 --- next --- 
femonk@rarp1 [CNN] 
Run Code Online (Sandbox Code Playgroud)

有谁知道我的代码有什么问题吗?预先非常感谢。

dam*_*ois 6

SLURM_JOBID环境变量仅适用于作业进程,不适用于提交作业的进程。作业 ID 是从sbatch命令返回的,因此如果您希望将其放在变量中,则需要对其进行分配。

  do
    SLURM_JOBID=$(sbatch --parsable -N 1 -n 1 --mem=20G --mail-type=END --gres=gpu:V100:3 --wrap="singularity --noslurm tensorflow_19.03-py3.simg python run_CNN_dynlayer.py ${SLURM_JOBID} ${layer} ${dc}")
    sleep 1 # pause 1s to be kind to the scheduler...
    echo "jobid: "+${SLURM_JOBID}
    echo " --- next --- "
  done   
Run Code Online (Sandbox Code Playgroud)

$()请注意命令替换与--parsable的参数的结合使用sbatch

另请注意,当前输出的行将Submitted batch job 3182711消失,因为它用于填充SLURM_JOBID变量。