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