Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slurm multinode example #3229

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions examples/complete_nlp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@ def collate_fn(examples):
references=references,
)

eval_metric = metric.compute()
# Use accelerator.print to print only on the main process.
accelerator.print(f"epoch {epoch}:", eval_metric)
if accelerator.is_main_process:
# Computing metrics in a distributed manner requires calling evaluate.load() with the
# n_process and process_id arguments. However, the metric.add_batch() step will fail
# due to a bug with datasets and evaluate (see https://github.com/huggingface/evaluate/issues/542)
# and related
eval_metric = metric.compute()
# Use accelerator.print to print only on the main process.
accelerator.print(f"epoch {epoch}:", eval_metric)
Comment on lines -249 to +256
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaking is a first for me, let me try to repr this

if args.with_tracking:
accelerator.log(
{
Expand Down
15 changes: 10 additions & 5 deletions examples/slurm/submit_multinode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@
#SBATCH --nodes=4 # number of nodes
#SBATCH --ntasks-per-node=1 # number of MP tasks
#SBATCH --gres=gpu:4 # number of GPUs per node
#SBATCH --cpus-per-task=160 # number of cores per tasks
#SBATCH --cpus-per-task=80 # number of cores per tasks
#SBATCH --time=01:59:00 # maximum execution time (HH:MM:SS)

######################
### Set enviroment ###
######################
source activateEnvironment.sh
export SRUN_CPUS_PER_TASK=${SLURM_CPUS_PER_TASK}
export GPUS_PER_NODE=4
######################

######################
#### Set network #####
######################
head_node_ip=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n 1)
NODE_RANK=$SLURM_PROCID
######################

export LAUNCHER="accelerate launch \
--num_processes $((SLURM_NNODES * GPUS_PER_NODE)) \
--num_machines $SLURM_NNODES \
--num_processes $((SLURM_JOB_NUM_NODES * GPUS_PER_NODE)) \
--num_machines $SLURM_JOB_NUM_NODES \
--rdzv_backend c10d \
--main_process_ip $head_node_ip \
--main_process_port 29500 \
--role $SLURMD_NODENAME: \
--machine_rank $NODE_RANK \
--multi_gpu \
"
export ACCELERATE_DIR="${ACCELERATE_DIR:-/accelerate}"
export SCRIPT="${ACCELERATE_DIR}/examples/complete_nlp_example.py"
Expand All @@ -38,5 +43,5 @@ export SCRIPT_ARGS=" \
"

# This step is necessary because accelerate launch does not handle multiline arguments properly
export CMD="$LAUNCHER $PYTHON_FILE $ARGS"
srun $CMD
export CMD="$LAUNCHER $SCRIPT $SCRIPT_ARGS"
srun $CMD
Loading