-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fast launch method based on openmpi (#69)
- Loading branch information
Showing
5 changed files
with
153 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
import os, re, sys | ||
import logging | ||
import argparse | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-m', default=False, action='store_true') | ||
parser.add_argument('rest', nargs=argparse.REMAINDER) | ||
args = parser.parse_args() | ||
|
||
local_rank = int(os.environ['LOCAL_RANK']) | ||
local_size = int(os.environ['LOCAL_SIZE']) | ||
|
||
os.environ['TUTEL_CUDA_SANDBOX'] = '1' | ||
os.environ['CUDA_VISIBLE_DEVICES'] = str(local_rank) | ||
|
||
cmd_args = [] | ||
try: | ||
if not os.path.exists('/usr/bin/numactl'): | ||
raise | ||
local_size = int(os.environ['LOCAL_SIZE']) | ||
cpu_nodes = sorted([str(x[4:]) for x in os.listdir('/sys/devices/system/node') if re.match('node[0-9]+', x)]) | ||
if len(cpu_nodes) <= local_size: | ||
sel_nodes = cpu_nodes[(local_rank // (local_size // len(cpu_nodes))) % len(cpu_nodes)] | ||
else: | ||
sel_nodes = cpu_nodes[local_rank::local_size] | ||
sel_nodes = ','.join(sel_nodes) | ||
|
||
cmd_args = ['/usr/bin/numactl', '--cpunodebind=%s' % sel_nodes] | ||
except Exception as ex: | ||
if local_rank == 0: | ||
logging.warning('`numactl` is not enabled by tutel.launcher.execl') | ||
|
||
cmd_args += [sys.executable, '-m'] if args.m else [] | ||
cmd_args += args.rest | ||
os.execl(cmd_args[0], *cmd_args) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
import os, sys | ||
|
||
def main(): | ||
host_size = int(os.environ['OMPI_COMM_WORLD_SIZE']) | ||
host_rank = int(os.environ['OMPI_COMM_WORLD_RANK']) | ||
local_size = int(os.environ.get('LOCAL_SIZE', 1)) | ||
|
||
master_addr = os.environ['MASTER_ADDR'] if host_size > 1 else 'localhost' | ||
master_port = int(os.environ.get('MASTER_PORT', 23232)) | ||
|
||
cmd_args = [sys.executable, '-m', 'torch.distributed.launch', '--use_env', | ||
'--nproc_per_node=%d' % local_size, | ||
'--nnodes=%d' % host_size, | ||
'--node_rank=%d' % host_rank, | ||
'--master_addr=%s' % master_addr, | ||
'--master_port=%s' % master_port, | ||
'-m', 'tutel.launcher.execl', | ||
] + sys.argv[1:] | ||
os.execl(cmd_args[0], *cmd_args) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters