-
-
Notifications
You must be signed in to change notification settings - Fork 663
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
Refactor Instantiate to support instantiating dataclasses #1236
Refactor Instantiate to support instantiating dataclasses #1236
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
8762d56
to
e7ad10f
Compare
Thanks @guillaumegenthial! Don't forget to sign the CLA (see message from the bot above, I can't accept it otherwise). |
cbaecfb
to
a1a8bae
Compare
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
103d599
to
3c7453d
Compare
@omry sure thing, don't hesitate to ping me when you have some time. To summarize the changes
I updated the dataclass test, and I think it now behaves as we would expect. Some cases are counter intuitive (convert = NONE and nesting |
Some high level feedback before I do a proper review based on your summary:
I am actually not sure about this one but I am guessing you can still override the mode in the child node?
While I definitely want better support for simple containers. Few things:
We should probably split it to a followup PR once the initial changes settles in. Finally, some of the CI tests are tailing (particularly plugins, which are being instantiated with instantiate(). be sure to take a look and fix the issues. |
Yes, children modes override the parent's modes if specified
Definitely agree, I included it here because it's easy to do with the new implementation (it kind of demonstrates its flexibility)
I see some "version mismatch" errors, I will have a look at it to understand how instantiate has an impact there. |
Ok, I'm pretty sure the failing ray launcher plugin tests are not caused by this PR. |
Yup, unrelated. I filed #1238 to track it. |
Simple comment : |
Certainly (assuming that use case is really not depending on type validation, interpolation or any other OmegaConf feature). |
4f96230
to
c1c5bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review pass.
see my comments.
meta:
At this point, switch to piling additional changes as new commits. it will make this easier to review.
We can squash everything before we merge.
hydra/utils.py
Outdated
_convert_container_targets_to_strings(kwargs) | ||
_convert_container_targets_to_strings(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a good opportunity to simplify this.
Now that OmegaConf supports objects, we should be able to just convert forward.
instead of converting types to strings (and then locate them again), we can convert everything to types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
EDIT: this works, what is below is incorrect
However it seems we can't really store types in OmegaConf containers.
from omegaconf import OmegaConf
class MyClass:
pass
OmegaConf.create({"_target_": MyClass})
raises
UnsupportedValueType: Value 'MyClass' is not a supported primitive type
full_key: _target_
reference_type=Optional[Dict[Union[str, Enum], Any]]
object_type=dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually my bad, I forgot the flag {"allow_objects"} so it works as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some ambiguity with dataclasses though
@dataclass
class MyClass:
x: int
cfg = OmegaConf.create({"_target_": MyClass}, flags={"allow_objects": True})
print(cfg._target_) # {'x': '???'}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That again, sounds like another case fox boxing the object.
config = _merge(config, kwargs) if kwargs else config | ||
|
||
# Override parent modes from config if specified | ||
# Cannot use pop with default because of OmegaConf typed config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand the statement.
if DictConfig.pop() behaves differently than native dict pop(), please file an issue with a minimal repro against OmegaConf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment on an opened issue omry/omegaconf#425.
I'm not sure this is really a bug, more like some type checking functionality of OmegaConf that forces us to "look before trying"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a separate issue at your request here omry/omegaconf#471
if convert == ConvertMode.ALL or ( | ||
convert == ConvertMode.PARTIAL and config._metadata.object_type is None | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how PARTIAL is leaking into this area. somehow this feels off.
Thank you for reviewing @omry . |
Please repeat the comment. |
looks like there are some conflicts, can you rebase and fix? |
57976c4
to
b13f8e8
Compare
I was referring to your comment
My answer was
And I agree, discussing live on the chat would be more efficient |
@guillaumegenthial, |
Taking over. Thanks for working on this. |
Motivation
Address #1183
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Related Issues and PRs
#1183
(Is this PR part of a group of changes? Link the other relevant PRs and Issues here. Use https://help.github.com/en/articles/closing-issues-using-keywords for help on GitHub syntax)