Skip to content

Commit

Permalink
[torch] Set nproc_per_node to 1 (#61552) (#64791)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #61552

Set `nproc_per_node` to 1

Test Plan: unittests

Reviewed By: cbalioglu

Differential Revision: D29667056

fbshipit-source-id: 6601f66fec5e018c7737d909f8c71642451abb29

Co-authored-by: Aliaksandr Ivanou <[email protected]>
  • Loading branch information
malfet and aivanou authored Sep 10, 2021
1 parent 7a9f23c commit 9cc96ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions test/distributed/launcher/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,35 @@ def test_launch_user_script_bash(self):
{str(i) for i in range(world_size)}, set(os.listdir(self.test_dir))
)

@unittest.skipIf(TEST_WITH_ASAN or TEST_WITH_TSAN, "test incompatible with tsan")
def test_launch_user_script_default_nproc(self):
run_id = str(uuid.uuid4().int)
nnodes = 1
world_size = 1
args = [
f"--nnodes={nnodes}",
"--rdzv_backend=etcd",
f"--rdzv_endpoint={self._etcd_endpoint}",
f"--rdzv_id={run_id}",
"--monitor_interval=1",
"--start_method=fork",
"--no_python",
]

script_args = [path("bin/test_script.sh"), f"{self.test_dir}"]

with self.assertRaises(ValueError):
# --no_python cannot be used with --module
launch.main(args + ["--module"] + script_args)

launch.main(args + script_args)

# make sure all the workers ran
# each worker touches a file with its global rank as the name
self.assertSetEqual(
{str(i) for i in range(world_size)}, set(os.listdir(self.test_dir))
)

@unittest.skipIf(TEST_WITH_ASAN or TEST_WITH_TSAN, "test incompatible with tsan")
def test_launch_with_env_vars(self):
run_id = str(uuid.uuid4().int)
Expand Down
3 changes: 2 additions & 1 deletion torch/distributed/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def train():
import torch
from torch.distributed.argparse_util import check_env, env
from torch.distributed.elastic.multiprocessing import Std
from torch.distributed.elastic.multiprocessing.errors import record
from torch.distributed.elastic.rendezvous.utils import _parse_rendezvous_config
from torch.distributed.elastic.utils import macros
from torch.distributed.elastic.utils.logging import get_logger
Expand Down Expand Up @@ -269,7 +270,7 @@ def get_args_parser() -> ArgumentParser:
"--nproc_per_node",
action=env,
type=str,
default="auto",
default="1",
help="Number of workers per node; supported values: [auto, cpu, gpu, int].",
)

Expand Down

0 comments on commit 9cc96ad

Please sign in to comment.