2022-04-19 07:14:54 +00:00
|
|
|
import click
|
|
|
|
from .run import launch_multi_processes
|
|
|
|
from colossalai.context import Config
|
|
|
|
|
|
|
|
|
|
|
|
@click.command(help="Launch distributed training on a single node or multiple nodes",
|
|
|
|
context_settings=dict(ignore_unknown_options=True))
|
2022-04-24 05:26:26 +00:00
|
|
|
@click.option("-H",
|
|
|
|
"-host",
|
|
|
|
"--host",
|
2022-04-19 07:14:54 +00:00
|
|
|
type=str,
|
|
|
|
default=None,
|
2022-04-24 05:26:26 +00:00
|
|
|
help="the list of hostnames to launch in the format <host1>,<host2>")
|
2022-04-19 07:14:54 +00:00
|
|
|
@click.option(
|
2022-04-24 05:26:26 +00:00
|
|
|
"--hostfile",
|
2022-04-19 07:14:54 +00:00
|
|
|
type=str,
|
|
|
|
default=None,
|
2022-04-24 05:26:26 +00:00
|
|
|
help="Hostfile path that defines the device pool available to the job, each line in the file is a hostname")
|
|
|
|
@click.option("--include",
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help="Specify computing devices to use during execution. String format is <host1>,<host2>,"
|
|
|
|
" only effective when used with --hostfile.")
|
2022-04-19 07:14:54 +00:00
|
|
|
@click.option(
|
|
|
|
"--exclude",
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help=
|
2022-04-24 05:26:26 +00:00
|
|
|
"Specify computing devices to NOT use during execution. Mutually exclusive with --include. Formatting is the same as --includ,"
|
|
|
|
" only effective when used with --hostfile.")
|
|
|
|
@click.option("--num_nodes",
|
|
|
|
type=int,
|
|
|
|
default=-1,
|
|
|
|
help="Total number of worker nodes to use, only effective when used with --hostfile.")
|
|
|
|
@click.option("--nproc_per_node", type=int, default=None, help="Number of GPUs to use on each node.")
|
2022-04-19 07:14:54 +00:00
|
|
|
@click.option("--master_port",
|
|
|
|
type=int,
|
|
|
|
default=29500,
|
|
|
|
help="(optional) Port used by PyTorch distributed for communication during distributed training.")
|
|
|
|
@click.option("--master_addr",
|
|
|
|
type=str,
|
|
|
|
default="127.0.0.1",
|
|
|
|
help="(optional) IP address of node 0, will be inferred via 'hostname -I' if not specified.")
|
|
|
|
@click.option(
|
2022-04-24 05:26:26 +00:00
|
|
|
"--extra_launch_args",
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help=
|
|
|
|
"Set additional torch distributed launcher arguments such as --standalone. The format is --extra_launch_args arg1=1,arg2=2. "
|
|
|
|
"This will be converted to --arg1=1 --arg2=2 during execution")
|
|
|
|
@click.option("--ssh-port", type=int, default=None, help="(optional) the port used for ssh connection")
|
2022-04-19 07:14:54 +00:00
|
|
|
@click.argument("user_script", type=str)
|
|
|
|
@click.argument('user_args', nargs=-1)
|
2022-04-20 02:38:21 +00:00
|
|
|
def run(host: str, hostfile: str, num_nodes: int, nproc_per_node: int, include: str, exclude: str, master_addr: str,
|
2022-04-24 05:26:26 +00:00
|
|
|
master_port: int, extra_launch_args: str, ssh_port: int, user_script: str, user_args: str) -> None:
|
2022-04-19 07:14:54 +00:00
|
|
|
"""
|
|
|
|
To launch multiple processes on a single node or multiple nodes via command line.
|
|
|
|
|
|
|
|
Usage::
|
2022-04-24 05:26:26 +00:00
|
|
|
# run with 4 GPUs on the current node use default port 29500
|
|
|
|
colossalai run --nprocs_per_node 4 train.py
|
2022-04-19 07:14:54 +00:00
|
|
|
|
2022-04-24 05:26:26 +00:00
|
|
|
# run with 2 GPUs on the current node at port 29550
|
|
|
|
colossalai run --nprocs_per_node 4 --master_port 29550 train.py
|
2022-04-19 07:14:54 +00:00
|
|
|
|
|
|
|
# run on two nodes
|
2022-04-24 05:26:26 +00:00
|
|
|
colossalai run --host <host1>,<host2> --master_addr host1 --nprocs_per_node 4 train.py
|
2022-04-19 07:14:54 +00:00
|
|
|
|
|
|
|
# run with hostfile
|
2022-04-24 05:26:26 +00:00
|
|
|
colossalai run --hostfile <file_path> --master_addr <host> --nprocs_per_node 4 train.py
|
|
|
|
|
|
|
|
# run with hostfile with only included hosts
|
|
|
|
colossalai run --hostfile <file_path> --master_addr host1 --include host1,host2 --nprocs_per_node 4 train.py
|
|
|
|
|
|
|
|
# run with hostfile excluding the hosts selected
|
|
|
|
colossalai run --hostfile <file_path> --master_addr host1 --exclude host2 --nprocs_per_node 4 train.py
|
2022-04-19 07:14:54 +00:00
|
|
|
"""
|
2022-04-24 05:26:26 +00:00
|
|
|
if not user_script.endswith('.py'):
|
|
|
|
click.echo(f'Error: invalid Python file {user_script}. Did you use a wrong option? Try colossalai run --help')
|
|
|
|
exit()
|
|
|
|
|
2022-04-19 07:14:54 +00:00
|
|
|
args_dict = locals()
|
|
|
|
args = Config(args_dict)
|
|
|
|
args.user_args = list(args.user_args)
|
2022-04-20 02:38:21 +00:00
|
|
|
launch_multi_processes(args)
|