Skip to content

Commit

Permalink
✨ Use store_true for bool args (#1822)
Browse files Browse the repository at this point in the history
* ✨ Use store_true for bool args

* debug

Co-authored-by: Nate Raw <nxr9266@g.rit.edu>
  • Loading branch information
williamFalcon and nateraw committed May 13, 2020
1 parent e961f7e commit 648d516
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit 648d516

Please sign in to comment.