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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default config file fails to initialize module. #11622
Comments
I can repro just with jsonargparse class Foo:
def __init__(self, foo: int):
self.foo = foo
from jsonargparse import ArgumentParser, ActionConfigFile
parser = ArgumentParser(default_config_files=["default.yaml"])
parser.add_argument('--config', action=ActionConfigFile)
subcommands = parser.add_subcommands()
subparser = ArgumentParser()
subparser.add_class_arguments(Foo, nested_key="model")
subcommands.add_subcommand("fit", subparser)
subparser = ArgumentParser()
subparser.add_class_arguments(Foo, nested_key="model")
subcommands.add_subcommand("test", subparser)
args = parser.parse_args()
print(args) Passing the config manually works as expected $ python -m main --config=default.yaml fit
Namespace(config=[Path_fr(default.yaml, cwd=/Users/carlosmocholi/git/pytorch-lightning)], subcommand='fit', fit=Namespace(model=Namespace(foo=123)), __default_config__=Path_fr(default.yaml, cwd=/Users/carlosmocholi/git/pytorch-lightning)) But not this: $ python -m main fit
usage: main.py [-h] [--config CONFIG] [--print_config [={comments,skip_null}+]] {fit,test} ...
main.py: error: Configuration check failed :: Key "fit.model.foo" is required but not included in config object or its value is None. Can you verify that it is a bug upstream @mauvilsa? |
Yes, looks like a bug in jsonargparse. |
It seems that forgot to implement the use @ramonemiliani93 for the time being, as a workaround define the default files for each subcommand. For example as @carmocca you can assign this issue to me. |
The missing feature has been implemented in jsonargparse commit omni-us/jsonargparse@0d07c9a. This is included in version 4.3.0, which has just been released. Probably we shouldn't close this issue until a unit test is added to lightning to prevent regressions. |
It seems like the problem continues to occur, or at least a similar one. https://lightning.ai/forums/t/problem-lightningcli-with-default-config-files/5963 |
馃悰 Bug
Hi! Not sure if it is a misunderstanding on my side, when the
default_config_files
is used on the LightningCLI with a file containing the parameters for a LightningModule constructor it fails.To Reproduce
main.py
default.yaml
To reproduce just put both on a folder and run
python -m main fit
inside.Expected behavior
The fit routine should run with
foo=123
.Environment
- GPU:
- available: False
- version: None
- numpy: 1.22.1
- pyTorch_debug: False
- pyTorch_version: 1.10.1
- pytorch-lightning: 1.5.9
- tqdm: 4.62.3
- OS: Darwin
- architecture:
- 64bit
-
- processor: i386
- python: 3.8.12
- version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64
cc @carmocca @mauvilsa
The text was updated successfully, but these errors were encountered: