mirror of
https://github.com/open-mmlab/mim.git
synced 2025-06-03 14:59:11 +08:00
[Feature]: Add -y to train / test / run / gridsearch (may need to install pkg) (#31)
This commit is contained in:
parent
a20a02a97f
commit
15d353731f
@ -60,6 +60,7 @@ from mim.utils import (
|
||||
@click.option('--max-jobs', type=int, help='Max parallel number', default=1)
|
||||
@click.option(
|
||||
'--srun-args', type=str, help='Other srun arguments that might be used')
|
||||
@click.option('-y', '--yes', is_flag=True, help='Don’t ask for confirmation.')
|
||||
@click.option(
|
||||
'--search-args', type=str, help='Arguments for hyper parameters search')
|
||||
@click.argument('other_args', nargs=-1, type=click.UNPROCESSED)
|
||||
@ -74,6 +75,7 @@ def cli(package: str,
|
||||
port: int = 29500,
|
||||
srun_args: Optional[str] = None,
|
||||
search_args: str = '',
|
||||
yes: bool = False,
|
||||
other_args: tuple = ()) -> None:
|
||||
"""Perform Hyper-parameter search.
|
||||
|
||||
@ -129,6 +131,7 @@ def cli(package: str,
|
||||
port=port,
|
||||
srun_args=srun_args,
|
||||
search_args=search_args,
|
||||
yes=yes,
|
||||
other_args=other_args)
|
||||
|
||||
if is_success:
|
||||
@ -149,6 +152,7 @@ def gridsearch(
|
||||
port: int = 29500,
|
||||
srun_args: Optional[str] = None,
|
||||
search_args: str = '',
|
||||
yes: bool = True,
|
||||
other_args: tuple = ()
|
||||
) -> Tuple[bool, Union[str, Exception]]:
|
||||
"""Hyper parameter search with given config.
|
||||
@ -174,6 +178,7 @@ def gridsearch(
|
||||
used, all arguments should be in a string. Defaults to None.
|
||||
search_args (str, optional): Arguments for hyper parameters search, all
|
||||
arguments should be in a string. Defaults to None.
|
||||
yes (bool): Don’t ask for confirmation. Default: True.
|
||||
other_args (tuple, optional): Other arguments, will be passed to the
|
||||
codebase's training script. Defaults to ().
|
||||
"""
|
||||
@ -188,7 +193,7 @@ def gridsearch(
|
||||
if not is_installed(package):
|
||||
msg = (f'The codebase {package} is not installed, '
|
||||
'do you want to install it? ')
|
||||
if click.confirm(msg):
|
||||
if yes or click.confirm(msg):
|
||||
click.echo(f'Installing {package}')
|
||||
cmd = ['mim', 'install', package]
|
||||
ret = subprocess.check_call(cmd)
|
||||
|
@ -24,8 +24,9 @@ from mim.utils import (
|
||||
cls=CustomCommand)
|
||||
@click.argument('package', type=str, callback=param2lowercase)
|
||||
@click.argument('command', type=str)
|
||||
@click.option('-y', '--yes', is_flag=True, help='Don’t ask for confirmation.')
|
||||
@click.argument('other_args', nargs=-1, type=click.UNPROCESSED)
|
||||
def cli(package: str, command: str, other_args: tuple = ()) -> None:
|
||||
def cli(package: str, command: str, yes: bool, other_args: tuple = ()) -> None:
|
||||
"""Run arbitrary command of a codebase.
|
||||
|
||||
Note if the command you call takes config files or checkpoint paths as
|
||||
@ -56,7 +57,7 @@ def cli(package: str, command: str, other_args: tuple = ()) -> None:
|
||||
> mim run mmcls train -h
|
||||
"""
|
||||
is_success, msg = run(
|
||||
package=package, command=command, other_args=other_args)
|
||||
package=package, command=command, yes=yes, other_args=other_args)
|
||||
|
||||
if is_success:
|
||||
echo_success(msg) # type: ignore
|
||||
@ -65,8 +66,11 @@ def cli(package: str, command: str, other_args: tuple = ()) -> None:
|
||||
|
||||
|
||||
def run(
|
||||
package: str, command: str,
|
||||
other_args: tuple = ()) -> Tuple[bool, Union[str, Exception]]:
|
||||
package: str,
|
||||
command: str,
|
||||
yes: bool = True,
|
||||
other_args: tuple = ()
|
||||
) -> Tuple[bool, Union[str, Exception]]:
|
||||
"""Run arbitrary command of a codebase.
|
||||
|
||||
This command assumes the command scripts have been put into the
|
||||
@ -74,6 +78,8 @@ def run(
|
||||
|
||||
Args:
|
||||
package (str): The codebase name.
|
||||
command (str): The command name.
|
||||
yes (bool): Don’t ask for confirmation. Default: True.
|
||||
other_args (tuple, optional): Other arguments, will be passed to the
|
||||
codebase's script. Defaults to ().
|
||||
"""
|
||||
@ -81,7 +87,7 @@ def run(
|
||||
if not is_installed(package):
|
||||
msg = (f'The codebase {package} is not installed, '
|
||||
'do you want to install it? ')
|
||||
if click.confirm(msg):
|
||||
if yes or click.confirm(msg):
|
||||
click.echo(f'Installing {package}')
|
||||
cmd = ['mim', 'install', package]
|
||||
ret = subprocess.check_call(cmd)
|
||||
|
@ -56,6 +56,7 @@ from mim.utils import (
|
||||
help='The partition to use (only applicable to launcher == "slurm")')
|
||||
@click.option(
|
||||
'--srun-args', type=str, help='Other srun arguments that might be used')
|
||||
@click.option('-y', '--yes', is_flag=True, help='Don’t ask for confirmation.')
|
||||
@click.argument('other_args', nargs=-1, type=click.UNPROCESSED)
|
||||
def cli(package: str,
|
||||
config: str,
|
||||
@ -67,6 +68,7 @@ def cli(package: str,
|
||||
launcher: str = 'none',
|
||||
port: int = None,
|
||||
srun_args: Optional[str] = None,
|
||||
yes: bool = False,
|
||||
other_args: tuple = ()) -> None:
|
||||
"""Perform Testing.
|
||||
|
||||
@ -104,6 +106,7 @@ def cli(package: str,
|
||||
launcher=launcher,
|
||||
port=port,
|
||||
srun_args=srun_args,
|
||||
yes=yes,
|
||||
other_args=other_args)
|
||||
|
||||
if is_success:
|
||||
@ -123,6 +126,7 @@ def test(
|
||||
launcher: str = 'none',
|
||||
port: int = None,
|
||||
srun_args: Optional[str] = None,
|
||||
yes: bool = True,
|
||||
other_args: tuple = ()
|
||||
) -> Tuple[bool, Union[str, Exception]]:
|
||||
"""Test a model with given config.
|
||||
@ -148,6 +152,7 @@ def test(
|
||||
between 20000 and 30000.
|
||||
srun_args (str, optional): Other srun arguments that might be
|
||||
used, all arguments should be in a string. Defaults to None.
|
||||
yes (bool): Don’t ask for confirmation. Default: True.
|
||||
other_args (tuple, optional): Other arguments, will be passed to the
|
||||
codebase's training script. Defaults to ().
|
||||
"""
|
||||
@ -178,7 +183,7 @@ def test(
|
||||
if not is_installed(package):
|
||||
msg = (f'The codebase {package} is not installed, '
|
||||
'do you want to install it? ')
|
||||
if click.confirm(msg):
|
||||
if yes or click.confirm(msg):
|
||||
click.echo(f'Installing {package}')
|
||||
cmd = ['mim', 'install', package]
|
||||
ret = subprocess.check_call(cmd)
|
||||
|
@ -52,6 +52,7 @@ from mim.utils import (
|
||||
help='The partition to use (only applicable to launcher == "slurm")')
|
||||
@click.option(
|
||||
'--srun-args', type=str, help='Other srun arguments that might be used')
|
||||
@click.option('-y', '--yes', is_flag=True, help='Don’t ask for confirmation.')
|
||||
@click.argument('other_args', nargs=-1, type=click.UNPROCESSED)
|
||||
def cli(package: str,
|
||||
config: str,
|
||||
@ -62,6 +63,7 @@ def cli(package: str,
|
||||
launcher: str = 'none',
|
||||
port: int = None,
|
||||
srun_args: Optional[str] = None,
|
||||
yes: bool = False,
|
||||
other_args: tuple = ()) -> None:
|
||||
"""Perform Training.
|
||||
|
||||
@ -95,6 +97,7 @@ def cli(package: str,
|
||||
launcher=launcher,
|
||||
port=port,
|
||||
srun_args=srun_args,
|
||||
yes=yes,
|
||||
other_args=other_args)
|
||||
|
||||
if is_success:
|
||||
@ -113,6 +116,7 @@ def train(
|
||||
launcher: str = 'none',
|
||||
port: int = None,
|
||||
srun_args: Optional[str] = None,
|
||||
yes: bool = True,
|
||||
other_args: tuple = ()
|
||||
) -> Tuple[bool, Union[str, Exception]]:
|
||||
"""Train a model with given config.
|
||||
@ -136,6 +140,7 @@ def train(
|
||||
between 20000 and 30000.
|
||||
srun_args (str, optional): Other srun arguments that might be
|
||||
used, all arguments should be in a string. Defaults to None.
|
||||
yes (bool): Don’t ask for confirmation. Default: True.
|
||||
other_args (tuple, optional): Other arguments, will be passed to the
|
||||
codebase's training script. Defaults to ().
|
||||
"""
|
||||
@ -155,7 +160,7 @@ def train(
|
||||
if not is_installed(package):
|
||||
msg = (f'The codebase {package} is not installed, '
|
||||
'do you want to install the latest release? ')
|
||||
if click.confirm(msg):
|
||||
if yes or click.confirm(msg):
|
||||
click.echo(f'Installing {package}')
|
||||
cmd = ['mim', 'install', package]
|
||||
ret = subprocess.check_call(cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user