Non-default argument follows default argument #412
-
I am running more and more into this Experiment = builds(
launch_experiment,
populate_full_signature=True,
hydra_defaults=[
"_self_",
{"model": "lnp"},
{"optimizer": "sgd"},
{"scheduler": "step"},
{"training": "default"},
{"dataset": "contactpose"},
{"trainer": "base"},
],
data_loader=pbuilds(TaskLoader, builds_bases=(DataloaderConf,)),
)
...
experiment_store = store(group="experiment", package="_global_")
experiment_store(
make_config(
hydra_defaults=[
"_self_",
],
model=dict(
y_dim=21 * 3, x_dim=store["dataset", "contactpose"].obj_ptcld_size * 3
), # TODO: Better way to handle this ? It breaks if I override the dataset config.
dataset=dict(
pair=("object", "hand"),
scaling="hand_object",
use_mano=False,
positive_unit_cube=True,
),
bases=(Experiment,),
),
name="lnp_keypoints_obj_to_hand",
)
experiment_store(
make_config(
hydra_defaults=[
"_self_",
{"override /trainer": "mano"},
{"override /model": "megalnp"},
],
bases=(Experiment,),
model=dict( # 18 MANO pose parameters and a 4x4 Sim(3) group transformation
mano_dim=18, x_dim=store["dataset", "contactpose"].obj_ptcld_size * 3
),
dataset=dict(
pair=("object", "hand"),
scaling="hand_object",
use_mano=True,
positive_unit_cube=False,
),
),
name="megalnp_mano_obj_to_hand",
) Now for some reason, I get this error: Thanks for the help |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
@DubiousCactus Interesting question. Unfortunately I cannot figure out what is going on with the information you provided. Is it possible to create a simple example recreating the error? At first glance I would say it's odd to use |
Beta Was this translation helpful? Give feedback.
-
Thanks for getting back to me so quickly. I am working on a PyTorch template with hydra-zen, so you can test the code if you clone my repo and run I followed your tutorial that shows how to use I don't see how I would set If you have suggestions for improving my architecture I would love to hear them, thanks! |
Beta Was this translation helpful? Give feedback.
-
@DubiousCactus ok. I can confirm that there is something weird going on here. The solution is to use from hydra_zen import zen, store, MISSING, make_config
def launch_experiment(trainer, model):
print(trainer, model)
store(dict(foo=1), group="trainer", name="default")
store(dict(foo=3), group="trainer", name="mano")
store(dict(bar=2), group="model", name="default")
store(dict(bar=4), group="model", name="megalnp")
Experiment = make_config(
hydra_defaults=["_self_", {"trainer": "default"}, {"model": "default"}],
trainer=MISSING, # normally I would use None, but that does not work with experiment configs
model=MISSING, # normally I would use None, but that does not work with experiment configs
)
store(Experiment, name="config")
experiment_store = store(group="experiment", package="_global_")
experiment_store(
make_config(
hydra_defaults=[
"_self_",
{"override /trainer": "mano"},
{"override /model": "megalnp"},
],
bases=(Experiment,),
),
name="exp1",
)
if __name__ == "__main__":
store.add_to_hydra_store()
zen(launch_experiment).hydra_main(
config_path=None, config_name="config", version_base="1.1"
) $ python myapp.py
{'foo': 1} {'bar': 2} $ python myapp.py +experiment=exp1
{'foo': 3} {'bar': 4} Note, because you use |
Beta Was this translation helpful? Give feedback.
-
@DubiousCactus sorry for the late follow up on this. I finally found time to dig in. Bad news and good news: Bad news: I am not going to make hydra-zen handle this automatically. It is really really hairy and will probably break other, more common patterns. Good news: This problem goes away if enable keyword-only fields in your configs (dataclasses)! Note that this requires Python 3.10+. from hydra_zen import make_config
A = make_config("a", "b")
B = make_config(a=1, bases=(A,)) # raises TypeError due to non-default arg following default arg
C = make_config(a=1, bases=(A,), zen_dataclass={'kw_only': True}) # OK! So I think you can just do Experiment = builds(
launch_experiment,
populate_full_signature=True,
hydra_defaults=[
"_self_",
{"model": "lnp"},
{"optimizer": "sgd"},
{"scheduler": "step"},
{"training": "default"},
{"dataset": "contactpose"},
{"trainer": "base"},
],
data_loader=pbuilds(TaskLoader, builds_bases=(DataloaderConf,)),
zen_dataclass={'kw_only': True}
) |
Beta Was this translation helpful? Give feedback.
@DubiousCactus ok. I can confirm that there is something weird going on here. The solution is to use
hydra_zen.MISSING
asNone
does not work. Here is my working example: