64
64
"This will be converted to --arg1=1 --arg2=2 during execution" ,
65
65
)
66
66
@click .option ("--ssh-port" , type = int , default = None , help = "(optional) the port used for ssh connection" )
67
- @click .argument ("user_script" , type = str )
67
+ @click .option ("-m" , type = str , default = None , help = "run library module as a script (terminates option list)" )
68
+ @click .argument ("user_script" , type = str , required = False , default = None )
68
69
@click .argument ("user_args" , nargs = - 1 )
69
70
def run (
70
71
host : str ,
@@ -77,8 +78,9 @@ def run(
77
78
master_port : int ,
78
79
extra_launch_args : str ,
79
80
ssh_port : int ,
81
+ m : str ,
80
82
user_script : str ,
81
- user_args : str ,
83
+ user_args : tuple ,
82
84
) -> None :
83
85
"""
84
86
To launch multiple processes on a single node or multiple nodes via command line.
@@ -102,9 +104,24 @@ def run(
102
104
# run with hostfile excluding the hosts selected
103
105
colossalai run --hostfile <file_path> --master_addr host1 --exclude host2 --nprocs_per_node 4 train.py
104
106
"""
105
- if not user_script .endswith (".py" ):
106
- click .echo (f"Error: invalid Python file { user_script } . Did you use a wrong option? Try colossalai run --help" )
107
- exit ()
107
+ if m is not None :
108
+ if m .endswith (".py" ):
109
+ click .echo (f"Error: invalid Python module { m } . Did you use a wrong option? Try colossalai run --help" )
110
+ exit ()
111
+ if user_script is not None :
112
+ user_args = (user_script ,) + user_args
113
+ user_script = m
114
+ m = True
115
+ else :
116
+ if user_script is None :
117
+ click .echo ("Error: missing script argument. Did you use a wrong option? Try colossalai run --help" )
118
+ exit ()
119
+ if not user_script .endswith (".py" ):
120
+ click .echo (
121
+ f"Error: invalid Python file { user_script } . Did you use a wrong option? Try colossalai run --help"
122
+ )
123
+ exit ()
124
+ m = False
108
125
109
126
args_dict = locals ()
110
127
args = Config (args_dict )
0 commit comments