Allow for optional boolean flags in sweeps
See original GitHub issueProblem or Use Case I’m using a yaml-based sweep config to run a script that uses ArgumentParser. Since ArgumentParser doesn’t accept bool values, one of the workarounds is to do the following:
parser.add_argument('--foo', dest='foo', action='store_true')
parser.set_defaults(foo=False)
In this scenario the foo will be False, unless --foo is provided. One could also add a --no-foo flag to make both options explicit.
I don’t see a way for wandb to sweep optional flags like this. My workaround is to make the arg a string like parser.add_argument('--foo', type=str, default='false'), give the sweep [true, false] categorical options, and later convert the value like so: args.foo = args.foo in {'True', 'true'}. But this is hacky; I don’t want to change my arg structure for external tools like wandb, and it’s easy to forget the conversion when adding new args.
Suggested Solution A way to configure optional flag configurations for sweeps, where the flag is either present or not
Issue Analytics
- State:
- Created 3 years ago
- Reactions:27
- Comments:38 (2 by maintainers)

Top Related StackOverflow Question
We can add boolean flags under
commandhttps://docs.wandb.ai/guides/sweeps/configuration#commandHi Evan, thanks for the good suggestion. We will be returning to Sweeps to start a new batch of improvements next quarter, and I’ll include your feedback in that process.