Skip to content
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

bugfix: Resolve interpolation bug with Hydra #5406

Merged
merged 19 commits into from
Jan 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
typo
tchaton committed Jan 9, 2021
commit 2045be692e5a6591d15351f81132ab02881b2b1f
2 changes: 1 addition & 1 deletion pytorch_lightning/core/saving.py
Original file line number Diff line number Diff line change
@@ -369,7 +369,7 @@ def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:

# saving with OmegaConf objects
if OMEGACONF_AVAILABLE:
# deepcopy: hparams from user is not resolved
# deepcopy: hparams from user shouldn't be resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit lost as to what the logic here is. Let's say I have multiple DictConfigs stored in hparams like below

{
    'arg1': DictConfig(...),
    'arg2': DictConfig(...)
}

With the logic you're proposing, we're going to resolve all DictConfig's eagerly (so that all interpolation's are resolved) and then save the hparams file.

The previous logic would only save the config if it found a DictConfig object, or in my logic the first conf that it finds, which is definitely unsuitable.

So to be clear, the issue is that hparams is a dictionary of DictConfigs and there is no save function that auto resolves them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised the PR got merged, but if we could come up with a solution that doesn't require a try/catch + recursive search this would be preferred I think (cc @tchaton @omry)

Any reason why the try catch was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omry It was auto-merge, but let s come with a better solution.

hparams = deepcopy(hparams)
to_container = partial(OmegaConf.to_container, resolve=True)
hparams = apply_to_collection(hparams, DictConfig, to_container)