Skip to content

Instantly share code, notes, and snippets.

@devforfu
Created November 8, 2020 19:40
Show Gist options
  • Save devforfu/4de0b2a6688620f3e8a360d91d392b85 to your computer and use it in GitHub Desktop.
Save devforfu/4de0b2a6688620f3e8a360d91d392b85 to your computer and use it in GitHub Desktop.
CLI
def basic_parser(script_filename: str = None) -> ArgumentParser:
experiment_name = (
Path(script_filename).stem
if script_filename is not None
else None
)
datasets = available_datasets()
p = ArgumentParser()
p.add_argument('--dataset_path', required=True)
p.add_argument('--dataset', choices=datasets, default=datasets[0])
return p
def add_scheduler_args(parser: ArgumentParser) -> ArgumentParser:
p = ArgumentParser(parents=[parser], add_help=False)
p.add_argument('--scheduler_name', default='exponential')
p.add_argument('--scheduler_interval', default='epoch', choices=['epoch', 'step'])
p.add_argument('--scheduler_disabled', action='store_true')
p.add_argument('--exponential_gamma', type=float, default=0.8)
return p
def add_optimizer_args(parser: ArgumentParser) -> ArgumentParser:
p = ArgumentParser(parents=[parser], add_help=False)
p.add_argument('--optimizer_name', default='adam', choices=['adam'])
p.add_argument('--adam_beta_1', type=float, default=0.9)
p.add_argument('--adam_beta_2', type=float, default=0.999)
return p
def create_default_parser(script_filename: str) -> ArgumentParser:
parser = reduce(lambda x, f: f(x), [
add_scheduler_args,
add_optimizer_args,
pl.Trainer.add_argparse_args,
], basic_parser(script_filename))
return parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment