Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Use store_true for bool args #1822

Merged
merged 2 commits into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions pytorch_lightning/trainer/trainer.py
Expand Up @@ -667,6 +667,16 @@ def add_argparse_args(cls, parent_parser: ArgumentParser) -> ArgumentParser:
def allowed_type(x):
return bool(parsing.strtobool(x))

# Bool args with default of True parsed as flags not key value pair
if arg_types == (bool,) and arg_default is False:
parser.add_argument(
f'--{arg}',
action='store_true',
dest=arg,
help='autogenerated by pl.Trainer'
)
continue

if arg == 'gpus':
allowed_type = Trainer.allowed_type
arg_default = Trainer.arg_default
Expand Down
2 changes: 1 addition & 1 deletion tests/trainer/test_trainer_cli.py
Expand Up @@ -30,7 +30,7 @@ def test_default_args(tmpdir):

@pytest.mark.parametrize('cli_args', [
['--accumulate_grad_batches=22'],
['--print_nan_grads=1', '--weights_save_path=./'],
['--print_nan_grads', '--weights_save_path=./'],
[]
])
def test_add_argparse_args_redefined(cli_args):
Expand Down