| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
#SBATCH --job-name=multinode |
| 4 |
#SBATCH -D . |
| 5 |
#SBATCH --output=O-%x.%j |
| 6 |
#SBATCH --error=E-%x.%j |
| 7 |
#SBATCH --nodes=4 # number of nodes |
| 8 |
#SBATCH --ntasks-per-node=1 # number of MP tasks |
| 9 |
#SBATCH --gres=gpu:4 # number of GPUs per node |
| 10 |
#SBATCH --cpus-per-task=160 # number of cores per tasks |
| 11 |
#SBATCH --time=01:59:00 # maximum execution time (HH:MM:SS) |
| 12 |
|
| 13 |
###################### |
| 14 |
### Set environment ### |
| 15 |
###################### |
| 16 |
source activateEnvironment.sh |
| 17 |
export GPUS_PER_NODE=4 |
| 18 |
###################### |
| 19 |
|
| 20 |
###################### |
| 21 |
#### Set network ##### |
| 22 |
###################### |
| 23 |
head_node_ip=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n 1) |
| 24 |
###################### |
| 25 |
export ACCELERATE_DIR="${ACCELERATE_DIR:-/accelerate}" |
| 26 |
|
| 27 |
export LAUNCHER="accelerate launch \ |
| 28 |
--config_file ${ACCELERATE_DIR}/examples/slurm/fsdp_config.yaml \ |
| 29 |
--num_processes $((SLURM_NNODES * GPUS_PER_NODE)) \ |
| 30 |
--num_machines $SLURM_NNODES \ |
| 31 |
--rdzv_backend c10d \ |
| 32 |
--main_process_ip $head_node_ip \ |
| 33 |
--main_process_port 29500 \ |
| 34 |
" |
| 35 |
export SCRIPT="${ACCELERATE_DIR}/examples/complete_nlp_example.py" |
| 36 |
export SCRIPT_ARGS=" \ |
| 37 |
--mixed_precision fp16 \ |
| 38 |
--output_dir ${ACCELERATE_DIR}/examples/output \ |
| 39 |
" |
| 40 |
|
| 41 |
# This step is necessary because accelerate launch does not handle multiline arguments properly |
| 42 |
export CMD="$LAUNCHER $SCRIPT $SCRIPT_ARGS" |
| 43 |
srun $CMD |