We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Traceback (most recent call last): File "/home/ubuntu/carlos/kk.py", line 18, in <module> args = parser.instantiate_classes(args) File "/home/ubuntu/.pyenv/versions/env/lib/python3.10/site-packages/jsonargparse/_deprecated.py", line 140, in patched_instantiate_classes cfg = self._unpatched_instantiate_classes(cfg, **kwargs) File "/home/ubuntu/.pyenv/versions/env/lib/python3.10/site-packages/jsonargparse/_core.py", line 1207, in instantiate_classes component.instantiate_class(component, cfg) File "/home/ubuntu/.pyenv/versions/env/lib/python3.10/site-packages/jsonargparse/_signatures.py", line 560, in group_instantiate_class parent[key] = instantiator_fn(group.group_class, **value) File "/home/ubuntu/.pyenv/versions/env/lib/python3.10/site-packages/jsonargparse/_common.py", line 155, in default_class_instantiator return class_type(*args, **kwargs) TypeError: MyConfig.__init__() got an unexpected keyword argument 'optimizer.class_path'
from dataclasses import dataclass from jsonargparse import ArgumentParser, Namespace import torch @dataclass class Foo: f: int @dataclass class MyConfig: f: Foo optimizer: Namespace parser = ArgumentParser() parser.add_class_arguments(MyConfig, nested_key="my_config", skip={"optimizer"}) parser.add_subclass_arguments((torch.optim.Optimizer,), nested_key="my_config.optimizer", skip={"params"}, instantiate=False) args = parser.parse_args(args=["--my_config.f.f=123", "--my_config.optimizer=torch.optim.Adam"]) args = parser.instantiate_classes(args) print(args)
This works though (there is no nested key):
from dataclasses import dataclass from jsonargparse import ArgumentParser, Namespace import torch @dataclass class Foo: f: int @dataclass class MyConfig: f: Foo optimizer: Namespace parser = ArgumentParser() parser.add_class_arguments(MyConfig, skip={"optimizer"}) parser.add_subclass_arguments((torch.optim.Optimizer,), nested_key="optimizer", skip={"params"}, instantiate=False) args = parser.parse_args(args=["--f.f=123", "--optimizer=torch.optim.Adam"]) args = parser.instantiate_classes(args) print(args)
Prints
Namespace(my_config=Namespace(f=Foo(f=123), optimizer=Namespace(class_path='torch.optim.Adam', init_args=Namespace(lr=0.001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0.0, amsgrad=False, foreach=None, maximize=False, capturable=False, differentiable=False, fused=None))))
Merry christmas
The text was updated successfully, but these errors were encountered:
No branches or pull requests
🐛 Bug report
To reproduce
This works though (there is no nested key):
Expected behavior
Prints
Environment
Merry christmas
The text was updated successfully, but these errors were encountered: