-
Notifications
You must be signed in to change notification settings - Fork 11
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
ConfigDicts aren't converted to dataclasses when specified in a list #442
Comments
Thanks very much for the nice repro -- very helpful. hydra-zen is constructing the config appropriately: from hydra_zen import to_yaml
>>> print(to_yaml(Config))
_target_: __main__.app
_convert_: all
dc:
- _target_: __main__.B
x: 0 The weirdness is on Hydra's end: >>> instantiate(Config()) # correct
[B(x=0)]
>>> instantiate(Config().dc) # incorrect
[{'x': 0}]
>>> instantiate(Config().dc, _convert_="object") # correct
[B(x=0)] I want I think I may have a fix for this.. in place of using def inst(x):
x = instantiate(x)
if isinstance(x, (ListConfig, DictConfig)):
# cant' use _convert_="object" because it is Hydra 1.3+ only
return OmegaConf.to_object(x)
else:
return x which gets your example to run without issue. I did a quick prototype and I will need to think about how this can be done in a way that lets people opt into the old behavior. Other than that, I am very keen to make this improvement; |
This comment was marked as off-topic.
This comment was marked as off-topic.
@DirkKuhn @kiyoon I just pushed a pre-release of hydra-zen v0.11.0, which should have a fix to the issue reported above. When you have a moment, please install it using @kiyoon in the example you posted I don't see |
@rsokl Oh sorry for not being clear. I'm not using zen but I'm using either |
@kiyoon that is ultimately an issue with how Hydra's instantiate works, not with how |
@rsokl Thanks a lot. The |
I recommend reading this if you are interested in understanding what is going on under the hood. Glad this resolved the issue! |
Thanks for sharing the link. I think it makes sense a little better. The problem with me is that I came from no hydra/OmegaConf background, so at first I found it hard to understand which functionality is hydra and which is hydra-zen. Can I ask one more question if you don't mind? Why would I ever need to remove |
Yeah.. this is a real problem. I would love to add a page to the Explanations section of hydra-zen's docs that give a high-level overview of what omegaconf, hydra, and hydra-zen are responsible for, respectively. Your confusion is totally understandable.
That is a good question... I don't think that you would! You can probably safely use that option everywhere. Unfortunately, I cannot do that by default in hydra-zen, because it would 1) Require that I end support for Hydra < 1.3 and 2) Be a major compatibility-breaking change. That all being said, I would like to make it much easier for people to be able to opt-in to this behavior uniformly across hydra-zen's API. |
I see. Just wanted to clarify if I'm not doing something wrong by putting that everywhere. Fair enough that it can't be a default as of now. Thanks a lot for your work on this project. The documentation is very nice and well done, and I also found the presentation about it on YouTube helpful. |
@rsokl It seems to work now! Thanks so much for your effort! |
The conversion back to dataclasses doesn't seem to work, when they are specified in a list.
Here is a minimal example.
It fails with an assertion error. The entry in
dc
is aDictConfig
.Thanks!
The text was updated successfully, but these errors were encountered: