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

Change boolean command line args to inverted flags #541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EyeDeck
Copy link

@EyeDeck EyeDeck commented Aug 1, 2023

Using argparse, if an argument is set up like

parser.add_argument('--half', type=bool, default=True)

argparse will cast whatever argument is passed to it, as a string, to a bool. The only string that will cast to False in Python is an empty one, so trying to turn this arg off in an intuitive way like --half False or --half off or --half 0 or even --half ""are all actually setting the argument to True (bool("False"), bool("off"), bool("0"), bool("\"\"") and so on), which is no different from leaving it out entirely.
In order to turn an arg set up this way off, you have call it exactly like
--half=""

I went through and changed them into flags like --no-half and --no-use_deepspeed , which is admittedly still a little awkward, but at least doesn't just fail silently anymore.

A cleaner way than I did it in this PR is to set the args up like

parser.add_argument("--half", action=argparse.BooleanOptionalAction, default=True)

however this adds a hard dependency on Python 3.9, which I don't want to impose unless something more important already requires it (and I don't know if it does). From a user's perspective it would still work exactly the same way anyway, so to turn off e.g. --half you still would pass --no-half.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant