-
Notifications
You must be signed in to change notification settings - Fork 1
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
Issue with use of configargparse and -h #5
Comments
Ah yeah, I was worried about that parse there, but didn't see yet how it would go wrong :) It turns out there are now module-level "properties" (not really properties, but still pretty awesome, I didn't know before just now!), so I would go with that, see here: https://www.python.org/dev/peps/pep-0562/ So for config.py, replace the def __getattr__(name):
"""Only trigger parsing when it's needed."""
if name == 'args':
args, unknown_args = parser.parse_known_args()
return args
raise AttributeError(f"module '{__name__}' has no attribute '{name}'") |
I tried that but |
Ah yeah, that would happen when another module (that you import from your script probably) uses |
It is in dataset.py. We might be able to avoid the issue here but I feel like we might run into this issue agian with the current setup. I was wondering wether an alternative could be to use two different parsers: one for general level config, such as dataset path, which wouldn't have help associated with it (we could document those parameters somewhere else) and another one for the script specific parameters that would appear in the help message. |
Hm, then it wouldn't give any help message if you run a script that doesn't add the second parser. Another option would be to just put all parameters in one file, even though we only use them in specific runs. We can indicate these experiment-specific parameters in the help section using groups: https://docs.python.org/3/library/argparse.html#argument-groups So for instance, parser = configargparse.get_argument_parser(name='platalea')
# [... current options there ...]
experiment_arguments = parser.add_argument_group('experiment arguments', "Some experiment run scripts use the following optional parameters.")
experiment_arguments.add_argument('--epochs', action='store', default=32, dest='epochs', type=int,
help='number of epochs after which to stop training (default: 32)')
# [... etc ...] The help message is then:
A downside of this approach is that we may at some point end up with a huge bunch of experiment arguments, but we can always reevaluate once this happens. Also, we may need slightly different variants/interpretations for different experiments. However, if we document this properly, it shouldn't be a big issue. What do you think? |
Btw, this approach also means we can get rid of the perhaps slightly overly complicated |
I am not really fond of adding all parameters in one file for 2 main reasons:
I would rather go for one of the following option:
|
After discussion, I think we came up with the following idea, please correct me if I misunderstood: We create a new class that internally uses the ConfigArgParse parser, but by default does not parse, it only parses when the user asks it to. Moreover, it exposes the default parameters so that we can still use those when parsing has not taken place. When parsing is activated, the class updates the parameters from their default values to the values from the parser. The parser has a set of default options included (those that are used inside the main platalea module, like The interface and use will be something like this: class PlataleaConfig:
def __init__(self):
# setup ConfigArgParse parser and default parameters in self.stuff dicts
def add_argument(self, *args, **kwargs):
self._parser.add_argument(*args, **kwargs)
def parse(self):
args, _ = self.parser.parse_known_args()
# update default parameters dict(s) using args results
def __getattr__(self, arg_name):
return self._stuff[arg_name] |
Yes, that's it. |
When
platalea.config
is imported in a script, it catches the-h
(help) parameter before the script's specific parameters are added. As an example,python utils/evaluate_asr.py -h
doesn't show the script's parameters (path
,-b
), only the global ones (e.g.data_root
,meta
). Importing config after the script has parsed the parameters would result in the opposite behavior.@egpbos, any idea how this could be handled better?
The text was updated successfully, but these errors were encountered: