in heyhi/run.py [0:0]
def parse_args_and_maybe_launch(main: Callable) -> None:
"""Main entrypoint to HeyHi.
It does eveything HeyHi is for:
* Finds a config.
* Applies local and global includes and overridefs to the config.
* Determindes a folder to put the experiment.
* Detects the status of the experiment (if already running).
* Depending on the status and mode, maybe start/restarts experiment
locally or remotely.
Args:
task: dictionary of callables one of which will be called based on
cfg.task.
"""
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-c", "--cfg", required=True, type=pathlib.Path)
parser.add_argument("--adhoc", action="store_true")
parser.add_argument(
"--force", action="store_true", help="Do not ask confirmation in restart mode"
)
parser.add_argument(
"--mode", choices=util.MODES, help="See heyhi/util.py for mode definitions."
)
checkpoint_repo.add_parser_arg(parser)
parser.add_argument(
"--exp_id_pattern_override",
default=util.EXP_ID_PATTERN,
help="A pattern to construct exp_id. Job's data is stored in <exp_root>/<exp_id>",
)
parser.add_argument("--out", help="Alias for exp_id_pattern_override. Overrides it if set.")
parser.add_argument(
"--print", help="If set, will print composed config and exit", action="store_true"
)
parser.add_argument(
"--print-flat",
help="If set, will print composed config as a list of redefines and exit. This command lists only explicitly defined flags",
action="store_true",
)
parser.add_argument(
"--print-flat-all",
help="If set, will print composed config as a list of redefines and exit. This command lists all possible flags",
action="store_true",
)
parser.add_argument("--log-level", default="INFO", choices=["ERROR", "WARN", "INFO", "DEBUG"])
args, overrides = parser.parse_known_args()
if args.out:
args.exp_id_pattern_override = args.out
del args.out
if args.mode is None:
args.mode = "restart" if args.adhoc else "gentle_start"
overrides = [x.lstrip("-") for x in overrides]
if args.print or args.print_flat or args.print_flat_all:
task, meta_cfg = conf.load_root_proto_message(args.cfg, overrides)
cfg = getattr(meta_cfg, task)
if args.print:
print(cfg)
if args.print_flat or args.print_flat_all:
for k, v in conf.flatten_cfg(cfg, with_all=args.print_flat_all).items():
if v is None:
v = "NULL"
elif isinstance(v, str) and (" " in v or not v):
v = repr(v)
print("%s=%s" % (k, v))
return
kwargs = {}
for k, v in vars(args).items():
if k.startswith("print"):
# If print was not handled.
assert not v, "Bug!"
continue
kwargs[k] = v
maybe_launch(main, exp_root=get_exp_dir(PROJECT_NAME), overrides=overrides, **kwargs)