Debian Codegraph @

examples/slurm/submit_multicpu.sh

raw
1 #!/bin/bash -l
2
3 #SBATCH --job-name=multicpu
4 #SBATCH --nodes=2 # number of Nodes
5 #SBATCH --ntasks-per-node=1 # number of MP tasks
6 #SBATCH --exclusive
7 #SBATCH --output=O-%x.%j
8 #SBATCH --error=E-%x.%j
9
10 ######################
11 ### Set environment ###
12 ######################
13 source activateEnvironment.sh
14
15 ######################
16 #### Set network #####
17 ######################
18 head_node_ip=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n 1)
19 ######################
20
21 # Setup env variables for distributed jobs
22 export MASTER_PORT="${MASTER_PORT:-29555 }"
23 echo "head_node_ip=${head_node_ip}"
24 echo "MASTER_PORT=${MASTER_PORT}"
25
26 INSTANCES_PER_NODE="${INSTANCES_PER_NODE:-1}"
27
28 if [[ $SLURM_NNODES == 1 ]] && [[ $INSTANCES_PER_NODE == 1 ]]; then
29 export CCL_WORKER_COUNT=0
30 LAUNCHER=""
31 else
32 # Setup env variables for distributed jobs
33 export CCL_WORKER_COUNT="${CCL_WORKER_COUNT:-2}"
34 echo "CCL_WORKER_COUNT=${CCL_WORKER_COUNT}"
35
36 # Write hostfile
37 HOSTFILE_PATH=hostfile
38 scontrol show hostname $SLURM_JOB_NODELIST | perl -ne 'chomb; print "$_"x1'> ${HOSTFILE_PATH}
39
40 export LAUNCHER="accelerate launch \
41 --num_processes $((SLURM_NNODES * ${INSTANCES_PER_NODE})) \
42 --num_machines $SLURM_NNODES \
43 --rdzv_backend c10d \
44 --main_process_ip $head_node_ip \
45 --main_process_port $MASTER_PORT \
46 --mpirun_hostfile $HOSTFILE_PATH
47 fi
48
49 # This step is necessary because accelerate launch does not handle multiline arguments properly
50 export ACCELERATE_DIR="${ACCELERATE_DIR:-/accelerate}"
51 export SCRIPT="${ACCELERATE_DIR}/examples/complete_nlp_example.py"
52 export SCRIPT_ARGS=" \
53 --cpu \
54 --output_dir ${ACCELERATE_DIR}/examples/output \
55 "
56
57 # This step is necessary because accelerate launch does not handle multiline arguments properly
58 export CMD="$LAUNCHER $SCRIPT $SCRIPT_ARGS"
59 # Print the command
60 echo $CMD
61 echo ""
62
63 # Run the command
64 eval $CMD