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

Enable multi-gpu training when "torch" is chosen as the RETURNN backend #445

Merged
merged 17 commits into from
Oct 26, 2023
47 changes: 28 additions & 19 deletions returnn/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,34 @@ def _get_run_cmd(self):
]

if self.horovod_num_processes:
# Normally, if the engine (e.g. SGE or Slurm) is configured correctly,
# it automatically provides the information on multiple nodes to mpirun,
# so it is not needed to explicitly pass on any hostnames here.
run_cmd = [
"mpirun",
"-np",
str(self.horovod_num_processes),
"-bind-to",
"none",
"-map-by",
"slot",
"-mca",
"pml",
"ob1",
"-mca",
"btl",
"^openib",
"--report-bindings",
] + run_cmd
if self.returnn_config.get("backend", None) == "torch":
# use torchrun to lauch DDP training when the backend is torch
nnodes = self.multi_node_slots if self.multi_node_slots else 1
run_cmd = [
"torchrun",
f"--nnodes={nnodes}",
Judyxujj marked this conversation as resolved.
Show resolved Hide resolved
f"--nproc-per-node={self.horovod_num_processes}",
] + run_cmd[1:]
else:
# Normally, if the engine (e.g. SGE or Slurm) is configured correctly,
# it automatically provides the information on multiple nodes to mpirun,
# so it is not needed to explicitly pass on any hostnames here.
run_cmd = [
"mpirun",
"-np",
str(self.horovod_num_processes),
"-bind-to",
"none",
"-map-by",
"slot",
"-mca",
"pml",
"ob1",
"-mca",
"btl",
"^openib",
"--report-bindings",
] + run_cmd

return run_cmd

Expand Down